bugs.python.org / extensions / search_id.py

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

class SearchIDAction(Action):
    def handle(self):
        request = self.context['request']
        if not request.search_text:
            raise exceptions.FormError("Missing search text")
        split = request.search_text.split()
        if len(split) == 1:
            id = split[0]
            if id.isdigit():
                if self.db.hasnode('issue', id):
                    raise exceptions.Redirect('issue'+id)
        if len(split) > 50:
            # Postgres crashes on long queries
            raise exceptions.FormError("too many search terms")

class OpenSearchAction(SearchIDAction):
    """Action referred to in the Open Search Description.
    This has just a single query parameter (in addition to the action
    name), and fills out the rest here.
    """
    def handle(self):
        # Check for IDs first
        SearchIDAction.handle(self)
        # regular search, fill out query parameters
        for k, v in [('@columns', 'id,activity,title,creator,assignee,status,type'), #columns_showall
                     ('@sort', '-activity'),
                     ('ignore', 'file:content')]:
            self.form.value.append(cgi.MiniFieldStorage(k, v))


def init(instance):
    instance.registerAction('searchid', SearchIDAction)
    instance.registerAction('opensearch', OpenSearchAction)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.