Exemple #1
0
    def render(self, *args, **kwargs):
        kind = args[0]
        tag_slug = args[1]
        current = int(args[2])

        pager_count = int(
            MPost2Label.total_number(tag_slug, kind) /
            config.CMS_CFG['list_num'])
        page_num = (
            pager_count
            if abs(pager_count - MPost2Label.total_number(tag_slug, kind) /
                   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/label_pager.html',
                                  kwd=kwd,
                                  cat_slug=tag_slug,
                                  pager_num=page_num,
                                  page_current=current,
                                  kind=kind)
Exemple #2
0
 def test_total_number(self):
     self.add_mess()
     a = MPost2Label.total_number(self.uid)
     self.add_M2L()
     b = MPost2Label.total_number(self.uid)
     assert a + 1 == b
     self.tearDown()
Exemple #3
0
    def update_label(self, signature):
        '''
        Update the label when updating.
        :param signature:
        :return:
        '''
        current_tag_infos = MPost2Label.get_by_uid(signature, kind=self.kind)
        post_data = self.get_post_data()
        if 'tags' in post_data:
            pass
        else:
            return False

        tags_arr = [x.strip() for x in post_data['tags'].split(',')]
        for tag_name in tags_arr:
            if tag_name == '':
                pass
            else:
                MPost2Label.add_record(signature, tag_name, 1)

        for cur_info in current_tag_infos:
            if cur_info.tag.name in tags_arr:
                pass
            else:
                MPost2Label.remove_relation(signature, cur_info.tag)
def update_label(signature, post_data):
    '''
    Update the label .
    '''
    current_tag_infos = MPost2Label.get_by_uid(signature).objects()
    if 'tags' in post_data:
        pass
    else:
        return False

    if ';' in post_data['tags']:
        tags_arr = [x.strip() for x in post_data['tags'].split(';')]
    elif ',' in post_data['tags']:
        tags_arr = [x.strip() for x in post_data['tags'].split(',')]
    elif ',' in post_data['tags']:
        tags_arr = [x.strip() for x in post_data['tags'].split(',')]
    elif ';' in post_data['tags']:
        tags_arr = [x.strip() for x in post_data['tags'].split(';')]
    else:
        tags_arr = [x.strip() for x in post_data['tags'].split(' ')]

    if len(tags_arr) > 5:
        del tags_arr[5:]

    for tag_name in tags_arr:
        if tag_name == '':
            pass
        else:
            MPost2Label.add_record(signature, tag_name, 1)

    for cur_info in current_tag_infos:
        if cur_info.tag_name in tags_arr:
            pass
        else:
            MPost2Label.remove_relation(signature, cur_info.tag_id)
Exemple #5
0
    def list(self, kind, tag_slug, cur_p=''):
        '''
        根据 cat_handler.py 中的 def view_cat_new(self, cat_slug, cur_p = '')
        '''
        # 下面用来使用关键字过滤信息,如果网站信息量不是很大不要开启
        # Todo:
        # if self.get_current_user():
        #     redisvr.sadd(config.redis_kw + self.userinfo.user_name, tag_slug)

        if cur_p == '':
            current_page_number = 1
        else:
            try:
                current_page_number = int(cur_p)
            except TypeError:
                current_page_number = 1
            except Exception as err:
                print(err.args)
                print(str(err))
                print(repr(err))

        current_page_number = 1 if current_page_number < 1 else current_page_number

        pager_num = int(
            MPost2Label.total_number(tag_slug, kind) / CMS_CFG['list_num'])
        tag_info = MLabel.get_by_slug(tag_slug)
        if tag_info:
            tag_name = tag_info.name
        else:
            tag_name = 'Label search results'
        kwd = {
            'tag_name': tag_name,
            'tag_slug': tag_slug,
            'title': tag_name,
            'current_page': current_page_number,
            'router': router_post[kind],
            'kind': kind
        }

        the_list_file = './templates/list/label_{kind}.html'.format(kind=kind)

        if os.path.exists(the_list_file):
            tmpl = 'list/label_{kind}.html'.format(kind=kind)

        else:
            tmpl = 'list/label.html'

        self.render(tmpl,
                    infos=MPost2Label.query_pager_by_slug(
                        tag_slug,
                        kind=kind,
                        current_page_num=current_page_number),
                    kwd=kwd,
                    userinfo=self.userinfo,
                    pager=self.gen_pager(kind, tag_slug, pager_num,
                                         current_page_number),
                    cfg=CMS_CFG)
Exemple #6
0
    def test_get_by_uid(self):
        self.tearDown()
        self.add_mess()
        a = MPost2Label.get_by_uid(self.post_id)
        print(a.count())
        assert a.count() == 0
        self.add_M2L()
        a = MPost2Label.get_by_uid(self.post_id)

        assert a[0].tag_id == self.uid
        self.tearDown()
Exemple #7
0
    def test_query_count(self):
        self.add_mess()
        a = MPost2Label.query_count(self.uid)

        print(a)
        self.add_M2L()

        b = MPost2Label.query_count(self.uid)
        print(b)
        assert a + 1 <= b
        self.tearDown()
Exemple #8
0
    def test_get_by_info(self):
        self.add_mess()
        self.add_M2L()
        a = MPost2Label.get_by_info(self.post_id, self.tag_id)
        assert a != None

        self.tearDown()
Exemple #9
0
    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)
