def viewinfo(self, postinfo): ''' In infor. :param postinfo: :return: ''' self.redirect_kind(postinfo) ext_catid = postinfo.extinfo[ 'def_cat_uid'] if 'def_cat_uid' in postinfo.extinfo else '' ext_catid2 = postinfo.extinfo[ 'def_cat_uid'] if 'def_cat_uid' in postinfo.extinfo else None cat_enum1 = MCategory.get_qian2(ext_catid2[:2]) if ext_catid else [] rand_recs, rel_recs = self.fetch_additional_posts(postinfo.uid) self._chuli_cookie_relation(postinfo.uid) catinfo = None p_catinfo = None post2catinfo = MPost2Catalog.get_first_category(postinfo.uid) if post2catinfo: catinfo = MCategory.get_by_uid(post2catinfo.tag_id) if catinfo: p_catinfo = MCategory.get_by_uid(catinfo.pid) kwd = self._the_view_kwd(postinfo) MPost.update_misc(postinfo.uid, count=True) if self.get_current_user(): MUsage.add_or_update(self.userinfo.uid, postinfo.uid, postinfo.kind) self.set_cookie('user_pass', kwd['cookie_str']) tmpl = self.ext_tmpl_view(postinfo) if self.userinfo: recent_apps = MUsage.query_recent(self.userinfo.uid, postinfo.kind, 6).naive()[1:] else: recent_apps = [] logger.info('The Info Template: {0}'.format(tmpl)) self.render( tmpl, kwd=dict(kwd, **self.ext_view_kwd(postinfo)), postinfo=postinfo, userinfo=self.userinfo, author=postinfo.user_name, # Todo: remove the key `author`. catinfo=catinfo, pcatinfo=p_catinfo, relations=rel_recs, rand_recs=rand_recs, unescape=tornado.escape.xhtml_unescape, ad_switch=random.randint(1, 18), # tag_info=MPost2Label.get_by_uid(postinfo.uid).naive(), tag_info=filter(lambda x: not x.tag_name.startswith('_'), MPost2Label.get_by_uid(postinfo.uid).naive()), recent_apps=recent_apps, cat_enum=cat_enum1)
def errcat(self): ''' List the posts to be modified. ''' post_recs = MPost.query_random(limit=1000) outrecs = [] errrecs = [] idx = 0 for postinfo in post_recs: if idx > 16: break cat = MPost2Catalog.get_first_category(postinfo.uid) if cat: if 'def_cat_uid' in postinfo.extinfo: if postinfo.extinfo['def_cat_uid'] == cat.tag_id: pass else: errrecs.append(postinfo) idx += 1 else: errrecs.append(postinfo) idx += 1 else: outrecs.append(postinfo) idx += 1 self.render('list/errcat.html', kwd={}, norecs=outrecs, errrecs=errrecs, userinfo=self.userinfo)
def add_or_update(user_id, post_id, kind): ''' Create the record if new, else update it. ''' rec = MUsage.query_by_signature(user_id, post_id) cate_rec = MInfor2Catalog.get_first_category(post_id) if cate_rec: cat_id = cate_rec.tag_id else: return False if rec.count() > 0: logger.info('Usage update: {uid}'.format(uid=post_id)) rec = rec.get() query = TabUsage.update(kind=kind).where(TabUsage.uid == rec.uid) query.execute() MUsage.count_increate(rec.uid, cat_id, rec.count) else: logger.info('Usage create: {uid}'.format(uid=post_id)) TabUsage.create( uid=tools.get_uuid(), post_id=post_id, user_id=user_id, count=1, tag_id=cat_id, timestamp=int(time.time()), kind=kind, )
def viewinfo(self, postinfo): ''' 查看 Post. ''' self.redirect_kind(postinfo) __ext_catid = postinfo.extinfo.get('def_cat_uid', '') cat_enum1 = MCategory.get_qian2(__ext_catid[:2]) if __ext_catid else [] rand_recs, rel_recs = self.fetch_additional_posts(postinfo.uid) self._chuli_cookie_relation(postinfo.uid) catinfo = None p_catinfo = None post2catinfo = MPost2Catalog.get_first_category(postinfo.uid) if post2catinfo: catinfo = MCategory.get_by_uid(post2catinfo.tag_id) if catinfo: p_catinfo = MCategory.get_by_uid(catinfo.pid) kwd = self._the_view_kwd(postinfo) MPost.update_misc(postinfo.uid, count=True) MAcces.add(postinfo.uid) if self.get_current_user() and self.userinfo: MUsage.add_or_update(self.userinfo.uid, postinfo.uid, postinfo.kind) self.set_cookie('user_pass', kwd['cookie_str']) tmpl = self.ext_tmpl_view(postinfo) if self.userinfo: recent_apps = MUsage.query_recent(self.userinfo.uid, postinfo.kind, 6).objects()[1:] else: recent_apps = [] logger.info('The Info Template: {0}'.format(tmpl)) self.render( tmpl, kwd=dict(kwd, **self.ext_view_kwd(postinfo)), postinfo=postinfo, userinfo=self.userinfo, author=postinfo.user_name, # Todo: remove the key `author`. catinfo=catinfo, pcatinfo=p_catinfo, relations=rel_recs, rand_recs=rand_recs, subcats=MCategory.query_sub_cat(p_catinfo.uid) if p_catinfo else '', ad_switch=random.randint(1, 18), tag_info=filter(lambda x: not x.tag_name.startswith('_'), MPost2Label.get_by_uid(postinfo.uid).objects()), recent_apps=recent_apps, cat_enum=cat_enum1)
def get_app_relations(app_id, num=20, kind='1'): ''' The the related infors. ''' info_tag = MInfor2Catalog.get_first_category(app_id) if info_tag: return TabPost2Tag.select( TabPost2Tag, TabPost.title.alias('post_title'), TabPost.valid.alias('post_valid') ).join( TabPost, on=(TabPost2Tag.post_id == TabPost.uid) ).where( (TabPost2Tag.tag_id == info_tag.tag_id) & (TabPost.kind == kind) ).order_by( peewee.fn.Random() ).limit(num) return TabPost2Tag.select( TabPost2Tag, TabPost.title.alias('post_title'), TabPost.valid.alias('post_valid') ).join( TabPost, on=(TabPost2Tag.post_id == TabPost.uid) ).where( TabPost.kind == kind ).order_by(peewee.fn.Random()).limit(num)
def check_tag(): ''' Checking the post of error tags. ''' print('Checking tag error: ') tstr = '' idx = 1 for kind in config.router_post.keys(): posts = MPost.query_all(kind=kind, limit=20000) for post in posts: p_catinfo = None post2catinfo = MPost2Catalog.get_first_category(post.uid) if post2catinfo: catinfo = MCategory.get_by_uid(post2catinfo.tag_id) if catinfo: p_catinfo = MCategory.get_by_uid(catinfo.pid) if post.extinfo.get('def_cat_pid') and post.extinfo.get( 'gcat0') and p_catinfo: pass else: the_url0 = '{site_url}/{kind_url}/{uid}'.format( site_url=config.SITE_CFG['site_url'], kind_url=config.router_post[post.kind], uid=post.uid) the_url = '{site_url}/{kind_url}/_edit/{uid}'.format( site_url=config.SITE_CFG['site_url'], kind_url=config.router_post[post.kind], uid=post.uid) the_url2 = '{site_url}/{kind_url}/_edit_kind/{uid}'.format( site_url=config.SITE_CFG['site_url'], kind_url=config.router_post[post.kind], uid=post.uid) req = requests.get(the_url0) if req.status_code == 200: pass else: print(the_url0) tstr = tstr + DT_STR.format( idx=str(idx).zfill(2), url0=the_url0, code=req.status_code, edit_link=the_url, edit_tag_link=the_url2, ) idx = idx + 1 time_local = time.localtime(timestamp()) with open( 'xx_err_tag_{d}.html'.format( d=str(time.strftime("%Y_%m_%d", time_local))), 'w') as fileo: fileo.write(HTML_TMPL.format(cnt=tstr)) print('Checking 200 finished.')
def _to_edit(self, infoid): ''' render the HTML page for post editing. ''' postinfo = MPost.get_by_uid(infoid) if postinfo: pass else: return self.show404() if 'def_cat_uid' in postinfo.extinfo: catid = postinfo.extinfo['def_cat_uid'] else: catid = '' if len(catid) == 4: pass else: catid = '' catinfo = None p_catinfo = None post2catinfo = MPost2Catalog.get_first_category(postinfo.uid) if post2catinfo: catid = post2catinfo.tag_id catinfo = MCategory.get_by_uid(catid) if catinfo: p_catinfo = MCategory.get_by_uid(catinfo.pid) kwd = { 'def_cat_uid': catid, 'parentname': '', 'catname': '', 'parentlist': MCategory.get_parent_list(), 'userip': self.request.remote_ip, 'extinfo': json.dumps(postinfo.extinfo, indent=2, ensure_ascii=False), } if self.filter_view: tmpl = 'autogen/edit/edit_{0}.html'.format(catid) else: tmpl = 'post_{0}/post_edit.html'.format(self.kind) logger.info('Meta template: {0}'.format(tmpl)) self.render(tmpl, kwd=kwd, postinfo=postinfo, catinfo=catinfo, pcatinfo=p_catinfo, userinfo=self.userinfo, cat_enum=MCategory.get_qian2(catid[:2]), tag_infos=MCategory.query_all(by_order=True, kind=self.kind), tag_infos2=MCategory.query_all(by_order=True, kind=self.kind), app2tag_info=MPost2Catalog.query_by_entity_uid(infoid, kind=self.kind).objects(), app2label_info=MPost2Label.get_by_uid(infoid).objects())
def test_get_first_category(self): self.add_message() self.add_P2C() a = MPost2Catalog.get_first_category(self.post_id) b = MPost2Catalog.del_by_uid(a) assert b self.tearDown()
def viewinfo(self, postinfo): ''' In infor. :param postinfo: :return: ''' self.redirect_kind(postinfo) ###################################################### if DB_CFG['kind'] == 's': cat_enum1 = [] else: ext_catid = postinfo.extinfo['def_cat_uid'] if 'def_cat_uid' in postinfo.extinfo else '' ext_catid2 = postinfo.extinfo[ 'def_cat_uid'] if 'def_cat_uid' in postinfo.extinfo else None cat_enum1 = MCategory.get_qian2(ext_catid2[:2]) if ext_catid else [] ###################################################### catinfo = None p_catinfo = None post2catinfo = MPost2Catalog.get_first_category(postinfo.uid) catalog_infors = None if post2catinfo: catinfo = MCategory.get_by_uid(post2catinfo.tag_id) if catinfo: p_catinfo = MCategory.get_by_uid(catinfo.pid) catalog_infors = MPost2Catalog.query_pager_by_slug(catinfo.slug, current_page_num=1, order=True) kwd = self._the_view_kwd(postinfo) MPost.update_misc(postinfo.uid, count=True) if self.get_current_user(): MUsage.add_or_update(self.userinfo.uid, postinfo.uid, postinfo.kind) tmpl = 'post_{0}/leaf_view.html'.format(self.kind) logger.info('The Info Template: {0}'.format(tmpl)) self.render(tmpl, kwd=dict(kwd, **self.ext_view_kwd(postinfo)), postinfo=postinfo, userinfo=self.userinfo, catinfo=catinfo, pcatinfo=p_catinfo, unescape=tornado.escape.xhtml_unescape, ad_switch=random.randint(1, 18), tag_info=MPost2Label.get_by_uid(postinfo.uid), catalog_infos=catalog_infors, cat_enum=cat_enum1)
def get_app_relations(app_id, num=20, kind='1'): ''' The the related infors. 如有标签按标签推荐,如无标签按分类推荐 ''' tag_info = filter(lambda x: not x.tag_name.startswith('_'), MPost2Label.get_by_uid(app_id).objects()) info_tag = MInfor2Catalog.get_first_category(app_id) tag_arr = [] for tag in tag_info: tag_arr.append(tag.tag_uid) if len(tag_arr) > 0: recs = TabPost2Tag.select( TabPost2Tag, TabPost.title.alias('post_title'), TabPost.valid.alias('post_valid')).join( TabPost, on=(TabPost2Tag.post_id == TabPost.uid )).where((TabPost2Tag.tag_id << tag_arr) & (TabPost.uid != app_id) & (TabPost.kind == kind) & (TabPost.valid == 1)).distinct( TabPost2Tag.post_id).order_by( TabPost2Tag.post_id).limit(num) if recs.count() == 0: recs = TabPost2Tag.select( TabPost2Tag, TabPost.title.alias('post_title'), TabPost.valid.alias('post_valid')).join( TabPost, on=(TabPost2Tag.post_id == TabPost.uid )).where((TabPost.uid != app_id) & (TabPost2Tag.tag_id == info_tag.tag_id) & (TabPost.kind == kind) & (TabPost.valid == 1)).order_by( peewee.fn.Random()).limit(num) else: recs = TabPost2Tag.select( TabPost2Tag, TabPost.title.alias('post_title'), TabPost.valid.alias('post_valid')).join( TabPost, on=(TabPost2Tag.post_id == TabPost.uid )).where((TabPost.uid != app_id) & (TabPost2Tag.tag_id == info_tag.tag_id) & (TabPost.kind == kind) & (TabPost.valid == 1)).order_by( peewee.fn.Random()).limit(num) return recs
def get_app_relations(app_id, num=20, kind='1'): ''' The the related infors. ''' info_tag = MInfor2Catalog.get_first_category(app_id) if info_tag: return g_Post2Tag.select().join( g_Post).where((g_Post2Tag.tag == info_tag.tag.uid) & (g_Post.kind == kind)).order_by( peewee.fn.Random()).limit(num) else: return g_Post2Tag.select().join(g_Post).where( g_Post.kind == kind).order_by(peewee.fn.Random()).limit(num)
def viewinfo(self, postinfo): ''' In infor. :param postinfo: :return: ''' logger.warning('info kind:{0} '.format(postinfo.kind)) # If not, there must be something wrong. if postinfo.kind == self.kind: pass else: self.redirect('/{0}/{1}'.format(router_post[postinfo.kind], postinfo.uid), permanent=True) ext_catid = postinfo.extinfo['def_cat_uid'] if 'def_cat_uid' in postinfo.extinfo else '' ext_catid2 = postinfo.extinfo['def_cat_uid'] if 'def_cat_uid' in postinfo.extinfo else None cat_enum1 = MCategory.get_qian2(ext_catid2[:2]) if ext_catid else [] rand_recs, rel_recs = self.fetch_additional_posts(postinfo.uid) self.__chuli_cookie_relation(postinfo.uid) cookie_str = tools.get_uuid() catinfo = None p_catinfo = None post2catinfo = MPost2Catalog.get_first_category(postinfo.uid) if post2catinfo: catinfo = MCategory.get_by_uid(post2catinfo.tag.uid) if catinfo: p_catinfo = MCategory.get_by_uid(catinfo.pid) kwd = { 'pager': '', 'url': self.request.uri, 'cookie_str': cookie_str, 'daohangstr': '', 'signature': postinfo.uid, 'tdesc': '', 'eval_0': MEvaluation.app_evaluation_count(postinfo.uid, 0), 'eval_1': MEvaluation.app_evaluation_count(postinfo.uid, 1), 'login': 1 if self.get_current_user() else 0, 'has_image': 0, 'parentlist': MCategory.get_parent_list(), 'parentname': '', 'catname': '', 'router': router_post[postinfo.kind] } MPost.update_misc(postinfo.uid, count=True) if self.get_current_user(): MUsage.add_or_update(self.userinfo.uid, postinfo.uid, postinfo.kind) self.set_cookie('user_pass', cookie_str) tmpl = self.ext_tmpl_view(postinfo) if self.userinfo: recent_apps = MUsage.query_recent(self.userinfo.uid, postinfo.kind, 6)[1:] else: recent_apps = [] logger.info('The Info Template: {0}'.format(tmpl)) self.render(tmpl, kwd=dict(kwd, **self.ext_view_kwd(postinfo)), postinfo=postinfo, calc_info=postinfo, # Deprecated post_info=postinfo, # Deprecated userinfo=self.userinfo, catinfo=catinfo, pcatinfo=p_catinfo, relations=rel_recs, rand_recs=rand_recs, unescape=tornado.escape.xhtml_unescape, ad_switch=random.randint(1, 18), tag_info=MPost2Label.get_by_uid(postinfo.uid), recent_apps=recent_apps, cat_enum=cat_enum1)
def __to_edit(self, infoid): ''' render the HTML page for post editing. :param infoid: :return: ''' if self.check_post_role()['EDIT']: pass else: return False rec_info = MPost.get_by_uid(infoid) postinfo = rec_info if rec_info: pass else: self.render('html/404.html') return if 'def_cat_uid' in rec_info.extinfo: catid = rec_info.extinfo['def_cat_uid'] else: catid = '' if len(catid) == 4: pass else: catid = '' catinfo = None p_catinfo = None post2catinfo = MPost2Catalog.get_first_category(postinfo.uid) if post2catinfo: catid = post2catinfo.tag.uid catinfo = MCategory.get_by_uid(catid) if catinfo: p_catinfo = MCategory.get_by_uid(catinfo.pid) kwd = { 'def_cat_uid': catid, 'parentname': '', 'catname': '', 'parentlist': MCategory.get_parent_list(), 'userip': self.request.remote_ip} if self.filter_view: tmpl = 'autogen/edit/edit_{0}.html'.format(catid) else: tmpl = 'post_{0}/post_edit.html'.format(self.kind) logger.info('Meta template: {0}'.format(tmpl)) self.render(tmpl, kwd=kwd, calc_info=rec_info, # Deprecated post_info=rec_info, # Deprecated app_info=rec_info, # Deprecated postinfo=rec_info, catinfo=catinfo, pcatinfo=p_catinfo, userinfo=self.userinfo, unescape=tornado.escape.xhtml_unescape, cat_enum=MCategory.get_qian2(catid[:2]), tag_infos=MCategory.query_all(by_order=True, kind=self.kind), tag_infos2=MCategory.query_all(by_order=True, kind=self.kind), app2tag_info=MPost2Catalog.query_by_entity_uid(infoid, kind=self.kind), app2label_info=MPost2Label.get_by_uid(infoid, kind=self.kind + '1'))
def viewinfo(self, postinfo): ''' In infor. :param postinfo: :return: ''' logger.warning('info kind:{0} '.format(postinfo.kind)) # If not, there must be something wrong. if postinfo.kind == self.kind: pass else: self.redirect('/{0}/{1}'.format(router_post[postinfo.kind], postinfo.uid), permanent=True) ###################################################### if DB_CFG['kind'] == 's': cat_enum1 = [] else: ext_catid = postinfo.extinfo['def_cat_uid'] if 'def_cat_uid' in postinfo.extinfo else '' ext_catid2 = postinfo.extinfo['def_cat_uid'] if 'def_cat_uid' in postinfo.extinfo else None cat_enum1 = MCategory.get_qian2(ext_catid2[:2]) if ext_catid else [] ###################################################### catinfo = None p_catinfo = None post2catinfo = MPost2Catalog.get_first_category(postinfo.uid) catalog_infors = None if post2catinfo: catinfo = MCategory.get_by_uid(post2catinfo.tag.uid) if catinfo: p_catinfo = MCategory.get_by_uid(catinfo.pid) catalog_infors = MPost2Catalog.query_pager_by_slug(catinfo.slug, current_page_num=1, order=True) kwd = { 'pager': '', 'url': self.request.uri, 'daohangstr': '', 'signature': postinfo.uid, 'tdesc': '', 'eval_0': MEvaluation.app_evaluation_count(postinfo.uid, 0), 'eval_1': MEvaluation.app_evaluation_count(postinfo.uid, 1), 'login': 1 if self.get_current_user() else 0, 'has_image': 0, 'parentlist': MCategory.get_parent_list(), 'parentname': '', 'catname': '', 'router': router_post[postinfo.kind] } MPost.update_misc(postinfo.uid, count=True) if self.get_current_user(): MUsage.add_or_update(self.userinfo.uid, postinfo.uid, postinfo.kind) tmpl = 'post_{0}/leaf_view.html'.format(self.kind) logger.info('The Info Template: {0}'.format(tmpl)) self.render(tmpl, kwd=dict(kwd, **self.ext_view_kwd(postinfo)), postinfo=postinfo, userinfo=self.userinfo, catinfo=catinfo, pcatinfo=p_catinfo, unescape=tornado.escape.xhtml_unescape, ad_switch=random.randint(1, 18), tag_info=MPost2Label.get_by_uid(postinfo.uid), catalog_infos=catalog_infors, cat_enum=cat_enum1)
def test_get_first_category(self): MPost2Catalog.get_first_category(self.uid) assert True