Exemplo n.º 1
0
    def tearDown(self):
        print("function teardown")

        tt = self.uu.get_by_uid(self.app_f)
        if tt:

            MPost2Catalog.remove_relation(self.app_t, self.tag_id)
            MPost2Catalog.remove_relation(self.app_f, self.tag_id)
            MCategory.delete(self.tag_id)

            MPost.delete(self.app_f)
            MPost.delete(self.app_t)

        MRelation.delete(self.uid)
        tt = MLabel.get_by_slug(self.slug)
        if tt:
            MLabel.delete(tt.uid)
Exemplo n.º 2
0
 def ajax_list_catalog(self, catid):
     '''
     Get posts of certain catid. In Json.
     '''
     out_arr = {}
     for catinfo in MPost2Catalog.query_postinfo_by_cat(catid):
         out_arr[catinfo.uid] = catinfo.title
     json.dump(out_arr, self)
Exemplo n.º 3
0
    def test_get_app_relations(self, **kwargs):
        MPost.delete(self.uid)
        MPost.delete(self.uid2)
        # 添加post
        post_data = {
            'title': 'test1',
            'cnt_md': '## test',
            'user_name': 'test',
            'view_count': 1,
            'logo': ' ',
            'keywords': 'test',
            'kind': '1'
        }

        uu1 = MPost.create_post(self.uid, post_data)

        post_data2 = {
            'title': 'test2',
            'cnt_md': '## test2',
            'user_name': 'test2',
            'view_count': 1,
            'logo': ' ',
            'keywords': 'test2',
            'kind': '1'
        }

        uu2 = MPost.create_post(self.uid2, post_data2)

        # 添加category
        cat_data = {
            'name': kwargs.get('name', 'category'),
            'slug': kwargs.get('slug', 'slug1'),
            'order': kwargs.get('order', '0'),
            'kind': kwargs.get('kind1', '1'),
            'pid': kwargs.get('pid', '0000'),
        }
        MCategory.add_or_update(self.tag_id, cat_data)

        MPost2Catalog.add_record(uu1, self.tag_id)

        MRelation.add_relation(uu1, uu2)

        MRelation.get_app_relations(uu1)

        assert True
Exemplo n.º 4
0
    def viewinfo(self, postinfo):
        '''
        In infor.
        '''
        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() 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),
            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)
Exemplo n.º 5
0
    def render(self, post_id, order=False):
        if order:
            tmpl_str = '''<a href="/catalog/{0}">{1}</a>'''
        else:
            tmpl_str = '''<a href="/list/{0}">{1}</a>'''

        format_arr = [tmpl_str.format(uu.tag_slug, uu.tag_name) for uu in
                      MPost2Catalog().query_by_entity_uid(post_id).objects()]
        return ', '.join(format_arr)
Exemplo n.º 6
0
 def render(self, uid):
     out_str = ''
     ii = 1
     for tag_info in MPost2Catalog.query_by_entity_uid(uid, kind='m'):
         tmp_str = '<a href="/tag/{0}" class="tag{1}">{2}</a>'.format(
             tag_info.tag.slug, ii, tag_info.tag.name)
         out_str += tmp_str
         ii += 1
     return out_str
Exemplo n.º 7
0
    def test_query_pager_by_slug(self):
        kwargs = {'slug': 'awer'}

        self.add_message(**kwargs)
        self.add_P2C()
        a = MPost2Catalog.query_pager_by_slug(kwargs['slug'])

        assert a[0].uid == self.post_id
        self.tearDown()
Exemplo n.º 8
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()
Exemplo n.º 9
0
 def render(self, *args, **kwargs):
     uid = args[0]
     out_str = ''
     iii = 1
     for tag_info in MPost2Catalog.query_by_entity_uid(uid).naive():
         tmp_str = '''<a data-inline="true" href="/tag/{0}"
          class="tag{1}">{2}</a>'''.format(tag_info.tag_slug, iii, tag_info.tag_name)
         out_str += tmp_str
         iii += 1
     return out_str
Exemplo n.º 10
0
    def delete_by_id(self, del_id):
        '''
        Delete  by id.

        '''
        print("-" * 50)
        print(del_id)
        if self.check_post_role()['DELETE']:
            pass
        else:
            return False
        post_resc = MPost2Catalog.query_postinfo_by_cat(del_id)
        for post in post_resc:
            MPost2Catalog.remove_relation(post.uid, del_id)
        if MCategory.delete(del_id):
            output = {'del_link': 1}
        else:
            output = {'del_link': 0}
        return json.dump(output, self)
