Exemple #1
0
 def find_by_slug(self, slug):
     """Find all categories by slug  sql like rule"""
     data = db.select(self.table).fields('title', 'slug', 'description',
                                         'cid').condition('slug',
                                                          slug).execute()
     if data:
         return self.load(data[0], self.model)
Exemple #2
0
 def find(self, cid):
     """Find category by category id, return the category model instance if category id exists in database"""
     data = db.select(self.table).fields('title', 'slug', 'description',
                                         'cid').condition('cid',
                                                          cid).execute()
     if data:
         return self.load(data[0], self.model)
Exemple #3
0
 def paginate(self, page=1, perpage=10, status='all'):
     q = db.select(self.table).fields('post_id', 'name', 'email', 'content', 'status', 'created', 'cid')
     if status != 'all':
         q.condition('status', status)
     results = q.limit(perpage).offset((page - 1) * perpage).order_by('created').execute()
     pages = [self.load(page, self.model) for page in results]
     return pages
Exemple #4
0
 def find_by_post_id(self, post_id, status='approved'):
     q = db.select(self.table).fields('post_id', 'name',
      'email', 'content', 'status', 'created', 'cid').condition('post_id', post_id)
     if status:
         q.condition('status', status)
     data = q.execute()
     return [self.load(_, self.model) for _ in data]
Exemple #5
0
 def find(self, type, node_id, extend_id):
     data = (db.select(self.table).fields(
         'node_id', 'type', 'extend',
         'data', 'mid').condition('type', type).condition(
             'node_id', node_id).condition('extend', extend_id).execute())
     if data:
         return self.load(data[0])
Exemple #6
0
 def take(self, page=1, perpage=10):
     count = self.count()
     q = db.select(self.table).select('username', 'email', 'real_name',
                                      'password', 'bio', 'status', 'role', 'uid')
     results = q.limit(perpage).offset((page - 1) * perpage).order_by('real_name', 'desc').execute()
     users = [self.load(user, self.model) for user in results]
     return users
Exemple #7
0
 def find_by_username(self, username):
     """Return user by username if find in database otherwise None"""
     data = (db.select(self.table).select(
         'username', 'email', 'real_name', 'password', 'bio', 'status',
         'role', 'uid').condition('username', username).execute())
     if data:
         return self.load(data[0], self.model)
Exemple #8
0
 def serach_count(self, key):
     q = db.select(self.table).fields(db.expr('count(*)',
             'total')).condition('status', 'published')
     _or = db.or_()
     _or.condition('slug', '%%%s%%' % key, 'LIKE').condition('title', '%%%s%%' % key, 'LIKE')
     q.condition(_or)
     return q.execute()[0][0]
Exemple #9
0
 def find(self, cid):
     data = db.select(self.table).fields('post_id', 'name', 'email',
                                         'content', 'status', 'created',
                                         'cid').condition('cid',
                                                          cid).execute()
     if data:
         return self.load(data[0], self.model)
Exemple #10
0
 def find_by_type(self, type):
     """Find and load the extend from database by eid(extend id)"""
     data = (db.select(self.table).fields('type', 'key', 'label', 'field',
                                          'attributes',
                                          'eid').condition('type',
                                                           type).execute())
     return [self.load(_) for _ in data]
Exemple #11
0
 def find(self, type, node_id, extend_id):
     data = (db.select(self.table).fields('node_id', 'type', 'extend', 'data', 'mid')
             .condition('type', type)
             .condition('node_id', node_id)
             .condition('extend',  extend_id)
             .execute())
     if data:
         return self.load(data[0])
Exemple #12
0
 def find(self, uid):
     """Find and load the user from database by uid(user id)"""
     data = (db.select(self.table).select('username', 'email', 'real_name',
             'password', 'bio', 'status', 'role', 'uid').
             condition('uid', uid).execute()
             )
     if data:
         return self.load(data[0], self.model)
Exemple #13
0
 def find_by_email(self, email):
     """Return user by email if find in database otherwise None"""
     data = (db.select(self.table).select('username', 'email', 'real_name',
             'password', 'bio', 'status', 'role', 'uid').
             condition('email', email).execute()
             )
     if data:
         return self.load(data[0], self.model)