Exemple #10
0
    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)
Exemple #11
0
    def render(self, *args, **kwargs):

        self.mapp2tag = MPost2Label()
        tag_slug = args[0]
        current = int(args[1])
        # cat_slug 分类
        # current 当前页面



        page_num = int(self.mapp2tag.total_number(tag_slug) / config.page_num)

        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/doc_label_pager.html',
                                  kwd=kwd,
                                  cat_slug=tag_slug,
                                  pager_num=page_num,
                                  page_current=current,
                                  )
    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())
Exemple #13
0
    def test_add_record(self):
        a = MPost2Label.get_by_uid(self.post_id)
        tf = True
        for i in a:
            if i.tag_id == self.tag_id:
                tf = False
        assert tf
        self.add_mess()
        MPost2Label.add_record(self.post_id, self.name)
        a = MPost2Label.get_by_uid(self.post_id)
        tf = False
        for i in a:

            if i.tag_id == self.tag_id:
                tf = True
        assert tf
        self.tearDown()
Exemple #14
0
    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)
Exemple #15
0
    def test_remove_relation(self):
        self.add_mess()
        self.add_M2L()
        a = MPost2Label.get_by_uid(self.post_id)
        tf = False
        for i in a:

            if i.tag_id == self.tag_id:
                tf = True
        assert tf
        MPost2Label.remove_relation(self.post_id, self.tag_id)
        a = MPost2Label.get_by_uid(self.post_id)
        tf = True
        for i in a:

            if i.tag_id == self.tag_id:
                tf = False
        assert tf
        self.tearDown()
Exemple #16
0
 def initialize(self):
     self.init()
     self.mpost = MPost()
     self.mcat = MCategory()
     self.cats = self.mcat.query_all()
     self.mpost_hist = MPostHist()
     self.mpost2catalog = MPost2Catalog()
     self.mpost2reply = MPost2Reply()
     self.mpost2label = MPost2Label()
     self.mrel = MRelation()
Exemple #17
0
 def initialize(self):
     self.init()
     self.mpost = MPost()
     self.mcat = MCategory()
     self.cats = self.mcat.query_all()
     self.mpost_hist = MPostHist()
     self.mpost2catalog = MPost2Catalog()
     # self.mpost2reply = MPost2Reply()
     self.mpost2label = MPost2Label()
     self.mrel = MRelation()
     self.tmpl_dir = 'admin'
     self.tmpl_router = 'post_ajax'
Exemple #18
0
 def initialize(self):
     self.init()
     self.mpost = MPost()
     self.mcat = MCategory()
     self.cats = self.mcat.query_all()
     self.mpost_hist = MPostHist()
     self.mpost2catalog = MPost2Catalog()
     self.mpost2label = MPost2Label()
     self.mrel = MRelation()
     self.tmpl_dir = 'doc'
     self.kind = '1'
     self.tmpl_router = 'post'
Exemple #19
0
    def add_message(self, **kwargs):
        p_d = {
            'title': kwargs.get('title', 'iiiii'),
            'cnt_md': kwargs.get('cnt_md', 'grgr'),
            'time_create': kwargs.get('time_create', '1992'),
            'time_update': kwargs.get('time_update', '1996070600'),
            'user_name': kwargs.get('user_name', 'yuanyuan'),
            'view_count': kwargs.get('view_count', 1),
            'logo': kwargs.get('logo', 'prprprprpr'),
            'memo': kwargs.get('memo', ''),
            'order': kwargs.get('order', '1'),
            'keywords': kwargs.get('keywords', ''),
            'extinfo': kwargs.get('extinfo', {}),
            'kind': kwargs.get('kind2', '1'),
            'valid': kwargs.get('valid', 1),
        }
        post_id = kwargs.get('post_id', self.post_id)

        MPost.create_post(post_id, p_d)
        self.uu.create_tag_with_uid(self.uid, self.name)
        MPost2Label.add_record(self.post_id, self.name)
Exemple #20
0
    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
