Пример #1
0
 async def get(self, *, uid_or_name: str='', pid: str='', tid: str=''):
     query = {}
     if uid_or_name:
         try:
             query['uid'] = int(uid_or_name)
         except ValueError:
             udoc = await user.get_by_uname(uid_or_name)
             if not udoc:
                 raise error.UserNotFoundError(uid_or_name) from None
             query['uid'] = udoc['_id']
     if pid:
         query['domain_id'] = self.domain_id
         query['pid'] = int(pid)
     if tid:
         query['domain_id'] = self.domain_id
         query['tid'] = int(tid)
     # TODO: projection, pagination
     rdocs = await record.get_all_multi(**query,
                                        get_hidden=self.has_priv(builtin.PRIV_VIEW_HIDDEN_RECORD)
                                        ).sort([('_id', -1)]).limit(50).to_list(None)
     if rdocs:
         # TODO: projection
         udict, pdict = await asyncio.gather(
             user.get_dict(rdoc['uid'] for rdoc in rdocs),
             problem.get_dict_multi_domain((rdoc['domain_id'], rdoc['pid']) for rdoc in rdocs)
         )
     else:
         udict = {}
         pdict = {}
     # statistics
     statistics = None
     if self.has_priv(builtin.PRIV_VIEW_JUDGE_STATISTICS):
         ts = calendar.timegm(datetime.datetime.utcnow().utctimetuple())
         day_count, week_count, month_count, year_count, rcount = await asyncio.gather(
             record.get_count(objectid.ObjectId(
                 struct.pack('>i', ts - 24 * 3600) + struct.pack('b', -1) * 8)),
             record.get_count(objectid.ObjectId(
                 struct.pack('>i', ts - 7 * 24 * 3600) + struct.pack('b', -1) * 8)),
             record.get_count(objectid.ObjectId(
                 struct.pack('>i', ts - 30 * 24 * 3600) + struct.pack('b', -1) * 8)),
             record.get_count(objectid.ObjectId(
                 struct.pack('>i', ts - int(365.2425 * 24 * 3600)) + struct.pack('b', -1) * 8)),
             record.get_count())
         statistics = {'day': day_count, 'week': week_count, 'month': month_count,
                       'year': year_count, 'total': rcount}
     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)
Пример #2
0
 async def get(self, *, page: int = 1):
     # TODO: continuation based pagination.
     nodes, (ddocs, dpcount, _) = await asyncio.gather(
         discussion.get_nodes(self.domain_id),
         # TODO: exclude problem/contest discussions?
         pagination.paginate(discussion.get_multi(self.domain_id), page,
                             self.DISCUSSIONS_PER_PAGE))
     udict, vndict = await asyncio.gather(
         user.get_dict(ddoc['owner_uid'] for ddoc in ddocs),
         discussion.get_dict_vnodes(self.domain_id,
                                    map(discussion.node_id, ddocs)))
     self.render('discussion_main_or_node.html',
                 discussion_nodes=nodes,
                 ddocs=ddocs,
                 udict=udict,
                 vndict=vndict,
                 page=page,
                 dpcount=dpcount,
                 datetime_stamp=self.datetime_stamp)
Пример #3
0
 async def get(self, *, did: objectid.ObjectId, page: int = 1):
     ddoc = await discussion.inc_views(self.domain_id, did)
     if self.has_priv(builtin.PRIV_USER_PROFILE):
         dsdoc = await discussion.get_status(self.domain_id, ddoc['_id'],
                                             self.user['_id'])
     else:
         dsdoc = None
     vnode, (drdocs, pcount, drcount) = await asyncio.gather(
         discussion.get_vnode(self.domain_id, discussion.node_id(ddoc)),
         pagination.paginate(
             discussion.get_multi_reply(self.domain_id, ddoc['_id']), page,
             self.REPLIES_PER_PAGE))
     uids = {ddoc['owner_uid']}
     uids.update(drdoc['owner_uid'] for drdoc in drdocs)
     for drdoc in drdocs:
         if 'reply' in drdoc:
             uids.update(drrdoc['owner_uid'] for drrdoc in drdoc['reply'])
     udict, dudict = await asyncio.gather(
         user.get_dict(uids),
         domain.get_dict_user_by_uid(self.domain_id, uids))
     path_components = self.build_path(
         (self.translate('discussion_main'),
          self.reverse_url('discussion_main')),
         (vnode['title'],
          node_url(self, 'discussion_node', discussion.node_id(ddoc))),
         (ddoc['title'], None))
     self.render('discussion_detail.html',
                 page_title=ddoc['title'],
                 path_components=path_components,
                 ddoc=ddoc,
                 dsdoc=dsdoc,
                 drdocs=drdocs,
                 page=page,
                 pcount=pcount,
                 drcount=drcount,
                 vnode=vnode,
                 udict=udict,
                 dudict=dudict)