Exemple #14
0
 def menu(self, is_menu=False):
     q = db.select(self.table).fields('parent', 'name', 'title', 'slug',
         'content', 'status', 'redirect', 'show_in_menu', 'pid').condition('show_in_menu', 1)
     if not is_menu:
         res = q.execute()
     else:
         res = q.condition('status', 'published').order_by('menu_order').execute()
     return [self.load(data,self.model) for data in res]
Exemple #15
0
 def get_published_posts(self, page=1, perpage=10, category=None):
     q = db.select(self.table).fields('title', 'slug', 'description', 'html', 'css', 'js',
                                      'category', 'status', 'allow_comment', 'author', 'updated', 'created', 'pid')
     if category:
         q.condition('category', category)
     results = (q.limit(perpage).offset((page - 1) * perpage).condition('status', 'published')
                 .order_by('created', 'DESC').execute())
     return [self.load(data, self.model) for data in results]
Exemple #16
0
 def paginate(self, page=1, perpage=10, status='all'):
     q = db.select(self.table).fields('parent', 'name', 'title', 'slug',
         'content', 'status', 'redirect', 'show_in_menu', 'pid')
     if status != 'all':
         q.condition('status', status)
     results = q.limit(perpage).offset((page - 1) * perpage).order_by('title', 'desc').execute()
     pages = [self.load(page, self.model) for page in results]
     return pages
Exemple #17
0
 def lists(self, exclude=None, sorted=False):
     q = db.select(self.table)
     if sorted:
         q.sort_by('key')
     if exclude:
         db.condition('key', exculde, '<>')
     res = q.execute()
     return [self.load(row, self.model) for row in res]
Exemple #18
0
 def find_by_post_id(self, post_id, status='approved'):
     q = db.select(self.table).fields('post_id', 'name', 'email', 'content',
                                      'status', 'created',
                                      'cid').condition('post_id', post_id)
     if status:
         q.condition('status', status)
     data = q.execute()
     return [self.load(_, self.model) for _ in data]
Exemple #19
0
 def find(self, eid):
     """Find and load the extend from database by eid(extend id)"""
     data = (db.select(self.table).fields('type', 'key', 'label', 'field',
                                          'attributes',
                                          'eid').condition('eid',
                                                           eid).execute())
     if data:
         return self.load(data[0])
Exemple #20
0
 def lists(self, exclude=None, sorted=False):
     q = db.select(self.table)
     if sorted:
         q.sort_by('key')
     if exclude:
         db.condition('key', exculde, '<>')
     res = q.execute()
     return [self.load(row, self.model) for row in res]
Exemple #21
0
 def take(self, page=1, perpage=10):
     count = self.count()
     q = db.select(self.table).select('username', 'email', 'real_name',
                                      'password', 'bio', 'status', 'role',
                                      'uid')
     results = q.limit(perpage).offset(
         (page - 1) * perpage).order_by('real_name', 'desc').execute()
     users = [self.load(user, self.model) for user in results]
     return users
Exemple #22
0
 def search(self, key, page=1, perpage=10):
     q = db.select(self.table).fields('title', 'slug', 'description', 'html', 'css', 'js',
                                      'category', 'status', 'allow_comment', 'author', 'updated', 'created', 'pid')
     _or = db.or_()
     _or.condition('slug', '%%%s%%' % key, 'LIKE').condition('title', '%%%s%%' % key, 'LIKE')
     q.condition(_or)
     results = (q.condition('status', 'published').limit(perpage).offset((page - 1) * perpage)
                 .order_by('created', 'DESC').execute())
     return [self.load(data, self.model) for data in results]
Exemple #23
0
 def find(self, uid):
     """Find and load the user from database by uid(user id)"""
     data = (db.select(self.table).select('username', 'email', 'real_name',
                                          'password', 'bio', 'status',
                                          'role',
                                          'uid').condition('uid',
                                                           uid).execute())
     if data:
         return self.load(data[0], self.model)
Exemple #24
0
 def serach_count(self, key):
     q = db.select(self.table).fields(db.expr('count(*)',
                                              'total')).condition(
                                                  'status', 'published')
     _or = db.or_()
     _or.condition('slug', '%%%s%%' % key,
                   'LIKE').condition('title', '%%%s%%' % key, 'LIKE')
     q.condition(_or)
     return q.execute()[0][0]
