Exemple #1
0
 def test_query_recent(self):
     self.add_mess()
     aa = MWiki.query_recent(num=50)
     tf = False
     for i in aa:
         if i.uid == self.uid:
             tf = True
             break
     self.tearDown()
     assert tf
Exemple #2
0
 def recent(self):
     '''
     List recent wiki.
     '''
     kwd = {
         'pager': '',
         'title': 'Recent Pages',
     }
     self.render('wiki_page/wiki_list.html',
                 view=MWiki.query_recent(),
                 format_date=tools.format_date,
                 kwd=kwd,
                 userinfo=self.userinfo)
Exemple #3
0
def do_for_wiki(writer, rand=True, doc_type=''):
    if rand:
        recs = MWiki.query_random(num=10, kind='1')
    else:
        recs = MWiki.query_recent(num=2, kind='1')

    for rec in recs:
        text2 = rec.title + ',' + html2text.html2text(
            tornado.escape.xhtml_unescape(rec.cnt_html))
        writer.update_document(title=rec.title,
                               catid='sid1',
                               type=doc_type,
                               link='/wiki/{0}'.format(rec.title),
                               content=text2)
Exemple #4
0
 def list(self):
     '''
     View the list of the pages.
     '''
     kwd = {
         'pager': '',
         'title': '单页列表',
     }
     self.render('wiki_page/page_list.html',
                 kwd=kwd,
                 view=MWiki.query_recent(),
                 view_all=MWiki.query_all(),
                 format_date=tools.format_date,
                 userinfo=self.userinfo,
                 cfg=CMS_CFG)
Exemple #5
0
 def recent(self):
     '''
     List recent wiki.
     :return:
     '''
     kwd = {
         'pager': '',
         'unescape': tornado.escape.xhtml_unescape,
         'title': 'Recent Pages',
     }
     self.render('wiki_page/wiki_list.html',
                 view=MWiki.query_recent(),
                 format_date=tools.format_date,
                 kwd=kwd,
                 userinfo=self.userinfo)
Exemple #6
0
def do_for_page(rand=True, doc_type=''):
    if rand:
        recs = MWiki.query_random(num=4, kind='2')
    else:
        recs = MWiki.query_recent(num=2, kind='2')

    for rec in recs:
        text2 = rec.title + ',' + html2text.html2text(
            tornado.escape.xhtml_unescape(rec.cnt_html))
        writer = TOR_IDX.writer()
        writer.update_document(title=rec.title,
                               catid='sid1',
                               type=doc_type,
                               link='/page/{0}'.format(rec.uid),
                               content=text2)
        writer.commit()
Exemple #7
0
def do_for_wiki(writer, rand=True, doc_type=''):
    mpost = MWiki()
    if rand:
        recs = mpost.query_random(50, )
    else:
        recs = mpost.query_recent(50, )

    print(recs.count())
    for rec in recs:
        # sleep(0.1)
        text2 = rec.title + ',' + html2text.html2text(
            tornado.escape.xhtml_unescape(rec.cnt_html))
        # writer.update_document(path=u"/a",content="Replacement for the first document")
        writer.update_document(title=rec.title,
                               catid='0000',
                               type=doc_type,
                               link='/wiki/{0}'.format(rec.title),
                               content=text2)
Exemple #8
0
    def p_list(self):
        pages = MWiki.query_recent(20, kind='2')

        self.render('admin/page_ajax/page_list.html', postrecs=pages)
