コード例 #1
0
ファイル: training.py プロジェクト: vijos/vj4
 async def get(self, *, sort: str='', page: int=1):
   if sort:
     qs = 'sort={0}'.format(sort)
   else:
     qs = ''
   tdocs, tpcount, _ = await pagination.paginate(training.get_multi(self.domain_id) \
                                                         .sort('doc_id', 1),
                                                 page, self.TRAININGS_PER_PAGE)
   tids = set(tdoc['doc_id'] for tdoc in tdocs)
   tsdict = dict()
   tdict = dict()
   if self.has_priv(builtin.PRIV_USER_PROFILE):
     enrolled_tids = set()
     async for tsdoc in training.get_multi_status(domain_id=self.domain_id,
                                                  uid=self.user['_id'],
                                                  **{'$or': [{'doc_id': {'$in': list(tids)}},
                                                             {'enroll': 1}]}):
       tsdict[tsdoc['doc_id']] = tsdoc
       enrolled_tids.add(tsdoc['doc_id'])
     enrolled_tids -= tids
     if enrolled_tids:
       tdict = await training.get_dict(self.domain_id, enrolled_tids)
   for tdoc in tdocs:
     tdict[tdoc['doc_id']] = tdoc
   self.render('training_main.html', tdocs=tdocs, page=page, tpcount=tpcount, qs=qs,
               tsdict=tsdict, tdict=tdict)
コード例 #2
0
 async def get(self, *, sort: str='', page: int=1):
   if sort:
     qs = 'sort={0}'.format(sort)
   else:
     qs = ''
   tdocs, tpcount, _ = await pagination.paginate(training.get_multi(self.domain_id) \
                                                         .sort('doc_id', 1),
                                                 page, self.TRAININGS_PER_PAGE)
   tids = set(tdoc['doc_id'] for tdoc in tdocs)
   tsdict = dict()
   tdict = dict()
   if self.has_priv(builtin.PRIV_USER_PROFILE):
     enrolled_tids = set()
     async for tsdoc in training.get_multi_status(domain_id=self.domain_id,
                                                  uid=self.user['_id'],
                                                  **{'$or': [{'doc_id': {'$in': list(tids)}},
                                                             {'enroll': 1}]}):
       tsdict[tsdoc['doc_id']] = tsdoc
       enrolled_tids.add(tsdoc['doc_id'])
     enrolled_tids -= tids
     if enrolled_tids:
       tdict = await training.get_dict(self.domain_id, enrolled_tids)
   for tdoc in tdocs:
     tdict[tdoc['doc_id']] = tdoc
   self.render('training_main.html', tdocs=tdocs, page=page, tpcount=tpcount, qs=qs,
               tsdict=tsdict, tdict=tdict)