Exemple #25
0
 def find(self, pid):
     data = db.select(self.table).fields('title', 'slug', 'description',
                                         'html', 'css', 'js', 'category',
                                         'status', 'allow_comment',
                                         'author', 'updated', 'created',
                                         'pid').condition('pid',
                                                          pid).execute()
     if data:
         return self.load(data[0], self.model)
Exemple #26
0
 def paginate(self, page=1, perpage=10, status='all'):
     q = db.select(self.table).fields('post_id', 'name', 'email', 'content',
                                      'status', 'created', 'cid')
     if status != 'all':
         q.condition('status', status)
     results = q.limit(perpage).offset(
         (page - 1) * perpage).order_by('created').execute()
     pages = [self.load(page, self.model) for page in results]
     return pages
Exemple #27
0
 def search(self, **kw):
     """Find the users match the condition in kw"""
     q = db.select(self.table).condition('status', 'active')
     for k, v in kw:
         q.condition(k, v)
     data = q.execute()
     users = []
     for user in data:
         users.append(self.load(user, self.model))
     return users
Exemple #28
0
 def get_published_posts(self, page=1, perpage=10, category=None):
     q = db.select(self.table).fields('title', 'slug', 'description',
                                      'html', 'css', 'js', 'category',
                                      'status', 'allow_comment', 'author',
                                      'updated', 'created', 'pid')
     if category:
         q.condition('category', category)
     results = (q.limit(perpage).offset((page - 1) * perpage).condition(
         'status', 'published').order_by('created', 'DESC').execute())
     return [self.load(data, self.model) for data in results]
Exemple #29
0
 def search(self, **kw):
     """Find the users match the condition in kw"""
     q = db.select(self.table).condition('status', 'active')
     for k, v in kw:
         q.condition(k, v)
     data = q.execute()
     users = []
     for user in data:
         users.append(self.load(user, self.model))
     return users
Exemple #30
0
    def dropdown(self, show_empty_option=True, exclude=[]):
        items = []
        if show_empty_option:
            items.append((0, '--'))

        pages = db.select(self.table).fields('pid', 'name').execute()
        for page in pages:
            if page[0] in exclude:
                continue
            items.append((page[0], page[1]))

        return items
Exemple #31
0
 def search(self, key, page=1, perpage=10):
     q = db.select(self.table).fields('title', 'slug', 'description',
                                      'html', 'css', 'js', 'category',
                                      'status', 'allow_comment', 'author',
                                      'updated', 'created', 'pid')
     _or = db.or_()
     _or.condition('slug', '%%%s%%' % key,
                   'LIKE').condition('title', '%%%s%%' % key, 'LIKE')
     q.condition(_or)
     results = (q.condition('status', 'published').limit(perpage).offset(
         (page - 1) * perpage).order_by('created', 'DESC').execute())
     return [self.load(data, self.model) for data in results]
Exemple #32
0
 def count(self, **kw):
     q = db.select(self.table).fields(db.expr('COUNT(*)'))
     if kw:
         for k, v in kw.iteritems():
             q.condition(k, v)
     return q.execute()[0][0]
Exemple #33
0
 def find(self, key):
     data = db.select(self.table).condition('key', key).execute()
     if data:
         return self.load(data[0], self.model)
Exemple #34
0
 def find(self, pid):
     data = db.select(self.table).fields('title', 'slug', 'description', 'html', 'css', 'js',
             'category', 'status', 'allow_comment', 'author', 'updated', 'created', 'pid').condition('pid', pid).execute()
     if data:
         return self.load(data[0], self.model)
Exemple #35
0
 def find(self, id):
     q = db.select(self.table).condition(self.primary_id, id)
     data = q.query()
     if data:
         return self.load(data[0], self.model)
Exemple #36
0
 def count(self, **kw):
     q = db.select(self.table).fields(db.expr('COUNT(*)'))
     if kw:
         for k, v in kw.iteritems():
             q.condition(k, v)
     return q.execute()[0][0]
