##// END OF EJS Templates
reports: fetch previous/next from elasticsearch
ergo -
Show More
@@ -254,13 +254,12 b' class Report(Base, BaseModel):'
254
254
255 instance_dict['group']['next_report'] = None
255 instance_dict['group']['next_report'] = None
256 instance_dict['group']['previous_report'] = None
256 instance_dict['group']['previous_report'] = None
257 next_in_group = self.get_next_in_group()
257 next_in_group = self.get_next_in_group(request)
258 previous_in_group = self.get_previous_in_group()
258 previous_in_group = self.get_previous_in_group(request)
259 if next_in_group:
259 if next_in_group:
260 instance_dict['group']['next_report'] = next_in_group.id
260 instance_dict['group']['next_report'] = next_in_group
261 if previous_in_group:
261 if previous_in_group:
262 instance_dict['group']['previous_report'] = \
262 instance_dict['group']['previous_report'] = previous_in_group
263 previous_in_group.id
264
263
265 # slow call ordering
264 # slow call ordering
266 def find_parent(row, data):
265 def find_parent(row, data):
@@ -301,21 +300,45 b' class Report(Base, BaseModel):'
301 del instance_dict[k]
300 del instance_dict[k]
302 return instance_dict
301 return instance_dict
303
302
304 def get_previous_in_group(self):
303 def get_previous_in_group(self, request):
305 start_day = self.report_group_time.date().replace(day=1)
304 query = {
306 end_day = start_day.replace(month=start_day.month+1)
305 "size": 1,
307 query = self.report_group.reports.filter(Report.id < self.id)
306 "query": {
308 query = query.filter(Report.report_group_time.between(
307 "filtered": {
309 start_day, end_day))
308 "filter": {
310 return query.order_by(sa.desc(Report.id)).first()
309 "and": [{"term": {"group_id": self.group_id}},
311
310 {"range": {"pg_id": {"lt": self.id}}}]
312 def get_next_in_group(self):
311 }
313 start_day = self.report_group_time.date().replace(day=1)
312 }
314 end_day = start_day.replace(month=start_day.month+1)
313 },
315 query = self.report_group.reports.filter(Report.id > self.id)
314 "sort": [
316 query = query.filter(Report.report_group_time.between(
315 {"_doc": {"order": "desc"}},
317 start_day, end_day))
316 ],
318 return query.order_by(sa.asc(Report.id)).first()
317 }
318 result = request.es_conn.search(query, index=self.partition_id,
319 doc_type='report')
320 if result['hits']['total']:
321 return result['hits']['hits'][0]['_source']['pg_id']
322
323 def get_next_in_group(self, request):
324 query = {
325 "size": 1,
326 "query": {
327 "filtered": {
328 "filter": {
329 "and": [{"term": {"group_id": self.group_id}},
330 {"range": {"pg_id": {"gt": self.id}}}]
331 }
332 }
333 },
334 "sort": [
335 {"_doc": {"order": "asc"}},
336 ],
337 }
338 result = request.es_conn.search(query, index=self.partition_id,
339 doc_type='report')
340 if result['hits']['total']:
341 return result['hits']['hits'][0]['_source']['pg_id']
319
342
320 def get_public_url(self, request=None, report_group=None, _app_url=None):
343 def get_public_url(self, request=None, report_group=None, _app_url=None):
321 """
344 """
General Comments 0
You need to be logged in to leave comments. Login now