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

Side by Side Diff: appengine/chromium_cq_status/handlers/query.py

Issue 2111713004: Teach CQ status app to check login status of users. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Review and tests. Created 4 years, 5 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
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from datetime import datetime 5 from datetime import datetime
6 import logging 6 import logging
7 import traceback 7 import traceback
8 8
9 from google.appengine.datastore.datastore_query import Cursor 9 from google.appengine.datastore.datastore_query import Cursor
10 import webapp2 10 import webapp2
(...skipping 11 matching lines...) Expand all
22 ) 22 )
23 from shared import utils 23 from shared import utils
24 24
25 def has_end_timestamp( 25 def has_end_timestamp(
26 cache_timestamp, # pylint: disable=W0613 26 cache_timestamp, # pylint: disable=W0613
27 kwargs): 27 kwargs):
28 end = kwargs.get('end') 28 end = kwargs.get('end')
29 return end and end < datetime.utcnow() 29 return end and end < datetime.utcnow()
30 30
31 @utils.memcachize(cache_check=has_end_timestamp) 31 @utils.memcachize(cache_check=has_end_timestamp)
32 def execute_query( 32 def execute_query(key, begin, end, tags, fields, count, cursor):
33 key, begin, end, tags, fields, count, cursor):
34 records = [] 33 records = []
35 next_cursor = '' 34 next_cursor = ''
36 if key and count > 0: 35 if key and count > 0:
37 record = Record.get_by_id(key) 36 record = Record.get_by_id(key)
38 if record and ( 37 if record and (
39 (not begin or record.timestamp >= begin) and 38 (not begin or record.timestamp >= begin) and
40 (not end or record.timestamp <= end) and 39 (not end or record.timestamp <= end) and
41 set(tags).issubset(record.tags) and 40 set(tags).issubset(record.tags) and
42 matches_fields(fields, record)): 41 matches_fields(fields, record)):
43 records.append(record) 42 records.append(record)
(...skipping 23 matching lines...) Expand all
67 } 66 }
68 67
69 def matches_fields(fields, record): 68 def matches_fields(fields, record):
70 for field, value in fields.items(): 69 for field, value in fields.items():
71 if not field in record.fields or record.fields[field] != value: 70 if not field in record.fields or record.fields[field] != value:
72 return False 71 return False
73 return True 72 return True
74 73
75 class Query(webapp2.RequestHandler): 74 class Query(webapp2.RequestHandler):
76 @utils.cross_origin_json 75 @utils.cross_origin_json
76 @utils.read_access
77 def get(self, url_tags): # pylint: disable=W0221 77 def get(self, url_tags): # pylint: disable=W0221
78 try: 78 try:
79 params = parse_request(self.request, { 79 params = parse_request(self.request, {
80 'begin': parse_timestamp, 80 'begin': parse_timestamp,
81 'end': parse_timestamp, 81 'end': parse_timestamp,
82 'key': parse_record_key, 82 'key': parse_record_key,
83 'tags': parse_strings, 83 'tags': parse_strings,
84 'fields': parse_fields, 84 'fields': parse_fields,
85 'count': parse_query_count, 85 'count': parse_query_count,
86 'cursor': parse_cursor, 86 'cursor': parse_cursor,
87 }) 87 })
88 params['tags'].extend(parse_url_tags(url_tags)) 88 params['tags'].extend(parse_url_tags(url_tags))
89 return execute_query(**params) 89 return execute_query(**params)
90 except ValueError as e: 90 except ValueError as e:
91 logging.warning(traceback.format_exc()) 91 logging.warning(traceback.format_exc())
92 self.response.write(e) 92 self.response.write(e)
OLDNEW
« no previous file with comments | « appengine/chromium_cq_status/handlers/post.py ('k') | appengine/chromium_cq_status/handlers/recent.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698