Exemple #1
0
    def redirect_kind(self, postinfo):
        '''
        Redirect according the kind of the post.
        :param postinfo: the postinfo
        :return: None
        '''
        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)
Exemple #2
0
    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)
Exemple #3
0
    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)
Exemple #4
0
    def view_info(self, info_id):
        '''
        Render the info
        :param info_id:
        :return: Nonthing.
        '''
        postinfo = self.mpost.get_by_uid(info_id)
        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],
                                            info_id),
                          permanent=True)

        if postinfo:
            pass
        else:
            kwd = {
                'info': '您要找的信息不存在。',
            }
            self.render(
                'html/404.html',
                kwd=kwd,
                userinfo=self.userinfo,
            )
            return False

        cats = self.mpost2catalog.query_by_entity_uid(info_id,
                                                      kind=postinfo.kind)
        cat_uid_arr = []
        for cat_rec in cats:
            cat_uid = cat_rec.tag.uid
            cat_uid_arr.append(cat_uid)
        logger.info('info category: {0}'.format(cat_uid_arr))

        rel_recs = self.mrel.get_app_relations(postinfo.uid,
                                               8,
                                               kind=postinfo.kind)
        logger.info('rel_recs count: {0}'.format(rel_recs.count()))

        if len(cat_uid_arr) > 0:
            rand_recs = self.mpost.query_cat_random(cat_uid_arr[0],
                                                    4 - rel_recs.count() + 4)
        else:
            rand_recs = self.mpost.query_random(num=4 - rel_recs.count() + 4,
                                                kind=postinfo.kind)

        self.chuli_cookie_relation(info_id)
        cookie_str = tools.get_uuid()

        if 'def_cat_uid' in postinfo.extinfo:
            ext_catid = postinfo.extinfo['def_cat_uid']
        else:
            ext_catid = ''

        if len(ext_catid) == 4:
            pass
        else:
            ext_catid = ''

        catinfo = None
        p_catinfo = None

        post2catinfo = self.mpost2catalog.get_entry_catalog(postinfo.uid)
        if post2catinfo:
            catid = post2catinfo.tag.uid
            catinfo = self.mcat.get_by_uid(catid)
            if catinfo:
                p_catinfo = self.mcat.get_by_uid(catinfo.pid)

        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),
            'login': 1 if self.get_current_user() else 0,
            'has_image': 0,
            'parentlist': self.mcat.get_parent_list(),
            'parentname': '',
            'catname': '',
            'router': router_post[postinfo.kind]
        }
        self.mpost.view_count_increase(info_id)
        if self.get_current_user():
            self.musage.add_or_update(self.userinfo.uid, info_id,
                                      postinfo.kind)
        self.set_cookie('user_pass', cookie_str)
        tmpl = self.ext_tmpl_name(postinfo) if self.ext_tmpl_name(
            postinfo) else self.get_tmpl_name(postinfo)

        print('info tmpl: ' + tmpl)
        ext_catid2 = postinfo.extinfo[
            'def_cat_uid'] if 'def_cat_uid' in postinfo.extinfo else None

        if self.userinfo:
            recent_apps = self.musage.query_recent(self.userinfo.uid,
                                                   postinfo.kind, 6)[1:]
        else:
            recent_apps = []
        self.render(
            tmpl,
            kwd=dict(kwd, **self.extra_kwd(postinfo)),
            calc_info=postinfo,  # Deprecated
            post_info=postinfo,  # Deprecated
            postinfo=postinfo,
            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=self.mpost2label.get_by_id(info_id),
            recent_apps=recent_apps,
            cat_enum=self.mcat.get_qian2(ext_catid2[:2]) if ext_catid else [],
        )