comparison MoinMoin/apps/frontend/views.py @ 2934:e2b5a79a1e06

Fixed issue #499 - Search for tickets assigned to a user
author Aabhas Majumdar <majumdaraabhas@gmail.com>
date Sun, 08 Mar 2015 20:57:53 +0530
parents 08007ac96dda
children 456c68761e96
comparison
equal deleted inserted replaced
2933:08007ac96dda 2934:e2b5a79a1e06
2283 status = u'open' 2283 status = u'open'
2284 2284
2285 current_timestamp = datetime.now().strftime("%Y_%m_%d-%H_%M_%S") 2285 current_timestamp = datetime.now().strftime("%Y_%m_%d-%H_%M_%S")
2286 idx_name = ALL_REVS 2286 idx_name = ALL_REVS
2287 qp = flaskg.storage.query_parser([TAGS, SUMMARY, CONTENT, ITEMID], idx_name=idx_name) 2287 qp = flaskg.storage.query_parser([TAGS, SUMMARY, CONTENT, ITEMID], idx_name=idx_name)
2288 terms = [Term(ITEMTYPE, ITEMTYPE_TICKET)] 2288 term1 = [Term(ITEMTYPE, ITEMTYPE_TICKET)]
2289 term2 = []
2289 if query: 2290 if query:
2290 terms.append(qp.parse(query)) 2291 term2.append(qp.parse(query))
2291 2292
2292 if status == u'open': 2293 if status == u'open':
2293 terms.append(Term(CLOSED, False)) 2294 term1.append(Term(CLOSED, False))
2294 elif status == u'closed': 2295 elif status == u'closed':
2295 terms.append(Term(CLOSED, True)) 2296 term1.append(Term(CLOSED, True))
2296 2297
2297 selected_tags = set(request.args.getlist(u'selected_tags')) 2298 selected_tags = set(request.args.getlist(u'selected_tags'))
2298 terms.extend(Term(TAGS, tag) for tag in selected_tags) 2299 term1.extend(Term(TAGS, tag) for tag in selected_tags)
2299 assigned_username = request.args.get(ASSIGNED_TO) 2300 assigned_username = request.args.get(ASSIGNED_TO) or query
2300 user = [Term(NAME, assigned_username)] 2301 user = [Term(NAME, assigned_username)]
2301 user.append(Term(CONTENTTYPE, CONTENTTYPE_USER)) 2302 user.append(Term(CONTENTTYPE, CONTENTTYPE_USER))
2302 user = And(user) 2303 user = And(user)
2303 2304
2304 with flaskg.storage.indexer.ix[LATEST_REVS].searcher() as searcher: 2305 with flaskg.storage.indexer.ix[LATEST_REVS].searcher() as searcher:
2305 if assigned_username: 2306 if assigned_username:
2306 selected_user = searcher.search(user, limit=None) 2307 selected_user = searcher.search(user, limit=None)
2307 if selected_user: 2308 if selected_user:
2308 assigned_to = selected_user[0][ITEMID] 2309 assigned_to = selected_user[0][ITEMID]
2309 terms.append(Term(ASSIGNED_TO, assigned_to)) 2310 term2.append(Term(ASSIGNED_TO, assigned_to))
2310 else: 2311 elif not query:
2311 terms = [] 2312 term2 = []
2312 2313 term1 = []
2313 q = And(terms) 2314 q = None
2315 # There are two cases when the user uses the search box in the ticket tracker and other
2316 # when user clicks on Assignee name in the ticket's table to view all tickets assigned to him
2317 # E.g of link for second case is +tickets?assigned_to=username
2318 # for first case i.e while we are using search box, variable 'query' (i.e what ever is searched) should be present either in
2319 # TAGS, SUMMARY, CONTENT, ITEMID 'or' ASSIGNED_TO 'and' should be of given status (closed or open).
2320 # while in second case we have to get all the results having given status 'and' Assigned_to = request.args.get(ASSIGNED_TO).
2321 # first case we use 'and' while in second case we use 'or' while adding the assigned_to condition to retrieve the results.
2322 if query:
2323 term2 = Or(term2)
2324 term1.extend([term2])
2325 else:
2326 term1.extend(term2)
2327 q = And(term1)
2314 results = searcher.search(q, limit=None) 2328 results = searcher.search(q, limit=None)
2315 tags = get_itemtype_specific_tags(ITEMTYPE_TICKET) 2329 tags = get_itemtype_specific_tags(ITEMTYPE_TICKET)
2316 return render_template('tickets.html', 2330 return render_template('tickets.html',
2317 results=results, 2331 results=results,
2318 query=query, 2332 query=query,