Exemplo n.º 11
0
def get_meta(catid, sig, cell_cars):
    uid = sig
    meta_base = './script_helper'
    if os.path.exists(meta_base):
        pass
    else:
        return False

    pp_data = {'logo': '', 'kind': 'k'}

    pp_data['title'] = cell_cars[1]
    # pp_data['cnt_md'] = cell_cars[1]

    pp_data['user_name'] = 'admin'
    pp_data['def_cat_uid'] = catid
    pp_data['def_cat_pid'] = catid[:2] + '00'

    pp_data['extinfo'] = {
        # ad_link 不存在则使用 raw_link
        'zlink': cell_cars[3] if cell_cars[3] else cell_cars[4]
    }

    for wroot, wdirs, wfiles in os.walk(meta_base):
        for wdir in wdirs:
            if wdir.lower() == sig:
                ds_base = pathlib.Path(os.path.join(wroot, wdir))
                for uu in ds_base.iterdir():
                    if uu.name.endswith('.xlsx'):
                        meta_dic = chuli_meta(sig[2:], uu)
                    elif uu.name.endswith('.md'):
                        pp_data['cnt_md'] = open(str(uu.absolute())).read()
                    elif uu.name.startswith('thumbnail_'):
                        pp_data['logo'] = os.path.join(wroot, wdir,
                                                       uu.name).strip('.')

    kwargsa = {
        'def_cat_uid': catid,
        'cat_id': catid,
    }
    MPost.add_or_update(uid, pp_data)
    update_category(uid, pp_data, kwargsa)
    MPost2Catalog.add_record(uid, catid)
Exemplo n.º 12
0
def run_export():
    for x in yaml_infos:

        if x['uid'] in filter_arr:

            print(x['uid'])
            MPost.create_post(x['uid'], x)

            x['extinfo']['def_cat_uid'] = x['extinfo'].get('def_cat_uid', '2103')

            print(x['extinfo']['def_cat_uid'])

            if x['extinfo']['def_cat_uid'] in ['me01', 'me02', 'mf01', 'mf03']:
                # pass
                MPost2Catalog.add_record(x['uid'], x['extinfo']['def_cat_uid'])
            else:
                # pass
                MPost2Catalog.add_record(x['uid'], '2103')

        pass
Exemplo n.º 13
0
 def render(self, signature):
     self.mapp2tag = MPost2Catalog()
     tag_infos = self.mapp2tag.query_by_entity_uid(signature, kind='10')
     out_str = ''
     ii = 1
     for tag_info in tag_infos:
         tmp_str = '<a href="/category/{0}" class="tag{1}">{2}</a>'.format(tag_info.tag.slug, ii,
                                                                           tag_info.tag.name)
         out_str += tmp_str
         ii += 1
     return out_str
Exemplo n.º 14
0
 def render(self, *args, **kwargs):
     uid = args[0]
     out_str = ''
     idx = 1
     for tag_info in MPost2Catalog.query_by_entity_uid(uid,
                                                       kind='m').objects():
         tmp_str = '<a href="/list/{0}" class="tag{1}">{2}</a>'.format(
             tag_info.tag_slug, idx, tag_info.tag_name)
         out_str += tmp_str
         idx += 1
     return out_str
Exemplo n.º 15
0
    def setup(self):
        print('setup 方法执行于本类中每条用例之前')
        self.uu = MPost()
        self.m2c = MPost2Catalog()

        self.app_f = 'ddss'
        self.app_t = '6122'

        self.tag_id = '6654'
        self.uid = ''
        self.slug = 'huio'
Exemplo n.º 16
0
    def add_post(self, **kwargs):
        p_d = {
            'title': kwargs.get('title', '一二三'),
            'cnt_md': kwargs.get('cnt_md', 'grgr'),
            'time_create': kwargs.get('time_create', '1992'),
            'time_update': kwargs.get('time_update', '1996070600'),
            'user_name': 'flower',
            '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', 'sd,as'),
            'extinfo': kwargs.get('extinfo', {}),
            'kind': kwargs.get('kind', '1'),
            'valid': kwargs.get('valid', 1),
        }
        p_id = kwargs['post_uid']

        MPost.create_post(p_id, p_d)
        MPost2Catalog.add_record(p_id, self.tag_id)
