Exemplo n.º 1
0
    def query_random(**kwargs):
        '''
        Return the random records of centain kind.
        :param num:
        :param kind:
        :return:
        '''

        if 'limit' in kwargs:
            limit = kwargs['limit']
        elif 'num' in kwargs:
            limit = kwargs['num']
        else:
            limit = 10

        if 'kind' in kwargs:
            kind = kwargs['kind']
        else:
            kind = None

        if kind:
            return g_Post.select().where((g_Post.kind == kind)
                                         & (g_Post.valid == 1)).order_by(
                                             peewee.fn.Random()).limit(limit)
        else:
            return g_Post.select().order_by(peewee.fn.Random()).limit(limit)
Exemplo n.º 2
0
 def query_pager_by_slug(slug, current_page_num=1, order=False):
     if order:
         recs = g_Post.select().join(g_Post2Tag).join(g_Tag).where(
             g_Tag.slug == slug).order_by(g_Post.order.asc())
     else:
         recs = g_Post.select().join(g_Post2Tag).join(g_Tag).where(
             g_Tag.slug == slug).order_by(
                 g_Post.time_update.desc()).paginate(
                     current_page_num, CMS_CFG['list_num'])
     return recs
Exemplo n.º 3
0
 def query_recent(num=8, **kwargs):
     '''
     :param num:
     :param kind:
     :return:
     '''
     if 'kind' in kwargs:
         kind = kwargs['kind']
         return g_Post.select().where(
             (g_Post.kind == kind) & (g_Post.valid == 1)).order_by(
                 g_Post.time_update.desc()).limit(num)
     else:
         return g_Post.select().where(g_Post.valid == 1).order_by(
             g_Post.time_update.desc()).limit(num)
Exemplo n.º 4
0
    def query_under_condition(condition, kind='2'):
        '''
        Get All data of certain kind according to the condition
        :param condition:
        :param kind:
        :return:
        '''
        if DB_CFG['kind'] == 's':
            return g_Post.select().where((g_Post.kind == kind) & (g_Post.valid == 1)).order_by(
                g_Post.time_update.desc())
        else:

            return g_Post.select().where(
                (g_Post.kind == kind) & (g_Post.valid == 1) & (g_Post.extinfo.contains(condition))
            ).order_by(g_Post.time_update.desc())
Exemplo n.º 5
0
 def query_keywords_empty(kind='1'):
     '''
     :param kind:
     :return:
     '''
     return g_Post.select().where((g_Post.kind == kind)
                                  & (g_Post.keywords == ''))
Exemplo n.º 6
0
 def get_all(kind='2'):
     return g_Post.select().where(
         (g_Post.kind == kind) &
         (g_Post.valid == 1)
     ).order_by(
         g_Post.time_update.desc()
     )
Exemplo n.º 7
0
 def query_by_tagname(tag_name, kind='2'):
     return g_Post.select().where(
         (g_Post.kind == kind) &
         (g_Post.valid == 1) &
         (g_Post.extinfo['def_tag_arr'].contains(tag_name))
     ).order_by(
         g_Post.time_update.desc()
     )
Exemplo n.º 8
0
 def query_extinfo_by_cat(cat_id, kind='2'):
     return g_Post.select().where(
         (g_Post.kind == kind) &
         (g_Post.valid == 1) &
         (g_Post.extinfo['def_cat_uid'] == cat_id)
     ).order_by(
         g_Post.time_update.desc()
     )
Exemplo n.º 9
0
 def get_by_keyword(par2, kind='2'):
     return g_Post.select().where(
         (g_Post.kind == kind) &
         (g_Post.valid == 1) &
         (g_Post.title.contains(par2))
     ).order_by(
         g_Post.time_update.desc()
     ).limit(20)
Exemplo n.º 10
0
 def query_least_by_cat(num=8, cat_str=1, kind='2'):
     return g_Post.select().join(g_Post2Tag).where(
         (g_Post.kind == kind) &
         (g_Post.valid == 1) &
         (g_Post2Tag.tag == cat_str)
     ).order_by(
         g_Post.view_count
     ).limit(num)
Exemplo n.º 11
0
 def query_dated(num=8, kind='1'):
     '''
     :param num:
     :param kind:
     :return:
     '''
     return g_Post.select().where(g_Post.kind == kind).order_by(
         g_Post.time_update.asc()).limit(num)
Exemplo n.º 12
0
 def get_previous_record(self, in_uid, kind='1'):
     current_rec = self.get_by_id(in_uid)
     query = g_Post.select().where(
         (self.tab.kind == kind) & (g_Post.time_create > current_rec.time_create)).order_by(g_Post.time_create)
     if query.count() == 0:
         return None
     else:
         return query.get()
Exemplo n.º 13
0
 def query_most_by_cat(num=8, catid=None, kind='2'):
     if catid:
         return g_Post.select().join(
             g_Post2Tag).where((g_Post.kind == kind) & (g_Post.valid == 1)
                               & (g_Post2Tag.tag == catid)).order_by(
                                   g_Post.view_count.desc()).limit(num)
     else:
         return False
Exemplo n.º 14
0
 def query_recent_edited(timstamp, kind='1'):
     '''
     :param timstamp:
     :param kind:
     :return:
     '''
     return g_Post.select().where((g_Post.kind == kind) & (
         g_Post.time_update > timstamp)).order_by(g_Post.time_update.desc())
