Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: appengine/monorail/tracker/issueadvsearch.py

Issue 1868553004: Open Source Monorail (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « appengine/monorail/tracker/issueadmin.py ('k') | appengine/monorail/tracker/issueattachment.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is govered by a BSD-style
3 # license that can be found in the LICENSE file or at
4 # https://developers.google.com/open-source/licenses/bsd
5
6 """Classes that implement the advanced search feature page.
7
8 The advanced search page simply displays an HTML page with a form.
9 The form handler converts the widget-based query into a googley query
10 string and redirects the user to the issue list servlet.
11 """
12
13 import logging
14 import re
15
16 from framework import framework_helpers
17 from framework import permissions
18 from framework import servlet
19 from framework import urls
20
21 # Patterns for search values that can be words, labels,
22 # component paths, or email addresses.
23 VALUE_RE = re.compile(r'[-a-zA-Z0-9._>@]+')
24
25
26 class IssueAdvancedSearch(servlet.Servlet):
27 """IssueAdvancedSearch shows a form to enter an advanced search."""
28
29 _PAGE_TEMPLATE = 'tracker/issue-advsearch-page.ezt'
30 _MAIN_TAB_MODE = servlet.Servlet.MAIN_TAB_ISSUES
31
32 # This form *only* redirects to a GET request, and permissions are checked
33 # in that handler.
34 CHECK_SECURITY_TOKEN = False
35
36 def GatherPageData(self, mr):
37 """Build up a dictionary of data values to use when rendering the page.
38
39 Args:
40 mr: commonly used info parsed from the request.
41
42 Returns:
43 Dict of values used by EZT for rendering the page.
44 """
45
46 # TODO(jrobbins): Allow deep-linking into this page.
47
48 return {
49 'issue_tab_mode': 'issueAdvSearch',
50 'page_perms': self.MakePagePerms(mr, None, permissions.CREATE_ISSUE),
51 }
52
53 def ProcessFormData(self, mr, post_data):
54 """Process a posted advanced query form.
55
56 Args:
57 mr: commonly used info parsed from the request.
58 post_data: HTML form data from the request.
59
60 Returns:
61 String URL to redirect the user to after processing.
62 """
63 # Default to searching open issues in this project.
64 can = post_data.get('can', 2)
65
66 terms = []
67 self._AccumulateANDTerm('', 'words', post_data, terms)
68 self._AccumulateANDTerm('-', 'without', post_data, terms)
69 self._AccumulateANDTerm('label:', 'labels', post_data, terms)
70 self._AccumulateORTerm('component:', 'components', post_data, terms)
71 self._AccumulateORTerm('status:', 'statuses', post_data, terms)
72 self._AccumulateORTerm('reporter:', 'reporters', post_data, terms)
73 self._AccumulateORTerm('owner:', 'owners', post_data, terms)
74 self._AccumulateORTerm('cc:', 'cc', post_data, terms)
75 self._AccumulateORTerm('commentby:', 'commentby', post_data, terms)
76
77 if 'starcount' in post_data:
78 starcount = int(post_data['starcount'])
79 if starcount >= 0:
80 terms.append('starcount:%s' % starcount)
81
82 return framework_helpers.FormatAbsoluteURL(
83 mr, urls.ISSUE_LIST, q=' '.join(terms), can=can)
84
85 def _AccumulateANDTerm(self, operator, form_field, post_data, search_query):
86 """Build a query that matches issues with ALL of the given field values."""
87 user_input = post_data.get(form_field)
88 if user_input:
89 values = VALUE_RE.findall(user_input)
90 search_terms = ['%s%s' % (operator, v) for v in values]
91 search_query.extend(search_terms)
92
93 def _AccumulateORTerm(self, operator, form_field, post_data, search_query):
94 """Build a query that matches issues with ANY of the given field values."""
95 user_input = post_data.get(form_field)
96 if user_input:
97 values = VALUE_RE.findall(user_input)
98 search_term = '%s%s' % (operator, ','.join(values))
99 search_query.append(search_term)
OLDNEW
« no previous file with comments | « appengine/monorail/tracker/issueadmin.py ('k') | appengine/monorail/tracker/issueattachment.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698