source: peerreviewplugin/tags/0.12/3.1/codereview/peerReviewSearch.py

Last change on this file was 17266, checked in by Cinc-th, 5 years ago

PeerReviewPlugin: record timestamp when finishing a review. The status considered as a terminal status are closed, approved, disapproved (unless configuration was changed). The finishing date is shown in the UI.

File size: 6.1 KB
Line 
1#
2# Copyright (C) 2005-2006 Team5
3# All rights reserved.
4#
5# This software is licensed as described in the file COPYING.txt, which
6# you should have received as part of this distribution.
7#
8# Author: Team5
9#
10
11import datetime
12import itertools
13import time
14
15from trac.core import *
16from trac.util import format_date
17from trac.web.chrome import INavigationContributor, add_stylesheet, add_script, add_script_data
18from trac.web.main import IRequestHandler
19
20from dbBackend import *
21from CodeReviewStruct import *
22from peerReviewMain import add_ctxt_nav_items
23from model import get_users
24
25
26class PeerReviewSearch(Component):
27    implements(IRequestHandler, INavigationContributor)
28
29    # IRequestHandler methods
30    def match_request(self, req):
31        return req.path_info == '/peerReviewSearch'
32
33    # INavigationContributor methods
34    def get_active_navigation_item(self, req):
35        return 'peerReviewMain'
36
37    def get_navigation_items(self, req):
38        return []
39
40    def process_request(self, req):
41        req.perm.require('CODE_REVIEW_DEV')
42        data = {}
43
44        #if the doSearch parameter is 'yes', perform the search
45        #this parameter is set when someone searches
46        if req.args.get('doSearch') == 'yes':
47            results = self.performSearch(req, data)
48            #if there are no results - fill the return array
49            #with blank data.
50            if len(results) == 0:
51                noValResult = []
52                noValResult.append("No results match query.")
53                noValResult.append("")
54                noValResult.append("")
55                noValResult.append("")
56                noValResult.append("")
57                noValResult.append("")
58                results.append(noValResult)
59            data['results'] = results
60            data['doSearch'] = 'yes'
61
62        users = get_users(self.env)
63        #sets the possible users for the user combo-box
64        data['users'] = users
65        #creates a year array containing the last 10
66        #years - for the year combo-box
67        now = datetime.datetime.now()
68        year = now.year
69        years = []
70        for i in range(0, 11):
71            years.append(year - i)
72
73        data['years'] = years
74        data['cycle'] = itertools.cycle
75
76        add_stylesheet(req, 'common/css/code.css')
77        add_stylesheet(req, 'common/css/browser.css')
78        add_stylesheet(req, 'hw/css/peerreview.css')
79        add_script(req, 'hw/js/peerReviewSearch.js')
80        if req.args.get('doSearch_'):
81            add_script_data(req, {'dateIndexSelected': '01',
82                                  'monthSelected': data['searchValues_month'],
83                                  'daySelected': data['searchValues_day'],
84                                  'yearSelected': data['searchValues_year'],
85                                  'statusSelected': data['searchValues_status'],
86                                  'authorSelected': data['searchValues_author'],
87                                  'nameSelected': data['searchValues_name']})
88        else:
89            add_script_data(req, {'dateIndexSelected': '',
90                                  'monthSelected': '',
91                                  'daySelected': '',
92                                  'yearSelected': '',
93                                  'statusSelected': '',
94                                  'authorSelected': '',
95                                  'nameSelected': ''})
96        add_ctxt_nav_items(req)
97        return 'peerReviewSearch.html', data, None
98
99    #Performs the search
100    def performSearch(self, req, data):
101        #create a code review struct to hold the search parameters
102        crStruct = CodeReviewStruct(None)
103        #get the search parameters from POST
104        author = req.args.get('Author')
105        name = req.args.get('CodeReviewName')
106        status = req.args.get('Status')
107        month = req.args.get('DateMonth', '0')
108        day = req.args.get('DateDay', '0')
109        year = req.args.get('DateYear', '0')
110
111        #store date values for ClearSilver - used to reset values to
112        #search parameters after a search is performed
113        data['searchValues_month'] = month
114        data['searchValues_day'] = day
115        data['searchValues_year'] = year
116        data['searchValues_status'] = status
117        data['searchValues_author'] = author
118        data['searchValues_name'] = name
119
120        #dates are ints in TRAC - convert search date to int
121        fromdate = "-1"
122
123        if (month != '0') and (day != '0') and (year != '0'):
124            t = time.strptime(month + '/' + day + '/' + year[2] + year[3], '%m/%d/%y')
125            #I have no idea what this is doing - obtained from TRAC source
126            fromdate = time.mktime((t[0], t[1], t[2], 23, 59, 59, t[6], t[7], t[8]))
127            #convert to string for database lookup
128            fromdate = `fromdate`
129
130        selectString = 'Select...'
131        data['dateSelected'] = fromdate
132        #if user has not selected parameter - leave
133        #value in struct NULL
134        if author != selectString:
135            crStruct.Author = author
136
137        if name != selectString:
138            crStruct.Name = name
139
140        if status != selectString:
141            crStruct.Status = status
142
143        crStruct.DateCreate = fromdate
144        #get the database
145        db = self.env.get_read_db()
146        dbBack = dbBackend(db)
147
148        #perform search
149        results = dbBack.searchCodeReviews(crStruct)
150        returnArray = []
151        tempArray = []
152
153        if results is None:
154            return []
155        #fill array with
156        #search results
157        for struct in results:
158            tempArray.append(struct.IDReview)
159            tempArray.append(struct.Author)
160            tempArray.append(struct.Status)
161            tempArray.append(format_date(struct.DateCreate))
162            tempArray.append(struct.Name)
163            if struct.date_closed:
164                tempArray.append(format_date(struct.date_closed))
165            else:
166                tempArray.append('')
167            returnArray.append(tempArray)
168            tempArray = []
169
170        return returnArray
Note: See TracBrowser for help on using the repository browser.