Exemplo n.º 15
0
 def get_next_record(self, in_uid, kind=1):
     current_rec = self.get_by_id(in_uid)
     query = g_Post.select().where(
         (self.tab.kind == kind) & (g_Post.time_update < current_rec.time_update)).order_by(
         g_Post.time_update.desc())
     if query.count() == 0:
         return None
     else:
         return query.get()
Exemplo n.º 16
0
 def query_most_pic(num, kind='1'):
     '''
     :param num:
     :param kind:
     :return:
     '''
     return g_Post.select().where((g_Post.kind == kind)
                                  & (g_Post.logo != "")).order_by(
                                      g_Post.view_count.desc()).limit(num)
Exemplo n.º 17
0
    def query_cat_random(catid, **kwargs):
        '''
        Get random lists of certain category.
        :param cat_id:
        :param num:
        :return:
        '''
        if 'limit' in kwargs:
            num = kwargs['limit']
        else:
            num = 8
        if catid == '':
            return g_Post.select().order_by(peewee.fn.Random()).limit(num)

        else:
            return g_Post.select().join(g_Post2Tag).where(
                (g_Post.valid == 1) & (g_Post2Tag.tag == catid)).order_by(
                    peewee.fn.Random()).limit(num)
Exemplo n.º 18
0
 def query_cat_recent(cat_id, num=8, kind='1'):
     '''
     :param cat_id:
     :param num:
     :param kind:
     :return:
     '''
     return g_Post.select().join(g_Post2Tag).where(
         (g_Post.kind == kind) & (g_Post2Tag.tag == cat_id)).order_by(
             g_Post.time_create.desc()).limit(num)
Exemplo n.º 19
0
 def query_recent_most(num=8, recent=30):
     '''
     Query the records from database that recently updated.
     :param num: the number that will returned.
     :param recent: the number of days recent.
     :return:
     '''
     time_that = int(time.time()) - recent * 24 * 3600
     return g_Post.select().where(g_Post.time_update > time_that).order_by(
         g_Post.view_count.desc()).limit(num)
Exemplo n.º 20
0
 def query_most(num=8, kind='1'):
     '''
     :param num:
     :param kind:
     :return:
     '''
     return g_Post.select().where(
         (g_Post.kind == kind) &
         (g_Post.valid == 1)
     ).order_by(
         g_Post.view_count.desc()
     ).limit(num)
Exemplo n.º 21
0
 def get_previous_record(in_uid, kind='1'):
     '''
     :param in_uid:
     :param kind:
     :return:
     '''
     current_rec = MPost.get_by_uid(in_uid)
     query = g_Post.select().where((g_Post.kind == kind) & (
         g_Post.time_create > current_rec.time_create)).order_by(
             g_Post.time_create)
     if query.count() == 0:
         return None
     else:
         return query.get()
Exemplo n.º 22
0
    def query_all(**kwargs):
        '''
            :param kwargs:
            :return:
        '''
        if 'kind' in kwargs:
            kind = kwargs['kind']
        else:
            kind = '1'
        if 'limit' in kwargs:
            limit = kwargs['limit']
        else:
            limit = 10

        return g_Post.select().where(
            (g_Post.kind == kind) & (g_Post.valid == 1)).order_by(
                g_Post.time_update.desc()).limit(limit)
Exemplo n.º 23
0
    def query_cat_random(self, cat_id, num=6):
        if cat_id == '':
            return self.query_random(num)

        return g_Post.select().join(g_Post2Tag).where(g_Post2Tag.tag == cat_id).order_by(
            peewee.fn.Random()).limit(num)
Exemplo n.º 24
0
 def query_most(self, num=8, kind='1'):
     return g_Post.select().where(self.tab.kind == kind).order_by(g_Post.view_count.desc()).limit(num)
Exemplo n.º 25
0
 def query_cat_by_pager(self, cat_str, cureent, kind='1'):
     tt = g_Post.select().where((self.tab.kind == kind) & (g_Post.id_cats.contains(str(cat_str)))).order_by(
         g_Post.time_create.desc()).paginate(cureent, config.page_num)
     return tt
Exemplo n.º 26
0
 def query_cat_recent(self, cat_id, num=8, kind='1'):
     return g_Post.select().join(g_Post2Tag).where((self.tab.kind == kind) & (g_Post2Tag.tag == cat_id)).order_by(
         g_Post.time_create.desc()).limit(num)
Exemplo n.º 27
0
 def query_most_pic(self, num, kind='1'):
     return g_Post.select().where((self.tab.kind == kind) & (g_Post.logo != "")).order_by(
         g_Post.view_count.desc()).limit(num)
Exemplo n.º 28
0
 def query_dated(self, num=8, kind='1'):
     return g_Post.select().where(self.tab.kind == kind).order_by(g_Post.time_update.asc()).limit(num)
Exemplo n.º 29
0
 def query_keywords_empty(self, kind='1'):
     return g_Post.select().where((self.tab.kind == kind) & (g_Post.keywords == ''))
Exemplo n.º 30
0
 def get_num_by_cat(self, cat_str, kind='1'):
     return g_Post.select().where(
         (self.tab.kind == kind) & (g_Post.id_cats.contains(',{0},'.format(cat_str)))).count()