Exemple #37
0
 def count_slug(self, slug):
     return db.select(self.table).fields(db.expr('COUNT(*)')).condition('slug', slug).execute()[0][0]
Exemple #38
0
 def paginate(self, page=1, perpage=10):
     """Paginate the categories"""
     results = (db.select(self.table).fields('title', 'slug', 'description', 'cid')
                .limit(perpage).offset((page - 1) * perpage)
                .order_by('title').execute())
     return [self.load(data, self.model) for data in results]
Exemple #39
0
 def category_count(self, category_id):
     return db.select(self.table).fields(db.expr(
         'count(*)', 'total')).condition('category', category_id).condition(
             'status', 'published').execute()[0][0]
Exemple #40
0
 def count(self):
     return db.select(self.table).fields(
         db.expr('COUNT(*)')).execute()[0][0]
Exemple #41
0
 def find_by_slug(self, slug):
     data = db.select(self.table).fields('parent', 'name', 'title', 'slug',
         'content', 'status', 'redirect', 'show_in_menu', 'pid').condition('slug', slug).execute()
     if data:
         return self.load(data[0], self.model)
Exemple #42
0
 def count(self, status=None):
     q= db.select(self.table).fields(db.expr('COUNT(*)'))
     if status != 'all':
         q.condition('status', status)
     return q.execute()[0][0]
Exemple #43
0
 def field(self, type, key, eid=-1):
     field = db.select(self.table).fields(
         'type', 'key', 'label', 'field', 'attributes',
         'eid').condition('type', type).condition('key', key).execute()
     if field:
         return self.load(field[0])
Exemple #44
0
 def find(self, eid):
     """Find and load the extend from database by eid(extend id)"""
     data = (db.select(self.table).fields('type', 'key', 'label', 'field', 'attributes', 'eid').
             condition('eid', eid).execute())
     if data:
         return self.load(data[0])
Exemple #45
0
 def count(self):
     return db.select(self.table).fields(db.expr('COUNT(*)')).execute()[0][0]
Exemple #46
0
 def spam_count(self, domain):
     return db.select(self.table).fields(db.expr('COUNT(*)')).condition(
         'email', domain, 'LIKE').execute()[0][0]
Exemple #47
0
 def find_by_type(self, type):
     """Find and load the extend from database by eid(extend id)"""
     data = (db.select(self.table).fields('type', 'key', 'label', 'field', 'attributes', 'eid').
             condition('type', type).execute())
     return [self.load(_) for _ in data]
Exemple #48
0
 def paginate(self, page=1, perpage=10):
     data = db.select(self.table).fields('type', 'key', 'label', 'field', 'attributes', 'eid').limit(perpage).offset((page - 1) * perpage).execute()
     return [self.load(_) for _ in data]
Exemple #49
0
 def field(self, type, key, eid=-1):
     field = db.select(self.table).fields('type', 'key', 'label', 'field', 'attributes', 'eid').condition('type', type).condition('key', key).execute()
     if field:
         return self.load(field[0])
Exemple #50
0
 def dropdown(self):
     """Returns the all category id"""
     return db.select(self.table).fields('cid', 'title').execute(as_dict=True)
Exemple #51
0
 def find(self, cid):
     """Find category by category id, return the category model instance if category id exists in database"""
     data = db.select(self.table).fields('title', 'slug', 'description', 'cid').condition('cid', cid).execute()
     if data:
         return self.load(data[0], self.model)
Exemple #52
0
 def count(self, status=None):
     q = db.select(self.table).fields(db.expr('COUNT(*)'))
     if status:
         q.condition('status', status)
     return q.execute()[0][0]
Exemple #53
0
 def order_by_title(self):
     results = db.select(self.table).fields('title', 'slug', 'description', 'cid').order_by('title').execute()
     return [self.load(data, self.model) for data in results]
Exemple #54
0
 def find(self, key):
     data = db.select(self.table).condition('key', key).execute()
     if data:
         return self.load(data[0], self.model)
Exemple #55
0
 def find_by_slug(self, slug):
     """Find all categories by slug  sql like rule"""
     data = db.select(self.table).fields('title', 'slug', 'description', 'cid').condition('slug', slug).execute()
     if data:
         return self.load(data[0], self.model)