class CollectHandler(BaseHandler, ): def initialize(self): self.init() self.mequa = MApp() self.musage = MUsage() self.mrel = MAppRel() self.mcollect = MCollect() def get(self, url_str=''): if len(url_str) > 0: url_arr = url_str.split('/') else: return False if url_str == 'list': self.list() elif len(url_arr) == 1 and len(url_str) == 4 : if self.get_current_user(): self.add_or_update(url_str) else: self.set_status('403') return False @tornado.web.authenticated def add_or_update(self, app_id): self.mcollect.add_or_update(self.userinfo.uid, app_id) @tornado.web.authenticated def list(self): self.render('tmpl_applite/collect/list.html', recs_collect = self.mcollect.query_recent(self.userinfo.uid, 20), userinfo = self.userinfo, )
class CollectHandler( BaseHandler, ): def initialize(self): self.init() self.mequa = MApp() self.musage = MUsage() self.mrel = MAppRel() self.mcollect = MCollect() def get(self, url_str=''): if len(url_str) > 0: url_arr = self.parse_url(url_str) else: return False if url_str == 'list': self.list() elif len(url_arr) == 1 and len(url_str) == 4: if self.get_current_user(): self.add_or_update(url_str) else: self.set_status('403') return False @tornado.web.authenticated def add_or_update(self, app_id): self.mcollect.add_or_update(self.userinfo.uid, app_id) @tornado.web.authenticated def list(self): self.render( 'user/collect/list.html', recs_collect=self.mcollect.query_recent(self.userinfo.uid, 20), userinfo=self.userinfo, )
def test_add_or_update(self): self.add_message() user_id = self.user_id app_id = self.post_id MCollect.add_or_update(user_id, app_id) a = MCollect.get_by_signature(user_id, app_id) assert a != None self.tearDown()
def add_mess(self): self.add_message() MCollect.add_or_update(self.user_id, self.post_id) a = MCollect.query_pager_by_all(self.user_id) tf = False for i in a: if i.post_id == self.post_id: tf = True assert tf
def test_count_of_user(self): user_id = self.user_id b = MCollect.count_of_user(user_id) self.add_mess() a = MCollect.count_of_user(user_id) assert a == b + 1 self.tearDown()
def add_or_update(self, app_id): ''' Add or update the category. ''' logger.info('Collect info: user-{0}, uid-{1}'.format( self.userinfo.uid, app_id)) MCollect.add_or_update(self.userinfo.uid, app_id) out_dic = {'success': True} return json.dump(out_dic, self)
def remove_collect(self, post_id): ''' Add or update the category. ''' logger.info('Collect info: user-{0}, uid-{1}'.format( self.userinfo.uid, post_id)) MCollect.remove_collect(self.userinfo.uid, post_id) out_dic = {'success': True} return json.dump(out_dic, self)
def render(self, *args, **kwargs): user_id = args[0] current = int(args[1]) # cat_slug 分类 # current 当前页面 the_count = MCollect.count_of_user(user_id) pager_count = int(the_count / config.CMS_CFG['list_num']) page_num = (pager_count if abs(pager_count - the_count / config.CMS_CFG['list_num']) < 0.1 else pager_count + 1) kwd = { 'page_home': False if current <= 1 else True, 'page_end': False if current >= page_num else True, 'page_pre': False if current <= 1 else True, 'page_next': False if current >= page_num else True, } return self.render_string('modules/post/collect_pager.html', kwd=kwd, pager_num=page_num, page_current=current)
def test_query_recent(self): self.add_mess() user_id = self.user_id a = MCollect.query_recent(user_id) assert a[0].post_id == self.post_id self.tearDown()
def render(self, *args, **kwargs): user_id = args[0] post_id = args[1] en = kwargs.get('en', False) user_collect = MCollect.get_by_signature(user_id, post_id) return self.render_string('modules/widget/collect.html', user_collect=user_collect, en=en)
def test_get_by_signature(self): user_id = self.user_id self.add_mess() a = MCollect.get_by_signature(user_id, self.post_id) assert a != None self.tearDown()
def test_query_pager_by_userid(self): user_id = self.user_id self.add_mess() a = MCollect.query_pager_by_userid(user_id, '1') tf = False for i in a: if i.post_id == self.post_id: tf = True assert tf self.tearDown()
def list(self, list, cur_p=''): if cur_p == '': current_page_num = 1 else: current_page_num = int(cur_p) current_page_num = 1 if current_page_num < 1 else current_page_num num_of_cat = MCollect.count_of_user(self.userinfo.uid) page_num = int(num_of_cat / CMS_CFG['list_num']) + 1 kwd = {'current_page': current_page_num} self.render('misc/collect/list.html', recs_collect=MCollect.query_pager_by_all( self.userinfo.uid, current_page_num).naive(), pager=tools.gen_pager_purecss('/collect/{0}'.format(list), page_num, current_page_num), userinfo=self.userinfo, cfg=CMS_CFG, kwd=kwd)
def render(self, *args, **kwargs): user_id = kwargs.get('user_id', args[0]) kind = kwargs.get('kind', args[1]) num = kwargs.get('num', args[2] if len(args) > 2 else 6) with_tag = kwargs.get('with_tag', False) glyph = kwargs.get('glyph', '') all_cats = MCollect.query_pager_by_userid(user_id, kind, num).objects() kwd = {'with_tag': with_tag, 'glyph': glyph} return self.render_string('modules/widget/user_collect.html', recs=all_cats, kwd=kwd)
def show_list(self, the_list, cur_p=''): ''' List of the user collections. ''' current_page_num = int(cur_p) if cur_p else 1 current_page_num = 1 if current_page_num < 1 else current_page_num num_of_cat = MCollect.count_of_user(self.userinfo.uid) page_num = int(num_of_cat / CMS_CFG['list_num']) + 1 kwd = {'current_page': current_page_num} self.render('misc/collect/list.html', recs_collect=MCollect.query_pager_by_all( self.userinfo.uid, current_page_num).objects(), pager=tools.gen_pager_purecss( '/collect/{0}'.format(the_list), page_num, current_page_num), userinfo=self.userinfo, cfg=CMS_CFG, kwd=kwd)
def test_query_recent(self): user_id = self.user_id MCollect.query_recent(user_id) assert True
def test_get_by_signature(self): user_id = self.user_id app_id = '11111' MCollect.get_by_signature(user_id, app_id) assert True
def Test(): assert MCollect()
def initialize(self): self.init() self.mequa = MApp() self.musage = MUsage() self.mrel = MAppRel() self.mcollect = MCollect()
def test_count_of_user(self): user_id = self.user_id MCollect.count_of_user(user_id) assert True
def initialize(self): self.init() self.mequa = MInfor() self.musage = MUsage() self.mrel = MInforRel() self.mcollect = MCollect()
def test_query_pager_by_all(self): user_id = self.user_id MCollect.query_pager_by_all(user_id) assert True
def list(self): self.render('misc/collect/list.html', recs_collect=MCollect.query_recent(self.userinfo.uid, 20), userinfo=self.userinfo)
def test_add_or_update(self): user_id = self.user_id app_id = '11111' MCollect.add_or_update(user_id, app_id) assert True
def test_query_pager_by_userid(self): user_id = self.user_id kind = '1' MCollect.query_pager_by_userid(user_id, kind) assert True
def test_remove_collect(self): MCollect.remove_collect(self.user_id, self.post_id) rec = MCollect.get_by_signature(self.user_id, self.post_id) assert rec == None self.tearDown()