1. Robot Mirror
  2. bugs.python.org


bugs.python.org / extensions / pydevutils.py

import random
from roundup.cgi.actions import Action
from roundup.cgi.exceptions import Redirect

def is_history_ok(request):
    user = request.client.userid
    db = request.client.db
    classname = request.classname
    nodeid = request.nodeid
    # restrict display of user history to user itself only
    if classname == 'user':
        return user == nodeid or 'Coordinator' in db.user.get(user, 'roles')
    # currently not used
    return True

def is_coordinator(request):
    user = request.client.userid
    db = request.client.db
    return 'Coordinator' in db.user.get(user, 'roles')

def issueid_and_action_from_class(cls):
    Return the id of the issue where the msg/file is/was linked
    and if the last "linking action" was 'link' or 'unlink'.
    last_action = ''
    for entry in cls._klass.history(cls._nodeid):
        if 'unlink' in entry:
            last_unlink = entry
            last_action = 'unlink'
        elif 'link' in entry:
            last_entry = entry
            last_action = 'link'
    if last_action in ('link', 'unlink'):
        # the msg has been unlinked and not linked back
        # the link looks like: ('16', <Date 2011-07-22.05:14:12.342>, '4',
        #                       'link', ('issue', '1', 'messages'))
        return last_entry[4][1], last_action
    return None, None

class RandomIssueAction(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})
        url = self.db.config.TRACKER_WEB + 'issue' + random.choice(issue_ids)
        raise Redirect(url)

def init(instance):
    instance.registerUtil('is_history_ok', is_history_ok)
    instance.registerUtil('is_coordinator', is_coordinator)
    instance.registerAction('random', RandomIssueAction)