Example #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)
Example #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)
Example #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
Example #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]
Example #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])
Example #6
0
File: user.py Project: lf8289/white
 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
Example #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)
Example #8
0
File: post.py Project: lf8289/white
 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]
Example #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)
Example #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]
Example #11
0
File: meta.py Project: lf8289/white
 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])
Example #12
0
File: user.py Project: lf8289/white
 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)
Example #13
0
File: user.py Project: lf8289/white
 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)
Example #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]
Example #15
0
File: post.py Project: lf8289/white
 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]
Example #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
Example #17
0
File: pair.py Project: zgwdg/white
 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]
Example #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]
Example #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])
Example #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]
Example #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
Example #22
0
File: post.py Project: lf8289/white
 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]
Example #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)
Example #24
0
File: post.py Project: zgwdg/white
 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]
Example #25
0
File: post.py Project: zgwdg/white
 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)
Example #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
Example #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
Example #28
0
File: post.py Project: zgwdg/white
 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]
Example #29
0
File: user.py Project: lf8289/white
 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
Example #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
Example #31
0
File: post.py Project: zgwdg/white
 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]
Example #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]
Example #33
0
File: pair.py Project: zgwdg/white
 def find(self, key):
     data = db.select(self.table).condition('key', key).execute()
     if data:
         return self.load(data[0], self.model)
Example #34
0
File: post.py Project: lf8289/white
 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)
Example #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)
Example #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]
Example #37
0
 def count_slug(self, slug):
     return db.select(self.table).fields(db.expr('COUNT(*)')).condition('slug', slug).execute()[0][0]
Example #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]
Example #39
0
File: post.py Project: zgwdg/white
 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]
Example #40
0
 def count(self):
     return db.select(self.table).fields(
         db.expr('COUNT(*)')).execute()[0][0]
Example #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)
Example #42
0
File: page.py Project: lf8289/white
 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]
Example #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])
Example #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])
Example #45
0
 def count(self):
     return db.select(self.table).fields(db.expr('COUNT(*)')).execute()[0][0]
Example #46
0
 def spam_count(self, domain):
     return db.select(self.table).fields(db.expr('COUNT(*)')).condition(
         'email', domain, 'LIKE').execute()[0][0]
Example #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]
Example #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]
Example #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])
Example #50
0
 def dropdown(self):
     """Returns the all category id"""
     return db.select(self.table).fields('cid', 'title').execute(as_dict=True)
Example #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)
Example #52
0
File: post.py Project: zgwdg/white
 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]
Example #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]
Example #54
0
 def find(self, key):
     data = db.select(self.table).condition('key', key).execute()
     if data:
         return self.load(data[0], self.model)
Example #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)