Exemple #9
0
class WikiHandler(BaseHandler):
    def initialize(self):
        self.init()
        self.mwiki = MWiki()
        self.mwiki_hist = MWikiHist()

    def get(self, url_str=''):
        url_arr = self.parse_url(url_str)

        if url_str == 'recent':
            self.recent()
        elif url_arr[0] == 'ajax_count_plus':
            self.ajax_count_plus(url_arr[1])
        elif url_str == 'refresh':
            self.refresh()
        elif url_arr[0] == 'edit':
            self.to_modify(url_arr[1])
        elif len(url_arr) == 1:
            self.wiki(url_str)
        else:
            kwd = {
                'info': '页面未找到',
            }
            self.render('html/404.html', kwd=kwd)

    def post(self, url_str=''):
        url_arr = self.parse_url(url_str)
        if url_arr[0] == 'edit':
            self.update(url_arr[1])
        elif url_arr[0] == 'add':
            self.wikinsert()
        else:
            self.redirect('html/404.html')

    def recent(self):
        kwd = {
            'pager': '',
            'unescape': tornado.escape.xhtml_unescape,
            'title': '最近文档',
        }
        self.render(
            'doc/wiki/wiki_list.html',
            view=self.mwiki.query_recent(),
            format_date=tools.format_date,
            cfg=config.cfg,
            kwd=kwd,
            userinfo=self.userinfo,
        )

    def refresh(self):
        kwd = {
            'pager': '',
            'unescape': tornado.escape.xhtml_unescape,
            'title': '最近文档',
        }
        self.render(
            'doc/wiki/wiki_list.html',
            view=self.mwiki.query_dated(16),
            format_date=tools.format_date,
            kwd=kwd,
            cfg=config.cfg,
            userinfo=self.userinfo,
        )

    def wiki(self, title):
        dbdate = self.mwiki.get_by_wiki(title)
        if dbdate:
            self.viewit(dbdate)
        else:
            self.to_add(title)

    @tornado.web.authenticated
    def to_add(self, title):
        if self.check_doc_priv(self.userinfo)['ADD']:
            pass
        else:
            return False

        kwd = {
            'title': title,
            'pager': '',
        }
        self.render(
            'doc/wiki/wiki_add.html',
            kwd=kwd,
            cfg=config.cfg,
            userinfo=self.userinfo,
        )

    @tornado.web.authenticated
    def update(self, uid):

        raw_data = self.mwiki.get_by_id(uid)
        if self.check_doc_priv(
                self.userinfo
        )['EDIT'] or raw_data.user_name == self.get_current_user():
            pass
        else:
            return False
        post_data = {}
        for key in self.request.arguments:
            post_data[key] = self.get_arguments(key)
        post_data['user_name'] = self.get_current_user()
        self.mwiki.update(uid, post_data)
        self.mwiki_hist.insert_data(raw_data)
        self.redirect('/wiki/{0}'.format(
            tornado.escape.url_escape(post_data['title'][0])))

    @tornado.web.authenticated
    def to_modify(self, id_rec):
        wiki_rec = self.mwiki.get_by_id(id_rec)
        # 用户具有管理权限,或文章是用户自己发布的。
        if self.check_doc_priv(
                self.userinfo
        )['EDIT'] or wiki_rec.user_name == self.get_current_user():
            pass
        else:
            return False

        kwd = {
            'pager': '',
        }
        self.render(
            'doc/wiki/wiki_edit.html',
            kwd=kwd,
            unescape=tornado.escape.xhtml_unescape,
            dbrec=wiki_rec,
            cfg=config.cfg,
            userinfo=self.userinfo,
        )

    def viewit(self, view):
        kwd = {
            'pager': '',
            'editable': self.editable(),
        }
        self.render(
            'doc/wiki/wiki_view.html',
            view=view,
            unescape=tornado.escape.xhtml_unescape,
            kwd=kwd,
            userinfo=self.userinfo,
            cfg=config.cfg,
        )

    def ajax_count_plus(self, slug):
        output = {
            'status': 1 if self.mwiki.update_view_count(slug) else 0,
        }

        return json.dump(output, self)

    @tornado.web.authenticated
    def wikinsert(self):
        if self.check_doc_priv(self.userinfo)['ADD']:
            pass
        else:
            return False
        post_data = {}
        for key in self.request.arguments:
            post_data[key] = self.get_arguments(key)

        post_data['user_name'] = self.get_current_user()
        if self.mwiki.get_by_wiki(post_data['title'][0]):
            pass
        else:
            self.mwiki.insert_data(post_data)

        self.redirect('/wiki/{0}'.format(
            tornado.escape.url_escape(post_data['title'][0])))
Exemple #10
0
 def p_list(self):
     '''
     List the post .
     '''
     self.render('admin/page_ajax/page_list.html',
                 postrecs=MWiki.query_recent(20, kind='2'))
