[Tracker-discuss] [issue644] 'Random Issue' Button isn't working
John Rouillard
metatracker at psf.upfronthosting.co.za
Thu May 31 20:41:57 EDT 2018
John Rouillard <rouilj+psf at cs.umb.edu> added the comment:
Hi all:
I took another look at this. I suggest replacing the current class
with:
class RandomIssueAction2(Action):
def handle(self):
"""Redirect to a random open issue."""
issue = self.context['context']
# use issue._klass to get a list of ids, and not a list of instances
issue_ids = issue._klass.filter(None, {'status': '1'})
random.seed()
url = self.db.config.TRACKER_WEB + 'issue' + random.choice(issue_ids)
raise Redirect(url)
two changes, the addition of the random.seed() call and change {'status': 1}
to {'status': '1'}. This works for my trackers. If I use the original
{'status': 1} value I get no id's back. The addition of the seed makes the
randomness return.
Also note that this function will throw a traceback if there are no issues
matching the reference criteria. Adding a try/catch or checking the size of
the issue_ids list is left as an exercise for the reader 8-).
-- rouilj
_______________________________________________________
PSF Meta Tracker <metatracker at psf.upfronthosting.co.za>
<http://psf.upfronthosting.co.za/roundup/meta/issue644>
_______________________________________________________
More information about the Tracker-discuss
mailing list