Exemplo n.º 1
0
    def __create_rec(*args, **kwargs):
        '''
        Create the record.
        '''
        uid = args[0]
        kind = args[1]
        post_data = kwargs['post_data']

        try:
            TabWiki.create(
                uid=uid,
                title=post_data['title'].strip(),
                date=datetime.datetime.now(),
                cnt_html=tools.markdown2html(post_data['cnt_md']),
                time_create=tools.timestamp(),
                user_name=post_data['user_name'],
                cnt_md=tornado.escape.xhtml_escape(post_data['cnt_md']),
                time_update=tools.timestamp(),
                view_count=1,
                kind=kind,  # 1 for wiki,  2 for page
            )
            return True
        except Exception as err:
            print(repr(err))
            return False
Exemplo n.º 2
0
 def view_count_plus(slug):
     '''
     View count plus one.
     '''
     entry = TabWiki.update(view_count=TabWiki.view_count +
                            1, ).where(TabWiki.uid == slug)
     entry.execute()
Exemplo n.º 3
0
 def update_view_count_by_uid(uid):
     '''
     update the count of wiki, by uid.
     '''
     entry = TabWiki.update(view_count=TabWiki.view_count +
                            1).where(TabWiki.uid == uid)
     entry.execute()
Exemplo n.º 4
0
 def query_pager_by_kind(kind, current_page_num=1):
     '''
     Query pager
     '''
     return TabWiki.select().where(TabWiki.kind == kind).order_by(
         TabWiki.time_create.desc()).paginate(current_page_num,
                                              CMS_CFG['list_num'])
Exemplo n.º 5
0
 def update_view_count(citiao):
     '''
     view count of the wiki, plus 1. By wiki
     '''
     entry = TabWiki.update(view_count=TabWiki.view_count +
                            1).where(TabWiki.title == citiao)
     entry.execute()
Exemplo n.º 6
0
    def count_of_certain_kind(kind):
        '''
        Get the count of certain kind.
        '''

        recs = TabWiki.select().where(TabWiki.kind == kind)

        return recs.count()
Exemplo n.º 7
0
 def update_cnt(uid, post_data):
     entry = TabWiki.update(
         cnt_html=tools.markdown2html(post_data['cnt_md']),
         user_name=post_data['user_name'],
         cnt_md=tornado.escape.xhtml_escape(post_data['cnt_md']),
         time_update=tools.timestamp(),
     ).where(TabWiki.uid == uid)
     entry.execute()
Exemplo n.º 8
0
    def query_all(**kwargs):
        '''
        Qeury recent wiki.
        '''
        kind = kwargs.get('kind', '1')
        limit = kwargs.get('limit', 50)

        return TabWiki.select().where(TabWiki.kind == kind).limit(limit)
Exemplo n.º 9
0
 def query_random(num=6, kind='1'):
     '''
     Query wikis randomly.
     '''
     return TabWiki.select().where(
         TabWiki.kind == kind
     ).order_by(
         peewee.fn.Random()
     ).limit(num)
Exemplo n.º 10
0
 def query_most(num=8, kind='1'):
     '''
     List the most viewed wiki.
     '''
     return TabWiki.select().where(
         TabWiki.kind == kind
     ).order_by(
         TabWiki.view_count.desc()
     ).limit(num)
Exemplo n.º 11
0
 def query_dated(num=10, kind='1'):
     '''
     List the wiki of dated.
     '''
     return TabWiki.select().where(
         TabWiki.kind == kind
     ).order_by(
         TabWiki.time_update.desc()
     ).limit(num)
Exemplo n.º 12
0
 def query_all(**kwargs):
     if 'kind' in kwargs:
         kind = kwargs['kind']
     else:
         kind = '1'
     if 'limit' in kwargs:
         limit = kwargs['limit']
     else:
         limit = 999999
     return TabWiki.select().where(TabWiki.kind == kind).limit(limit)
Exemplo n.º 13
0
 def get_by_wiki(citiao):
     '''
     Get the wiki record by title.
     '''
     q_res = TabWiki.select().where(TabWiki.title == citiao)
     the_count = q_res.count()
     if the_count == 0 or the_count > 1:
         return None
     else:
         MWiki.update_view_count(citiao)
         return q_res.get()
Exemplo n.º 14
0
    def update(uid, post_data):
        title = post_data['title'].strip()
        if len(title) < 2:
            return False

        cnt_html = tools.markdown2html(post_data['cnt_md'])

        entry = TabWiki.update(
            title=title,
            date=datetime.datetime.now(),
            cnt_html=cnt_html,
            user_name=post_data['user_name'],
            cnt_md=tornado.escape.xhtml_escape(post_data['cnt_md']),
            time_update=tools.timestamp()).where(TabWiki.uid == uid)
        entry.execute()
Exemplo n.º 15
0
 def query_recent_edited(timstamp, kind='1'):
     return TabWiki.select().where((TabWiki.kind == kind) & (
         TabWiki.time_update > timstamp)).order_by(
             TabWiki.time_update.desc())
Exemplo n.º 16
0
 def get_counts():
     '''
     The count in table.
     '''
     return TabWiki.select().count()
Exemplo n.º 17
0
 def view_count_plus(slug):
     entry = TabWiki.update(view_count=TabWiki.view_count +
                            1, ).where(TabWiki.uid == slug)
     entry.execute()
Exemplo n.º 18
0
 def total_number(kind):
     '''
     Return the number of certian slug.
     '''
     return TabWiki.select().where(TabWiki.kind == kind).count()
Exemplo n.º 19
0
 def query_recent(num=8, kind='1'):
     return TabWiki.select().where(TabWiki.kind == kind).order_by(
         TabWiki.time_update.desc()).limit(num)
Exemplo n.º 20
0
 def get_counts():
     '''
     The count in table.
     '''
     # adding ``None`` to hide ``No value for argument 'database' in method call``
     return TabWiki.select().count(None)