Exemple #21
0
    def list(self, kind, tag_slug, cur_p=''):
        '''
        根据 cat_handler.py 中的 def view_cat_new(self, cat_slug, cur_p = '')
        :param tag_slug:
        :return:
        '''
        # 下面用来使用关键字过滤信息,如果网站信息量不是很大不要开启
        # Todo:
        # if self.get_current_user():
        #     redisvr.sadd(config.redis_kw + self.userinfo.user_name, tag_slug)

        if cur_p == '':
            current_page_number = 1
        else:
            current_page_number = int(cur_p)

        current_page_number = 1 if current_page_number < 1 else current_page_number

        pager_num = int(
            MPost2Label.total_number(tag_slug, kind) / CMS_CFG['list_num'])
        tag_name = ''
        kwd = {
            'tag_name': tag_name,
            'tag_slug': tag_slug,
            'title': tag_name,
            'current_page': current_page_number
        }

        self.render('list/label_{kind}.html'.format(kind=kind),
                    infos=MPost2Label.query_pager_by_slug(
                        tag_slug,
                        kind=kind,
                        current_page_num=current_page_number),
                    unescape=tornado.escape.xhtml_unescape,
                    kwd=kwd,
                    userinfo=self.userinfo,
                    pager=self.gen_pager(kind, tag_slug, pager_num,
                                         current_page_number),
                    cfg=CMS_CFG)
Exemple #22
0
def update_label(signature, post_data):
    '''
    Update the label when updating.
    '''
    current_tag_infos = MPost2Label.get_by_uid(signature).objects()
    if 'tags' in post_data:
        pass
    else:
        return False

    tags_arr = [x.strip() for x in post_data['tags'].split(',')]
    for tag_name in tags_arr:
        if tag_name == '':
            pass
        else:
            MPost2Label.add_record(signature, tag_name, 1)

    for cur_info in current_tag_infos:
        if cur_info.tag_name in tags_arr:
            pass
        else:
            MPost2Label.remove_relation(signature, cur_info.tag_id)
Exemple #23
0
 def setup(self):
     print('setup 方法执行于本类中每条用例之前')
     self.uu = MPost()
     self.m2c = MPost2Catalog()
     self.ml = MLabel()
     self.m2l = MPost2Label()
     self.labeluid = '9999'
     self.raw_count = self.uu.get_counts()
     self.post_title = 'ccc'
     self.uid = tools.get_uu4d()
     self.post_id = '66565'
     self.tag_id = '2342'
     self.post_id2 = '89898'
     self.slug = 'huio'
Exemple #24
0
    def test_query_pager_by_slug(self):
        self.add_mess()
        self.add_M2L()
        a = MPost2Label.query_pager_by_slug(self.uid)
        print(a)
        print(a.count())

        tf = False
        for i in a:
            print(i)

            if i.uid == self.post_id:
                tf = True
        assert tf
        self.tearDown()
Exemple #25
0
 def render(self, postinfo=None):
     if postinfo:
         tag_info = MPost2Label.get_by_uid(postinfo.uid)
         idx = 1
         outstr = '<span class="post_label">'
         for x in tag_info:
             outstr += '''<a href = "/label/{kind}/{tag_uid}"
                 class ="app_label tag{index}" > {tag_name} </a>
                 '''.format(tag_uid=x.tag.uid,
                            kind=postinfo.kind,
                            tag_name=x.tag.name,
                            index=idx)
             idx += 1
         return outstr + '</span>'
     else:
         return ''
Exemple #26
0
 def render(self, *args, **kwargs):
     postinfo = kwargs.get('postinfo', None)
     if postinfo:
         tag_info = filter(lambda x: not x.tag_name.startswith('_'),
                           MPost2Label.get_by_uid(postinfo.uid).objects())
         idx = 1
         outstr = '<span class="post_label">'
         for tag in tag_info:
             outstr += '''<a href="/label/{kind}/{tag_uid}"
                 class ="app_label tag{index}"> {tag_name} </a>
                 '''.format(tag_uid=tag.tag_id,
                            kind=postinfo.kind,
                            tag_name=tag.tag_name,
                            index=idx)
             idx += 1
         return outstr + '</span>'
     return ''
Exemple #27
0
 def render(self, *args, **kwargs):
     postinfo = kwargs['postinfo'] if 'postinfo' in kwargs else None
     if postinfo:
         tag_info = MPost2Label.get_by_uid(postinfo.uid).naive()
         idx = 1
         outstr = '<span class="post_label">'
         for tag in tag_info:
             outstr += '''<a href="/label/{kind}/{tag_uid}"
                 class ="app_label tag{index}"> {tag_name} </a>
                 '''.format(tag_uid=tag.tag_id,
                            kind=postinfo.kind,
                            tag_name=tag.tag_name,
                            index=idx)
             idx += 1
         return outstr + '</span>'
     else:
         return ''
Exemple #28
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 #29
0
    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'))
Exemple #30
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)