##// 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 255 instance_dict['group']['next_report'] = None
256 256 instance_dict['group']['previous_report'] = None
257 next_in_group = self.get_next_in_group()
258 previous_in_group = self.get_previous_in_group()
257 next_in_group = self.get_next_in_group(request)
258 previous_in_group = self.get_previous_in_group(request)
259 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 261 if previous_in_group:
262 instance_dict['group']['previous_report'] = \
263 previous_in_group.id
262 instance_dict['group']['previous_report'] = previous_in_group
264 263
265 264 # slow call ordering
266 265 def find_parent(row, data):
@@ -301,21 +300,45 b' class Report(Base, BaseModel):'
301 300 del instance_dict[k]
302 301 return instance_dict
303 302
304 def get_previous_in_group(self):
305 start_day = self.report_group_time.date().replace(day=1)
306 end_day = start_day.replace(month=start_day.month+1)
307 query = self.report_group.reports.filter(Report.id < self.id)
308 query = query.filter(Report.report_group_time.between(
309 start_day, end_day))
310 return query.order_by(sa.desc(Report.id)).first()
311
312 def get_next_in_group(self):
313 start_day = self.report_group_time.date().replace(day=1)
314 end_day = start_day.replace(month=start_day.month+1)
315 query = self.report_group.reports.filter(Report.id > self.id)
316 query = query.filter(Report.report_group_time.between(
317 start_day, end_day))
318 return query.order_by(sa.asc(Report.id)).first()
303 def get_previous_in_group(self, request):
304 query = {
305 "size": 1,
306 "query": {
307 "filtered": {
308 "filter": {
309 "and": [{"term": {"group_id": self.group_id}},
310 {"range": {"pg_id": {"lt": self.id}}}]
311 }
312 }
313 },
314 "sort": [
315 {"_doc": {"order": "desc"}},
316 ],
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 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