Exemple #11
0
class WikiHandler(BaseHandler):
    def initialize(self):
        self.init()
        self.mwiki = MWiki()
        self.mwiki_hist = MWikiHist()
        self.kind = '1'

    def get(self, url_str=''):
        url_arr = self.parse_url(url_str)

        if url_str == 'recent':
            self.recent()
        elif url_arr[0] == 'ajax_count_plus':
            self.ajax_count_plus(url_arr[1])
        elif url_str == 'refresh':
            self.refresh()
        elif url_arr[0] == 'edit':
            self.to_modify(url_arr[1])
        elif len(url_arr) == 1:
            self.wiki(url_str)
        else:
            kwd = {
                'info': '页面未找到',
            }
            self.render('html/404.html', kwd=kwd)

    def post(self, url_str=''):
        url_arr = self.parse_url(url_str)
        if url_arr[0] == 'edit':
            self.update(url_arr[1])
        elif url_arr[0] == 'add':
            self.wikinsert()
        else:
            self.redirect('html/404.html')

    def recent(self):
        kwd = {
            'pager': '',
            'unescape': tornado.escape.xhtml_unescape,
            'title': '最近文档',
        }
        self.render(
            'doc/wiki/wiki_list.html',
            view=self.mwiki.query_recent(),
            format_date=tools.format_date,
            # cfg=cfg, # Todo: Should delete.
            kwd=kwd,
            userinfo=self.userinfo,
        )

    def refresh(self):
        kwd = {
            'pager': '',
            'unescape': tornado.escape.xhtml_unescape,
            'title': '最近文档',
        }
        self.render(
            'doc/wiki/wiki_list.html',
            view=self.mwiki.query_dated(16),
            format_date=tools.format_date,
            kwd=kwd,
            # cfg=cfg, # Todo: Should delete
            userinfo=self.userinfo,
        )

    def wiki(self, title):
        postinfo = self.mwiki.get_by_wiki(title)
        if postinfo:
            if postinfo.kind == self.kind:
                self.viewit(postinfo)
            else:
                return False
        else:
            self.to_add(title)

    @tornado.web.authenticated
    def update(self, uid):

        raw_data = self.mwiki.get_by_id(uid)
        if self.check_post_role(
                self.userinfo
        )['EDIT'] or raw_data.user_name == self.get_current_user():
            pass
        else:
            return False
        post_data = self.get_post_data()

        post_data['user_name'] = self.get_current_user()
        self.mwiki.update(uid, post_data)
        self.mwiki_hist.insert_data(raw_data)
        self.redirect('/wiki/{0}'.format(
            tornado.escape.url_escape(post_data['title'])))

    @tornado.web.authenticated
    def to_modify(self, id_rec):
        wiki_rec = self.mwiki.get_by_id(id_rec)
        # 用户具有管理权限,或文章是用户自己发布的。
        if self.check_post_role(
                self.userinfo
        )['EDIT'] or wiki_rec.user_name == self.get_current_user():
            pass
        else:
            return False

        kwd = {
            'pager': '',
        }
        self.render(
            'doc/wiki/wiki_edit.html',
            kwd=kwd,
            unescape=tornado.escape.xhtml_unescape,
            dbrec=wiki_rec,  # Deprecated.
            postinfo=wiki_rec,
            # cfg=cfg, # Todo: Should delete
            userinfo=self.userinfo,
        )

    def viewit(self, view):
        kwd = {
            'pager': '',
            'editable': self.editable(),
        }
        self.render(
            'doc/wiki/wiki_view.html',
            view=view,  # Deprecated
            postinfo=view,
            unescape=tornado.escape.xhtml_unescape,
            kwd=kwd,
            userinfo=self.userinfo,
            # cfg=cfg, # Todo: Should delete
        )

    def ajax_count_plus(self, slug):
        output = {
            'status': 1 if self.mwiki.update_view_count(slug) else 0,
        }

        return json.dump(output, self)

    def to_add(self, title):
        kwd = {
            'title': title,
            'pager': '',
        }
        if self.userinfo and self.userinfo.role[0] > '0':
            tmpl = 'doc/wiki/wiki_add.html'
        else:
            tmpl = 'doc/wiki/wiki_login.html'

        self.render(
            tmpl,
            kwd=kwd,
            # cfg= cfg, # Todo: should delete
            userinfo=self.userinfo,
        )

    @tornado.web.authenticated
    def wikinsert(self):
        if self.userinfo.role[0] > '0':
            pass
        else:
            return False

        post_data = self.get_post_data()

        post_data['user_name'] = self.get_current_user()
        if self.mwiki.get_by_wiki(post_data['title']):
            pass
        else:
            self.mwiki.insert_data(post_data)

        self.redirect('/wiki/{0}'.format(
            tornado.escape.url_escape(post_data['title'])))