Exemplo n.º 1
0
    def restore(self, hist_uid):
        '''
        Restore by ID
        '''
        if self.check_post_role()['ADMIN']:
            pass
        else:
            return False
        histinfo = MWikiHist.get_by_uid(hist_uid)
        if histinfo:
            pass
        else:
            return False

        postinfo = MWiki.get_by_uid(histinfo.wiki_id)
        cur_cnt = tornado.escape.xhtml_unescape(postinfo.cnt_md)
        old_cnt = tornado.escape.xhtml_unescape(histinfo.cnt_md)

        MWiki.update_cnt(histinfo.wiki_id, {
            'cnt_md': old_cnt,
            'user_name': self.userinfo.user_name
        })

        MWikiHist.update_cnt(histinfo.uid, {
            'cnt_md': cur_cnt,
            'user_name': postinfo.user_name
        })

        if postinfo.kind == '1':
            self.redirect('/wiki/{0}'.format(postinfo.title))
        elif postinfo.kind == '2':
            self.redirect('/page/{0}.html'.format(postinfo.uid))
Exemplo n.º 2
0
 def test_update_cnt(self):
     self.add_w_h()
     aa = MWikiHist.get_by_uid(self.uid)
     post_data = {'user_name': self.username, 'cnt_md': 'asdf'}
     MWikiHist.update_cnt(self.uid, post_data)
     bb = MWikiHist.get_by_uid(self.uid)
     assert aa.cnt_md != bb.cnt_md
     assert bb.cnt_md == post_data['cnt_md']
     self.tearDown()
Exemplo n.º 3
0
class WikiManHandler(BaseHandler):
    def initialize(self):
        self.init()
        self.mpost = MWiki()
        self.mposthist = MWikiHist()
        self.tmpl_dir = 'wiki_man'

    def get(self, url_str=''):
        url_arr = self.parse_url(url_str)
        if url_arr[0] == 'view':
            self.view(url_arr[1])
        elif url_arr[0] == 'edit':
            self.to_edit(url_arr[1])
        elif url_arr[0] == 'restore':
            self.restore(url_arr[1])
        elif url_arr[0] == 'delete':
            self.delete(url_arr[1])
        else:
            kwd = {
                'info': '页面未找到',
            }
            self.render(
                'html/404.html',
                kwd=kwd,
                userinfo=self.userinfo,
            )

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

        if url_arr[0] == 'edit':
            self.update(url_arr[1])
        else:
            self.redirect('html/404.html')

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

        post_data = self.get_post_data()
        if self.userinfo:
            post_data['user_name'] = self.userinfo.user_name
        else:
            post_data['user_name'] = ''
        cur_info = self.mpost.get_by_id(uid)
        self.mposthist.insert_data(cur_info)
        self.mpost.update_cnt(uid, post_data)
        if cur_info.kind == '1':
            self.redirect('/wiki/{0}'.format(cur_info.title))
        elif cur_info.kind == '2':
            self.redirect('/page/{0}.html'.format(cur_info.uid))

    @tornado.web.authenticated
    def to_edit(self, postid):
        if self.userinfo.role[0] > '1':
            pass
        else:
            return False
        post_rec = self.mpost.get_by_uid(postid)
        self.render(
            '{0}/wiki_man_edit.html'.format(self.tmpl_dir),
            userinfo=self.userinfo,
            unescape=tornado.escape.xhtml_escape,
            postinfo=post_rec,
        )

    @tornado.web.authenticated
    def delete(self, uid):
        if self.check_post_role(self.userinfo)['DELETE']:
            pass
        else:
            return False

        histinfo = self.mposthist.get_by_id(uid)
        if histinfo:
            pass
        else:
            return False

        postinfo = self.mpost.get_by_id(histinfo.wiki_id)
        self.mposthist.delete(uid)
        self.redirect('/wiki_man/view/{0}'.format(postinfo.uid))

    def view(self, uid):
        postinfo = self.mpost.get_by_id(uid)
        if postinfo:
            pass
        else:
            return

        hist_recs = self.mposthist.query_by_wikiid(uid, limit=5)
        html_diff_arr = []
        for hist_rec in hist_recs:

            if hist_rec:
                infobox = diff_table(hist_rec.cnt_md, postinfo.cnt_md)
            else:
                infobox = ''

            html_diff_arr.append({
                'hist_uid': hist_rec.uid,
                'html_diff': infobox
            })

        self.render(
            '{0}/wiki_man_view.html'.format(self.tmpl_dir),
            userinfo=self.userinfo,
            unescape=tornado.escape.xhtml_escape,
            view=postinfo,  # Deprecated
            postinfo=postinfo,
            html_diff_arr=html_diff_arr)

    @tornado.web.authenticated
    def restore(self, hist_uid):
        if self.check_post_role(self.userinfo)['ADMIN']:
            pass
        else:
            return False
        histinfo = self.mposthist.get_by_id(hist_uid)
        if histinfo:
            pass
        else:
            return False

        postinfo = self.mpost.get_by_id(histinfo.wiki_id)
        cur_cnt = tornado.escape.xhtml_unescape(postinfo.cnt_md)
        old_cnt = tornado.escape.xhtml_unescape(histinfo.cnt_md)

        self.mpost.update_cnt(histinfo.wiki_id, {
            'cnt_md': old_cnt,
            'user_name': self.userinfo.user_name
        })

        self.mposthist.update_cnt(histinfo.uid, {
            'cnt_md': cur_cnt,
            'user_name': postinfo.user_name
        })

        if postinfo.kind == '1':
            self.redirect('/wiki/{0}'.format(postinfo.title))
        elif postinfo.kind == '2':
            self.redirect('/page/{0}.html'.format(postinfo.uid))
Exemplo n.º 4
0
 def test_update_cnt(self):
     post_data = {'user_name': 'giser', 'cnt_md': 'asdf'}
     MWikiHist.update_cnt(self.userinfo['uid'], post_data)
     assert True