Пример #4
0
 async def get(self, *, tid: int):
     tdoc, tsdocs = await contest.get_and_list_status(self.domain_id, tid)
     if (not contest.RULES[tdoc['rule']].show_func(tdoc, self.now) and
             not self.has_perm(builtin.PERM_VIEW_CONTEST_HIDDEN_STATUS)):
         raise error.ContestStatusHiddenError()
     udict, pdict = await asyncio.gather(
         user.get_dict([tsdoc['uid'] for tsdoc in tsdocs]),
         problem.get_dict(self.domain_id, tdoc['pids']))
     for index, pid in enumerate(tdoc['pids']):
         pdict[pid]['letter'] = chr(ord('A') + index)
     ranked_tsdocs = contest.RULES[tdoc['rule']].rank_func(tsdocs)
     path_components = self.build_path(
         (self.translate('contest_main'), self.reverse_url('contest_main')),
         (tdoc['title'], self.reverse_url('contest_detail',
                                          tid=tdoc['_id'])),
         (self.translate('contest_status'), None))
     self.render('contest_status.html',
                 tdoc=tdoc,
                 ranked_tsdocs=ranked_tsdocs,
                 dict=dict,
                 udict=udict,
                 pdict=pdict,
                 path_components=path_components)
Пример #5
0
 async def get(self, *, tid: int):
     tdocs = await contest.get_multi(self.domain_id,
                                     **{
                                         'begin_at': {
                                             '$lte': self.now
                                         },
                                         'end_at': {
                                             '$gt': self.now
                                         }
                                     },
                                     projection={
                                         '_id': True
                                     }).to_list(None)
     tids = [tdoc['_id'] for tdoc in tdocs]
     query = {
         'domain_id': self.domain_id,
         'tid': {
             '$in': list(set(tids))
         },
         'detail.accept': True,
         'detail.balloon': False
     }
     tsdocs = await contest.get_multi_status(**query).sort('_id',
                                                           1).to_list(None)
     balloons = []
     for tsdoc in tsdocs:
         for pstatus in tsdoc['detail']:
             if pstatus['accept'] and not pstatus['balloon']:
                 balloons.append({
                     'tid': tsdoc['tid'],
                     'uid': tsdoc['uid'],
                     'pid': pstatus['pid'],
                     'balloon': pstatus['balloon']
                 })
     udict, udoc, tdoc = await asyncio.gather(
         user.get_dict([balloon['uid'] for balloon in balloons]),
         user.get_by_uid(self.user['_id']),
         contest.get(self.domain_id, tid))
     for balloon in balloons:
         balloon.update({
             'uname':
             udict[balloon['uid']]['uname'],
             'nickname':
             udict[balloon['uid']].get('nickname', ''),
             'letter':
             contest.convert_to_letter(tdoc['pids'], balloon['pid'])
         })
     if not self.prefer_json:
         path_components = self.build_path(
             (self.translate('contest_main'),
              self.reverse_url('contest_main')),
             (tdoc['title'], self.reverse_url('contest_detail', tid=tid)),
             (self.translate('contest_balloon'), None))
         self.render('contest_balloon.html',
                     path_components=path_components,
                     udict=udict,
                     udoc=udoc,
                     tdoc=tdoc,
                     balloons=balloons)
     else:
         self.json({'balloons': balloons})