From 01b5662db16b4be0343b0275eda1e8d7167a834d Mon Sep 17 00:00:00 2001 From: Wende Tan Date: Sun, 23 Jul 2017 01:15:07 +0800 Subject: [PATCH] record pagination --- vj4/handler/record.py | 16 ++++++++++++---- vj4/ui/templates/record_main.html | 7 +++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/vj4/handler/record.py b/vj4/handler/record.py index bfae4917d..d1f210f3e 100644 --- a/vj4/handler/record.py +++ b/vj4/handler/record.py @@ -53,10 +53,16 @@ async def get_filter_query(self, uid_or_name, pid, tid): class RecordMainHandler(base.Handler, RecordMixin): @base.get_argument @base.sanitize - async def get(self, *, uid_or_name: str='', pid: str='', tid: str=''): + async def get(self, *, start: str='', uid_or_name: str='', pid: str='', tid: str=''): + if not self.has_priv(builtin.PRIV_VIEW_JUDGE_STATISTICS): + start = '' + if start: + start = objectid.ObjectId(start) + else: + start = None query = await self.get_filter_query(uid_or_name, pid, tid) # TODO(iceboy): projection, pagination. - rdocs = await record.get_all_multi(**query, + rdocs = await record.get_all_multi(**query, end_id=start, get_hidden=self.has_priv(builtin.PRIV_VIEW_HIDDEN_RECORD)).sort([('_id', -1)]).limit(50).to_list() # TODO(iceboy): projection. udict, pdict = await asyncio.gather( @@ -78,10 +84,12 @@ async def get(self, *, uid_or_name: str='', pid: str='', tid: str=''): record.get_count()) statistics = {'day': day_count, 'week': week_count, 'month': month_count, 'year': year_count, 'total': rcount} + query_string = urllib.parse.urlencode( + [('uid_or_name', uid_or_name), ('pid', pid), ('tid', tid)]) self.render('record_main.html', rdocs=rdocs, udict=udict, pdict=pdict, statistics=statistics, filter_uid_or_name=uid_or_name, filter_pid=pid, filter_tid=tid, - socket_url='/records-conn?' + urllib.parse.urlencode( - [('uid_or_name', uid_or_name), ('pid', pid), ('tid', tid)])) + socket_url='/records-conn?' + query_string, + query_string=query_string) @app.connection_route('/records-conn', 'record_main-conn') diff --git a/vj4/ui/templates/record_main.html b/vj4/ui/templates/record_main.html index 0d541ebe1..77f83efe9 100644 --- a/vj4/ui/templates/record_main.html +++ b/vj4/ui/templates/record_main.html @@ -81,6 +81,13 @@

{{ _('Filter') }}

{% endfor %} + {% if handler.has_priv(vj4.model.builtin.PRIV_VIEW_JUDGE_STATISTICS) %} + + {% endif %} {% endif %}