Exemplo n.º 1
0
 async def get(self, *, did: document.convert_doc_id, 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['doc_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['doc_id']),
                           page, self.REPLIES_PER_PAGE))
   if not vnode:
     vnode = builtin.VNODE_MISSING
   elif vnode['doc_type'] == document.TYPE_PROBLEM and vnode.get('hidden', False):
     self.check_perm(builtin.PERM_VIEW_PROBLEM_HIDDEN)
   # TODO(twd2): do more visibility check eg. contest
   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'])
   if 'owner_uid' in vnode:
     uids.add(vnode['owner_uid'])
   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)
Exemplo n.º 2
0
 async def get(self, *, did: document.convert_doc_id, 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['doc_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['doc_id']),
                           page, self.REPLIES_PER_PAGE))
   if not vnode:
     vnode = builtin.VNODE_MISSING
   elif vnode['doc_type'] == document.TYPE_PROBLEM and vnode.get('hidden', False):
     self.check_perm(builtin.PERM_VIEW_PROBLEM_HIDDEN)
   # TODO(twd2): do more visibility check eg. contest
   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'])
   if 'owner_uid' in vnode:
     uids.add(vnode['owner_uid'])
   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)
Exemplo n.º 3
0
 async def get(self, *, did: document.convert_doc_id, 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['doc_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['doc_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)