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 add_usage(self): MUsage.add_or_update(self.userid, self.postid, '1') aa = MUsage.query_by_post(self.postid) for i in aa: if i.user_id == self.userid: self.uid = i.uid
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 show_geojson(self, gid): kwd = { 'pager': '', 'url': self.request.uri, 'geojson': gid, 'tdesc': '', 'login': 1 if self.get_current_user() else 0 } map_hist = [] if self.get_secure_cookie('map_hist'): for xx in range( 0, len(self.get_secure_cookie('map_hist').decode('utf-8')), 4): map_hist.append( self.get_secure_cookie('map_hist').decode('utf-8')[xx:xx + 4]) recent_apps = MUsage.query_recent(self.get_current_user(), 'm', 6)[1:] if self.userinfo else [] print('=' * 20) for x in recent_apps: print(x.uid) self.render( 'post_m/full_screen_draw.html', kwd=kwd, userinfo=self.userinfo, unescape=tornado.escape.xhtml_unescape, recent_apps=MUsage.query_recent(self.userinfo.uid, 'm', 6)[1:] if self.userinfo else [])
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 initialize(self, hinfo=''): self.init() self.mevaluation = MEvaluation() self.mapp2catalog = MApp2Catalog() self.mapp2tag = MApp2Label() self.minfo = MApp() self.musage = MUsage() self.mcat = MInforCatalog() self.mrel = MAppRel() self.mreply = MApp2Reply()
def add_usage(self, **kwargs): id = kwargs.get('post_id', self.postid) MUsage.add_or_update(self.userid, id, '1') aa = MUsage.query_by_post(id) print('add_usage') print(aa) for i in aa: if i.user_id == self.userid: self.uid = i.uid print(self.uid)
def initialize(self, hinfo=''): self.init() self.mevaluation = MEvaluation() self.mapp2catalog = MInfor2Catalog() self.mapp2tag = MInfor2Label() self.minfo = MInfor() self.musage = MUsage() self.mcat = MCategory() self.mrel = MInforRel() # self.mreply = MInfor2Reply() self.kind = '2'
def initialize(self, hinfo=''): self.init() self.mevaluation = MEvaluation() self.mpost2label = MInfor2Label() self.mpost2catalog = MInfor2Catalog() self.mpost = MInfor() self.musage = MUsage() self.mcat = MCategory() self.mrel = MInforRel() self.mreply = MReply() self.mpost_hist = MInfoHist() self.kind = '2' self.sig = '2' # '1' for maplet, '2' for drr
def test_count_increate(self): self.add_message() self.add_usage() MUsage.count_increate(self.uid, self.tag_id, 8) aa = MUsage.query_recent(self.userid, '1') tf = False for i in aa: if i.user_id == self.userid: assert i.count >= 8 tf = True break self.tearDown() assert tf
def test_add_or_update(self): self.add_message() MUsage.add_or_update(self.userid, self.postid, '1') aa = MUsage.query_recent(self.userid, '1') tf = False for i in aa: if i.user_id == self.userid: self.uid = i.uid assert i.post_id == self.postid tf = True break self.tearDown() assert tf
def render_user(self, *args, **kwargs): ''' Render user. :param args: :param kwargs: :return: ''' kind = args[0] num = args[1] with_tag = kwargs['with_tag'] if 'with_tag' in kwargs else False user_id = kwargs['user_id'] if 'user_id' in kwargs else '' glyph = kwargs['glyph'] if 'glyph' in kwargs else '' all_cats = MUsage.query_most(user_id, kind, num).naive() kwd = { 'with_tag': with_tag, 'router': router_post[kind], 'glyph': glyph } return self.render_string('modules/info/list_user_equation.html', recs=all_cats, kwd=kwd)
def render(self, *args, **kwargs): ''' fun(user_name, kind) fun(user_name, kind, num) fun(user_name, kind, num, with_tag = val1, glyph = val2) fun(user_name = vala, kind = valb, num = valc, with_tag = val1, glyph = val2) ''' # kind = kwargs.get('kind', args[0] if len(args) > 0 else '1') # user_name = args[0] # kind = args[1] # num = args[2] # with_tag = kwargs['with_tag'] if 'with_tag' in kwargs else False # glyph = kwargs['glyph'] if 'glyph' in kwargs else '' user_name = kwargs.get('user_name', 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 = MUsage.query_most(user_name, kind, num).naive() kwd = { 'with_tag': with_tag, 'router': router_post[kind], 'glyph': glyph } return self.render_string('modules/info/list_user_equation.html', recs=all_cats, kwd=kwd)
def render(self, *args, **kwargs): ''' fun(user_name, catid) fun(user_name, catid, num) fun(user_name, catid, num, glyph = val1) ''' # user_name = args[0] # cat_id = args[1] # num = args[2] # glyph = kwargs['glyph'] if 'glyph' in kwargs else '' user_name = kwargs.get('user_name', args[0]) cat_id = kwargs.get('cat_id', args[1]) num = kwargs.get('num', args[2] if len(args) > 2 else 6) glyph = kwargs.get('glyph', '') all_cats = MUsage.query_recent_by_cat(user_name, cat_id, num).naive() kwd = { 'glyph': glyph } return self.render_string('modules/info/list_user_equation_no_catalog.html', recs=all_cats, kwd=kwd)
def render_user(self, *args, **kwargs): ''' render, with userinfo ''' kind = args[0] num = args[1] with_tag = kwargs['with_tag'] if 'with_tag' in kwargs else False user_id = kwargs['user_id'] if 'user_id' in kwargs else '' glyph = kwargs['glyph'] if 'glyph' in kwargs else '' logger.info('Infor user recent, username: {user_name}, kind: {kind}, num: {num}'.format( user_name=user_id, kind=kind, num=num )) all_cats = MUsage.query_recent(user_id, kind, num).naive() kwd = { 'with_tag': with_tag, 'router': router_post[kind], 'glyph': glyph } return self.render_string('modules/info/list_user_equation.html', recs=all_cats, kwd=kwd)
def render_user(self, *args, **kwargs): ''' render, with userinfo fun(kind, num) fun(kind, num, with_tag = val1) fun(kind, num, with_tag = val1, user_id = val2) fun(kind, num, with_tag = val1, user_id = val2, glyph = val3) ''' kind = kwargs.get('kind', args[0]) num = kwargs.get('num', args[1] if len(args) > 1 else 6) with_tag = kwargs.get('with_tag', False) user_id = kwargs.get('user_id', '') glyph = kwargs.get('glyph', '') logger.info( 'Infor user recent, username: {user_name}, kind: {kind}, num: {num}' .format(user_name=user_id, kind=kind, num=num)) all_cats = MUsage.query_recent(user_id, kind, num).objects() kwd = { 'with_tag': with_tag, 'router': router_post[kind], 'glyph': glyph } return self.render_string('modules/info/list_user_equation.html', recs=all_cats, kwd=kwd)
def render_user(self, *args, **kwargs): ''' Render user. fun(kind, num) fun(kind, num, with_tag = val1) fun(kind, num, with_tag = val1, user_id = val2) fun(kind, num, with_tag = val1, user_id = val2, glyph = val3) ''' # kind = args[0] # num = args[1] # # with_tag = kwargs['with_tag'] if 'with_tag' in kwargs else False # # user_id = kwargs['user_id'] if 'user_id' in kwargs else '' # # glyph = kwargs['glyph'] if 'glyph' in kwargs else '' kind = kwargs.get('kind', args[0]) num = kwargs.get('num', args[1] if len(args) > 1 else 6) with_tag = kwargs.get('with_tag', False) user_id = kwargs.get('user_id', '') glyph = kwargs.get('glyph', '') all_cats = MUsage.query_most(user_id, kind, num).naive() kwd = { 'with_tag': with_tag, 'router': router_post[kind], 'glyph': glyph } return self.render_string('modules/info/list_user_equation.html', recs=all_cats, kwd=kwd)
def test_query_by_signature(self): self.add_message() self.add_usage() aa = MUsage.query_by_signature(self.userid, self.postid) assert aa[0].uid == self.uid self.tearDown()
def test_update_field(self): self.add_message() self.add_usage() aa = MUsage.query_recent(self.userid, '1') tf = False for i in aa: if i.user_id == self.userid: self.uid = i.uid assert i.post_id == self.postid tf = True assert tf p = {'post_id': self.postid2} self.add_message(**p) a = MPost.get_by_uid(self.postid2) MUsage.update_field(self.uid, post_id=self.postid2) aa = MUsage.query_recent(self.userid, '1') tf = False for i in aa: if i.user_id == self.userid: assert i.post_id == self.postid2 tf = True assert tf MUsage.update_field(self.uid, self.postid) aa = MUsage.query_recent(self.userid, '1') tf = False for i in aa: if i.user_id == self.userid: assert i.post_id == self.postid tf = True assert tf MPost.delete(self.postid2) self.tearDown()
def initialize(self, hinfo=''): self.init() self.mevaluation = MEvaluation() self.mapp2catalog = MApp2Catalog() self.mapp2tag = MApp2Label() self.minfo = MApp() self.musage = MUsage() self.mcat = MAppCatalog() self.mrel = MAppRel() self.mreply = MApp2Reply()
def test_query_recent(self): self.add_message() self.add_usage() aa = MUsage.query_recent(self.userid, '1', num=30) tf = False for i in aa: if i.post_id == self.postid: assert i.uid == self.uid tf = True assert tf self.tearDown()
def test_query_random(self): self.add_message() self.add_usage() aa = MUsage.query_random(limit=30) tf = False for i in aa: if i.post_id == self.postid: assert i.uid == self.uid tf = True assert tf self.tearDown()
def test_query_recent_by_cat(self): self.add_message() self.add_usage() aa = MUsage.query_recent_by_cat(self.userid, self.tag_id, 8) tf = False for i in aa: if i.post_id == self.postid: assert i.uid == self.uid tf = True break self.tearDown() assert tf
def test_query_most(self): self.add_message() self.add_usage() aa = MUsage.query_most(self.userid, '1', 8) print(aa.count()) tf = False for i in aa: if i.post_id == self.postid: assert i.uid == self.uid tf = True assert tf self.tearDown()
def test_query_by_post(self): self.add_message() self.add_usage() aa = MUsage.query_by_post(self.postid) tf = False for i in aa: if i.user_id == self.userid: assert i.uid == self.uid tf = True break self.tearDown() assert tf
def render(self, *args, **kwargs): user_name = args[0] cat_id = args[1] num = args[2] glyph = kwargs['glyph'] if 'glyph' in kwargs else '' all_cats = MUsage.query_recent_by_cat(user_name, cat_id, num).naive() kwd = {'glyph': glyph} return self.render_string( 'modules/info/list_user_equation_no_catalog.html', recs=all_cats, kwd=kwd)
def initialize(self): self.init() self.mpost = MInfor() self.mcat = MCategory() self.cats = self.mcat.query_all() self.mpost_hist = MInfoHist() self.mpost2catalog = MInfor2Catalog() self.mpost2reply = MInfor2Reply() self.mpost2label = MInfor2Label() self.mrel = MInforRel() self.musage = MUsage() self.mevaluation = MEvaluation() self.kind = '2'
def initialize(self): self.init() self.mappcat = MInforCatalog() self.mevaluation = MEvaluation() self.mapp2catalog = MApp2Catalog() self.mapp2tag = MApp2Label() self.mapp = MApp() self.musage = MUsage() self.mtag = MInforCatalog() self.mrel = MAppRel() self.mreply = MApp2Reply() if 'app_url_name' in cfg: self.app_url_name = cfg['app_url_name'] else: self.app_url_name = 'info'
def render(self, *args, **kwargs): user_name = args[0] kind = args[1] num = args[2] with_tag = kwargs['with_tag'] if 'with_tag' in kwargs else False glyph = kwargs['glyph'] if 'glyph' in kwargs else '' all_cats = MUsage.query_recent(user_name, kind, num).naive() kwd = { 'with_tag': with_tag, 'router': router_post[kind], 'glyph': glyph } return self.render_string('modules/info/list_user_equation.html', recs=all_cats, kwd=kwd)
class InfoHandler(BaseHandler): def initialize(self, hinfo=''): self.init() self.mevaluation = MEvaluation() self.mapp2catalog = MApp2Catalog() self.mapp2tag = MApp2Label() self.minfo = MApp() self.musage = MUsage() self.mcat = MInforCatalog() self.mrel = MAppRel() self.mreply = MApp2Reply() def get(self, url_str=''): url_arr = self.parse_url(url_str) if len(url_arr) == 1 and len(url_str) == 4: self.view_info(url_str) else: kwd = { 'title': '', 'info': '', } self.render('html/404.html', kwd=kwd, userinfo=self.userinfo, ) def post(self, url_str=''): url_arr = self.parse_url(url_str) if url_arr[0] == 'rel': if self.get_current_user(): self.add_relation(url_arr[1], url_arr[2]) else: self.redirect('/user/login') elif url_arr[0] == 'comment_add': self.add_comment(url_arr[1]) else: return False @tornado.web.authenticated def add_comment(self, id_post): post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) post_data['user_id'] = self.userinfo.uid post_data['user_name'] = self.userinfo.user_name comment_uid = self.mreply.insert_data(post_data, id_post) if comment_uid: output = { 'pinglun': comment_uid, } else: output = { 'pinglun': 0, } return json.dump(output, self) def view_info(self, info_id): ''' Render the info :param info_id: :return: Nonthing. ''' rec = self.minfo.get_by_uid(info_id) if rec: pass else: kwd = { 'info': '您要找的信息不存在。', } self.render('html/404.html', kwd=kwd, userinfo=self.userinfo, ) return False replys = self.mreply.get_by_id(info_id) rel_recs = self.mrel.get_app_relations(rec.uid, 4) rand_recs = self.minfo.query_random(4 - rel_recs.count() + 2) self.chuli_cookie_relation(info_id) cookie_str = tools.get_uuid() if 'def_cat_uid' in rec.extinfo: catid = rec.extinfo['def_cat_uid'] else: catid = '' parent_name = self.mcat.get_by_id(catid[:2] + '00').name if catid != '' else '' if catid != '': cat_rec = self.mcat.get_by_uid(catid) priv_mask_idx = cat_rec.priv_mask.index('1') cat_name = cat_rec.name else: priv_mask_idx = 0 cat_name = '' parentname = '<a href="/list/{0}">{1}</a>'.format(catid[:2] + '00', parent_name) catname = '<a href="/list/{0}">{1}</a>'.format(catid, cat_name) kwd = { 'pager': '', 'url': self.request.uri, 'cookie_str': cookie_str, 'daohangstr': '', 'signature': info_id, 'tdesc': '', 'eval_0': self.mevaluation.app_evaluation_count(info_id, 0), 'eval_1': self.mevaluation.app_evaluation_count(info_id, 1), 'site_url': config.site_url, 'login': 1 if self.get_current_user() else 0, 'has_image': 0, 'parentlist': self.mcat.get_parent_list(), 'parentname': parentname, 'catname': catname, } self.minfo.view_count_increase(info_id) if self.get_current_user(): self.musage.add_or_update(self.userinfo.uid, info_id) self.set_cookie('user_pass', cookie_str) tmpl = self.ext_tmpl_name(rec) if self.ext_tmpl_name(rec) else self.get_tmpl_name(rec) catid = rec.extinfo['def_cat_uid'] if 'def_cat_uid' in rec.extinfo else None print(rec.extinfo) self.render(tmpl, kwd=dict(kwd, **self.extra_kwd(rec)), calc_info=rec, userinfo=self.userinfo, relations=rel_recs, rand_recs=rand_recs, unescape=tornado.escape.xhtml_unescape, ad_switch=random.randint(1, 18), tag_info=self.mapp2tag.get_by_id(info_id), recent_apps=self.musage.query_recent(self.get_current_user(), 6)[1:], post_info=rec, replys=replys, cat_enum=self.mcat.get_qian2(catid[:2]) if catid else [], priv_mask_idx=priv_mask_idx, ) def extra_kwd(self, info_rec): ''' The additional information. :param info_rec: :return: directory. ''' return {} def chuli_cookie_relation(self, app_id): ''' The current Info and the Info viewed last should have some relation. And the last viewed Info could be found from cookie. :param app_id: the current app :return: None ''' last_app_uid = self.get_secure_cookie('use_app_uid') if last_app_uid: last_app_uid = last_app_uid.decode('utf-8') self.set_secure_cookie('use_app_uid', app_id) if last_app_uid and self.minfo.get_by_uid(last_app_uid): self.add_relation(last_app_uid, app_id) def ext_tmpl_name(self, rec): return None def get_tmpl_name(self, rec): ''' According to the application, each info of it's classification could has different temaplate. :param rec: the App record. :return: the temaplte path. ''' if 'def_cat_uid' in rec.extinfo and rec.extinfo['def_cat_uid'] != '': cat_id = rec.extinfo['def_cat_uid'] else: cat_id = False if cat_id: tmpl = 'autogen/view/view_{0}.html'.format(cat_id) else: tmpl = 'infor/app/show_map.html' return tmpl def add_relation(self, f_uid, t_uid): ''' Add the relation. And the from and to, should have different weight. :param f_uid: :param t_uid: :return: return True if the relation has been succesfully added. ''' if self.minfo.get_by_uid(t_uid): pass else: return False if f_uid == t_uid: return False self.mrel.add_relation(f_uid, t_uid, 2) self.mrel.add_relation(t_uid, f_uid, 1) return True
def initialize(self): self.init() self.mjson = MJson() self.musage = MUsage()
class InfoHandler(BaseHandler): def initialize(self, hinfo=''): self.init() self.mevaluation = MEvaluation() self.mapp2catalog = MApp2Catalog() self.mapp2tag = MApp2Label() self.minfo = MApp() self.musage = MUsage() self.mcat = MAppCatalog() self.mrel = MAppRel() self.mreply = MApp2Reply() def get(self, url_str=''): url_arr = self.parse_url(url_str) if len(url_arr) == 1 and len(url_str) == 4: self.view_info(url_str) else: kwd = { 'title': '', 'info': '', } self.render('html/404.html', kwd=kwd, userinfo=self.userinfo, ) def post(self, url_str=''): url_arr = self.parse_url(url_str) if url_arr[0] == 'rel': if self.get_current_user(): self.add_relation(url_arr[1]) else: self.redirect('/user/login') elif url_arr[0] == 'comment_add': self.add_comment(url_arr[1]) else: return False @tornado.web.authenticated def add_comment(self, id_post): post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) post_data['user_id'] = self.userinfo.uid post_data['user_name'] = self.userinfo.user_name comment_uid = self.mreply.insert_data(post_data, id_post) if comment_uid: output = { 'pinglun': comment_uid, } else: output = { 'pinglun': 0, } return json.dump(output, self) def view_info(self, info_id): ''' Render the info :param info_id: :return: Nonthing. ''' rec = self.minfo.get_by_uid(info_id) if rec: pass else: kwd = { 'info': '您要找的信息不存在。', } self.render('html/404.html', kwd=kwd, userinfo=self.userinfo, ) return False replys = self.mreply.get_by_id(info_id) rel_recs = self.mrel.get_app_relations(rec.uid, 4) rand_recs = self.minfo.query_random(4 - rel_recs.count() + 2) self.chuli_cookie_relation(info_id) cookie_str = tools.get_uuid() kwd = { 'pager': '', 'url': self.request.uri, 'cookie_str': cookie_str, 'signature': info_id, 'tdesc': '', 'eval_0': self.mevaluation.app_evaluation_count(info_id, 0), 'eval_1': self.mevaluation.app_evaluation_count(info_id, 1), 'site_url': config.site_url, 'login': 1 if self.get_current_user() else 0, 'has_image': 0, 'parentlist': self.mcat.get_parent_list(), } self.minfo.view_count_increase(info_id) if self.get_current_user(): self.musage.add_or_update(self.userinfo.uid, info_id) self.set_cookie('user_pass', cookie_str) tmpl = self.ext_tmpl_name(rec) if self.ext_tmpl_name(rec) else self.get_tmpl_name(rec) catid = rec.extinfo['def_cat_uid'] if 'def_cat_uid' in rec.extinfo else None self.render(tmpl, kwd=dict(kwd, **self.extra_kwd(rec)), calc_info=rec, userinfo=self.userinfo, relations=rel_recs, rand_recs=rand_recs, unescape=tornado.escape.xhtml_unescape, ad_switch=random.randint(1, 18), tag_info=self.mapp2tag.get_by_id(info_id), recent_apps=self.musage.query_recent(self.get_current_user(), 6)[1:], post_info=rec, replys=replys, cat_enum = self.mcat.get_qian2(catid[:2]) if catid else [], ) def extra_kwd(self, info_rec): ''' The additional information. :param info_rec: :return: directory. ''' return {} def chuli_cookie_relation(self, app_id): ''' The current Info and the Info viewed last should have some relation. And the last viewed Info could be found from cookie. :param app_id: the current app :return: None ''' last_map_id = self.get_secure_cookie('use_app_uid') if last_map_id: last_map_id = last_map_id.decode('utf-8') self.set_secure_cookie('use_app_uid', app_id) if last_map_id and self.minfo.get_by_uid(last_map_id): self.add_relation(last_map_id, app_id) def ext_tmpl_name(self, rec): return None def get_tmpl_name(self, rec): ''' According to the application, each info of it's classification could has different temaplate. :param rec: the App record. :return: the temaplte path. ''' if 'def_cat_uid' in rec.extinfo and rec.extinfo['def_cat_uid'] != '': cat_id = rec.extinfo['def_cat_uid'] else: cat_id = False if cat_id: tmpl = 'autogen/view/view_{0}.html'.format(cat_id) else: tmpl = 'tmpl_applite/app/show_map.html' return tmpl def add_relation(self, f_uid, t_uid): ''' Add the relation. And the from and to, should have different weight. :param f_uid: :param t_uid: :return: return True if the relation has been succesfully added. ''' if self.minfo.get_by_uid(t_uid): pass else: return False if f_uid == t_uid: return False self.mrel.add_relation(f_uid, t_uid, 2) self.mrel.add_relation(t_uid, f_uid, 1) return True