Exemplo n.º 17
0
    def tearDown(self):
        print("function teardown")
        tt = MCategory.get_by_uid(self.tag_id)
        if tt:
            MCategory.delete(self.tag_id)
        tt = MPost.get_by_uid(self.post_id)
        if tt:
            MPost.delete(self.post_id)

            MPost2Catalog.remove_relation(self.post_id, self.tag_id)
        tt = MPost.get_by_uid(self.post_id2)
        if tt:
            MPost.delete(self.post_id2)

            MPost2Catalog.remove_relation(self.post_id2, self.tag_id)

        tt = MLabel.get_by_slug(self.slug)
        if tt:
            print('8888888888')
            MLabel.delete(self.slug)
Exemplo n.º 18
0
    def test_query_all(self):
        self.add_message()
        self.add_P2C()
        a = MPost2Catalog.query_all()
        TF = False

        for i in a:
            if i.post_id == self.post_id:
                TF = True

        assert TF
        self.tearDown()
Exemplo n.º 19
0
    def render(self, post_id, order=False):
        if order:
            tmpl_str = '''<a href="/catalog/{0}">{1}</a>'''
        else:
            tmpl_str = '''<a href="/category/{0}">{1}</a>'''

        # print('=' * 10)
        # for uu in MPost2Catalog().query_by_entity_uid(post_id):
        #     print(dir(uu.as_entity()))
        format_arr = [tmpl_str.format(uu.tag_slug, uu.tag_name) for uu in
                      MPost2Catalog().query_by_entity_uid(post_id).objects()]
        return ', '.join(format_arr)
Exemplo n.º 20
0
 def render(self, *args, **kwargs):
     uid = args[0]
     kind = args[1]
     out_str = ''
     ii = 1
     for tag_info in MPost2Catalog.query_by_entity_uid(uid,
                                                       kind=kind).naive():
         tmp_str = '<a href="/category/{0}" class="tag{1}">{2}</a>'.format(
             tag_info.tag_slug, ii, tag_info.tag_name)
         out_str += tmp_str
         ii += 1
     return out_str
Exemplo n.º 21
0
    def test_query_count(self):
        self.add_message()
        self.add_P2C()
        ss = MPost2Catalog.query_count()

        TF = False
        for i in ss:
            if i.tag_id == self.tag_id:
                if i.num == 1:
                    TF = True
        assert TF
        self.tearDown()
Exemplo n.º 22
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'
Exemplo n.º 23
0
 def render(self, cat_id, num=10, with_catalog=True, with_date=True):
     self.mpost = MPost()
     self.mpost2cat = MPost2Catalog()
     recs = self.mpost.query_cat_recent(cat_id, num)
     kwd = {
         'with_catalog': with_catalog,
         'with_date': with_date,
     }
     return self.render_string('modules/post/post_list.html',
                               recs=recs,
                               unescape=tornado.escape.xhtml_unescape,
                               kwd=kwd, )
Exemplo n.º 24
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'
Exemplo n.º 25
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
Exemplo n.º 26
0
 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)
Exemplo n.º 27
0
def run_check_kind(*args):
    for kd in router_post.keys():
        for rec in MCategory.query_all(kind=kd):
            catid = rec.uid

            catinfo = MCategory.get_by_uid(catid)
            recs = MPost2Catalog.query_by_catid(catid)
            for rec in recs:
                postinfo = MPost.get_by_uid(rec.post.uid)
                if postinfo.kind == catinfo.kind:
                    pass
                else:
                    print(postinfo.uid)
Exemplo n.º 28
0
def check_kind():
    '''
    对 post 与 对应类型的 kind 进行检查
    '''
    for kindv in router_post:
        for rec_cat in MCategory.query_all(kind=kindv):
            catid = rec_cat.uid
            catinfo = MCategory.get_by_uid(catid)
            for rec_post2tag in MPost2Catalog.query_by_catid(catid):
                postinfo = MPost.get_by_uid(rec_post2tag.post_id)
                if postinfo.kind == catinfo.kind:
                    pass
                else:
                    print(postinfo.uid)
Exemplo n.º 29
0
def run_check_kind(_):
    '''
    Running the script.
    '''
    for kindv in router_post:
        for rec_cat in MCategory.query_all(kind=kindv):
            catid = rec_cat.uid
            catinfo = MCategory.get_by_uid(catid)
            for rec_post2tag in MPost2Catalog.query_by_catid(catid):
                postinfo = MPost.get_by_uid(rec_post2tag.post_id)
                if postinfo.kind == catinfo.kind:
                    pass
                else:
                    print(postinfo.uid)
Exemplo n.º 30
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'