Skip to content

Commit

Permalink
record pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
twd2 committed Jul 22, 2017
1 parent ff39103 commit 01b5662
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
16 changes: 12 additions & 4 deletions vj4/handler/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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')
Expand Down
7 changes: 7 additions & 0 deletions vj4/ui/templates/record_main.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ <h1 class="section__title">{{ _('Filter') }}</h1>
{% endfor %}
</tbody>
</table>
{% if handler.has_priv(vj4.model.builtin.PRIV_VIEW_JUDGE_STATISTICS) %}
<ul class="pager">
<li>
<a class="pager__item next link" href="?start={{ rdocs[-1]['_id'] }}&{{ query_string }}">{{ _('pager_next') }}</a>
</li>
</ul>
{% endif %}
{% endif %}
</div>
</div>
Expand Down

0 comments on commit 01b5662

Please sign in to comment.