Пример #1
0
    def update(self, uid):
        '''
        Update the wiki.
        '''
        postinfo = MWiki.get_by_uid(uid)
        if self.check_post_role(
        )['EDIT'] or postinfo.user_name == self.get_current_user():
            pass
        else:
            return False
        post_data = self.get_post_data()
        post_data['user_name'] = self.userinfo.user_name

        cnt_old = tornado.escape.xhtml_unescape(postinfo.cnt_md).strip()
        cnt_new = post_data['cnt_md'].strip()

        if cnt_old == cnt_new:
            pass
        else:
            MWikiHist.create_wiki_history(postinfo)

        MWiki.update(uid, post_data)

        # cele_gen_whoosh.delay()
        tornado.ioloop.IOLoop.instance().add_callback(self.cele_gen_whoosh)

        self.redirect('/wiki/{0}'.format(
            tornado.escape.url_escape(post_data['title'])))
Пример #2
0
    def update(self, uid):
        '''
        Update the post via ID.
        '''
        if self.userinfo.role[0] > '0':
            pass
        else:
            return False

        post_data = self.get_post_data()
        post_data[
            'user_name'] = self.userinfo.user_name if self.userinfo else ''
        cur_info = MWiki.get_by_uid(uid)

        cnt_old = tornado.escape.xhtml_unescape(cur_info.cnt_md).strip()
        cnt_new = post_data['cnt_md'].strip()
        if cnt_old == cnt_new:
            pass
        else:
            MWikiHist.create_wiki_history(cur_info, self.userinfo)
            MWiki.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))
Пример #3
0
    def update(self, slug):
        '''
        Update the page.
        :param slug:
        :return:
        '''

        if self.__could_edit(slug):
            pass
        else:
            return False
        post_data = self.get_post_data()

        post_data['user_name'] = self.userinfo.user_name

        pageinfo = MWiki.get_by_uid(slug)

        cnt_old = tornado.escape.xhtml_unescape(pageinfo.cnt_md).strip()
        cnt_new = post_data['cnt_md'].strip()
        if cnt_old == cnt_new:
            pass
        else:
            MWikiHist.create_wiki_history(MWiki.get_by_uid(slug))

        MWiki.update(slug, post_data)
        tornado.ioloop.IOLoop.instance().add_callback(self.cele_gen_whoosh)

        self.redirect('/page/{0}.html'.format(post_data['slug']))
Пример #4
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))
Пример #5
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()
Пример #6
0
    def delete(self, uid):
        if self.check_post_role()['DELETE']:
            pass
        else:
            return False

        histinfo = MWikiHist.get_by_uid(uid)
        if histinfo:
            pass
        else:
            return False

        postinfo = MWiki.get_by_uid(histinfo.wiki_id)
        MWikiHist.delete(uid)
        self.redirect('/wiki_man/view/{0}'.format(postinfo.uid))
Пример #7
0
    def view(self, uid):
        '''
        View the wiki with hisotical infos.
        '''
        postinfo = MWiki.get_by_uid(uid)
        if postinfo:
            pass
        else:
            return

        hist_recs = MWikiHist.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)
                hist_user = hist_rec.user_name
            else:
                infobox = ''

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

        self.render(
            'man_info/wiki_man_view.html',
            userinfo=self.userinfo,
            unescape=tornado.escape.xhtml_unescape,
            view=postinfo,  # Deprecated
            postinfo=postinfo,
            html_diff_arr=html_diff_arr)
Пример #8
0
 def add_w_h(self):
     self.add_user()
     self.add_wiki()
     post_data = MWiki.get_by_uid(self.wiki_uid)
     userinfo = MUser.get_by_uid(self.user_uid)
     aa = MWikiHist.create_wiki_history(post_data, userinfo)
     self.uid = aa
Пример #9
0
def __get_page_review(email_cnt, idx):
    '''
    Review for pages.
    '''
    recent_posts = MWiki.query_recent_edited(tools.timestamp() - TIME_LIMIT)
    for recent_post in recent_posts:
        hist_rec = MWikiHist.get_last(recent_post.uid)
        if hist_rec:
            foo_str = '''
                    <tr><td>{0}</td><td>{1}</td><td class="diff_chg">Edit</td><td>{2}</td>
                    <td><a href="{3}">{3}</a></td></tr>
                    '''.format(
                idx, recent_post.user_name, recent_post.title,
                os.path.join(SITE_CFG['site_url'], 'wiki', recent_post.title))
            email_cnt = email_cnt + foo_str
        else:
            foo_str = '''
                    <tr><td>{0}</td><td>{1}</td><td class="diff_add">New </td><td>{2}</td>
                    <td><a href="{3}">{3}</a></td></tr>
                    '''.format(
                idx, recent_post.user_name, recent_post.title,
                os.path.join(SITE_CFG['site_url'], 'wiki', recent_post.title))
            email_cnt = email_cnt + foo_str
        idx = idx + 1

    return email_cnt, idx
Пример #10
0
    def update(self, uid):
        '''
        Update the post via ID.
        '''
        if self.userinfo.role[0] > '0':
            pass
        else:
            return False

        post_data = self.get_post_data()
        post_data['user_name'] = self.userinfo.user_name if self.userinfo else ''
        cur_info = MWiki.get_by_uid(uid)
        MWikiHist.create_wiki_history(cur_info, self.userinfo)
        MWiki.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))
Пример #11
0
 def test_query_by_wikiid(self):
     self.add_w_h()
     aa = MWikiHist.query_by_wikiid(self.wiki_uid)
     tf = False
     for i in aa:
         if i.uid == self.uid:
             tf = True
             break
     self.tearDown()
     assert tf
Пример #12
0
    def view(self, uid):
        '''
        View the wiki with hisotical infos.
        '''
        postinfo = MWiki.get_by_uid(uid)
        if postinfo:
            pass
        else:
            return

        hist_recs = MWikiHist.query_by_wikiid(uid, limit=5)
        html_diff_arr = []
        if hist_recs:

            for hist_rec in hist_recs:


                infobox = diff_table(hist_rec.cnt_md, postinfo.cnt_md)
                hist_user = hist_rec.user_name
                hist_time = hist_rec.time_update

                hist_words_num = len((hist_rec.cnt_md).strip())
                post_words_num = len((postinfo.cnt_md).strip())
                up_words_num = post_words_num - hist_words_num




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

            kwd = {}
            self.render('man_info/wiki_man_view.html',
                        userinfo=self.userinfo,
                        postinfo=postinfo,
                        html_diff_arr=html_diff_arr,
                        kwd=kwd)
        else:
            self.redirect('/{0}/{1}'.format(router_post[postinfo.kind], postinfo.uid))
    def view(self, uid):
        '''
        View the wiki with hisotical infos.
        '''
        postinfo = MWiki.get_by_uid(uid)
        if postinfo:
            pass
        else:
            return

        hist_recs = MWikiHist.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)
                hist_user = hist_rec.user_name
                hist_time = hist_rec.time_update

                hist_words_num = len((hist_rec.cnt_md).strip())
                post_words_num = len((postinfo.cnt_md).strip())
                up_words_num = post_words_num - hist_words_num
            else:
                infobox = ''
                hist_user = ''
                hist_time = ''
                up_words_num = ''

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

        self.render(
            'man_info/wiki_man_view.html',
            userinfo=self.userinfo,
            view=postinfo,  # Deprecated
            postinfo=postinfo,
            html_diff_arr=html_diff_arr)
Пример #14
0
 def test_get_last(self):
     self.add_w_h()
     aa = MWikiHist.get_last(self.wiki_uid)
     assert aa.uid == self.uid
     self.tearDown()
Пример #15
0
 def test_delete(self):
     MWikiHist.delete(self.userinfo['uid'])
     assert True
Пример #16
0
def run_edit_diff():
    email_cnt = '''<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <style type="text/css">
        table.diff {font-family:Courier; border:medium;}
        .diff_header {background-color:#e0e0e0}
        td.diff_header {text-align:right}
        .diff_next {background-color:#c0c0c0}
        .diff_add {background-color:#aaffaa}
        .diff_chg {background-color:#ffff77}
        .diff_sub {background-color:#ffaaaa}
    </style></head><body>'''

    idx = 1

    email_cnt = email_cnt + '<table border=1>'

    mpost = MPost()
    mposthist = MPostHist()

    for key in router_post.keys():
        recent_posts = mpost.query_recent_edited(tools.timestamp() -
                                                 time_limit,
                                                 kind=key)
        for recent_post in recent_posts:
            hist_rec = mposthist.get_last(recent_post.uid)
            if hist_rec:
                foo_str = '''
                    <tr><td>{0}</td><td>{1}</td><td class="diff_chg">Edit</td><td>{2}</td>
                    <td><a href="{3}">{3}</a></td></tr>
                    '''.format(
                    idx, recent_post.user_name, recent_post.title,
                    os.path.join(site_url, router_post[key], recent_post.uid))
                email_cnt = email_cnt + foo_str
            else:
                foo_str = '''
                    <tr><td>{0}</td><td>{1}</td><td class="diff_add">New </td><td>{2}</td>
                    <td><a href="{3}">{3}</a></td></tr>
                    '''.format(
                    idx, recent_post.user_name, recent_post.title,
                    os.path.join(site_url, router_post[key], recent_post.uid))
                email_cnt = email_cnt + foo_str
            idx = idx + 1

    ## wiki
    mpost = MWiki()
    mposthist = MWikiHist()

    recent_posts = mpost.query_recent_edited(tools.timestamp() - time_limit)
    for recent_post in recent_posts:
        hist_rec = mposthist.get_last(recent_post.uid)
        if hist_rec:
            foo_str = '''
                    <tr><td>{0}</td><td>{1}</td><td class="diff_chg">Edit</td><td>{2}</td>
                    <td><a href="{3}">{3}</a></td></tr>
                    '''.format(
                idx, recent_post.user_name, recent_post.title,
                os.path.join(site_url, 'wiki', recent_post.title))
            email_cnt = email_cnt + foo_str
        else:
            foo_str = '''
                    <tr><td>{0}</td><td>{1}</td><td class="diff_add">New </td><td>{2}</td>
                    <td><a href="{3}">{3}</a></td></tr>
                    '''.format(
                idx, recent_post.user_name, recent_post.title,
                os.path.join(site_url, 'wiki', recent_post.title))
            email_cnt = email_cnt + foo_str
        idx = idx + 1

    ## page.
    recent_posts = mpost.query_recent_edited(tools.timestamp() - time_limit,
                                             kind='2')
    for recent_post in recent_posts:
        hist_rec = mposthist.get_last(recent_post.uid)
        if hist_rec:
            foo_str = '''
                    <tr><td>{0}</td><td>{1}</td><td class="diff_chg">Edit</td><td>{2}</td>
                    <td><a href="{3}">{3}</a></td></tr>
                    '''.format(idx, recent_post.user_name, recent_post.title,
                               os.path.join(site_url, 'page', recent_post.uid))
            email_cnt = email_cnt + foo_str
        else:
            foo_str = '''
                    <tr><td>{0}</td><td>{1}</td><td class="diff_add">New </td><td>{2}</td>
                    <td><a href="{3}">{3}</a></td></tr>
                    '''.format(idx, recent_post.user_name, recent_post.title,
                               os.path.join(site_url, 'page', recent_post.uid))
            email_cnt = email_cnt + foo_str
        idx = idx + 1

    email_cnt = email_cnt + '</table>'

    mpost = MPost()
    mposthist = MPostHist()
    diff_str = ''
    ######################################################

    ######################################################

    for key in router_post.keys():
        recent_posts = mpost.query_recent_edited(tools.timestamp() -
                                                 time_limit,
                                                 kind=key)
        for recent_post in recent_posts:
            hist_rec = mposthist.get_last(recent_post.uid)
            if hist_rec:
                print('=' * 10)

                print(recent_post.title)

                raw_title = hist_rec.title
                new_title = recent_post.title

                infobox = diff_table(raw_title, new_title)
                # infobox = test[start:end] + '</table>'
                # if ('diff_add' in infobox) or ('diff_chg' in infobox) or ('diff_sub' in infobox):
                diff_str = diff_str + '<h2 style="color:red; font-size:larger; font-weight:70;">TITLE: {0}</h2>'.format(
                    recent_post.title) + infobox

                infobox = diff_table(hist_rec.cnt_md, recent_post.cnt_md)

                diff_str = diff_str + '<h3>CONTENT</h3>'.format(
                    recent_post.title) + infobox + '</hr>'
            else:
                continue
    ###########################################################
    if len(diff_str) < 20000:
        email_cnt = email_cnt + diff_str
    email_cnt = email_cnt + '''</body></html>'''

    # print (email_cnt)
    print('edit diff count:', idx)
    if idx > 1:
        send_mail(post_emails, "{0}|{1}|{2}".format(smtp_cfg['name'], '文档更新情况',
                                                    datestr), email_cnt)
Пример #17
0
 def initialize(self):
     self.init()
     self.mpost = MWiki()
     self.mposthist = MWikiHist()
Пример #18
0
 def test_get_by_uid(self):
     MWikiHist.get_by_uid(self.userinfo['uid'])
     assert True
Пример #19
0
 def initialize(self):
     self.init()
     self.mwiki = MWiki()
     self.mwiki_hist = MWikiHist()
Пример #20
0
 def test_query_by_wikiid(self):
     MWikiHist.query_by_wikiid(self.userinfo['uid'])
     assert True
Пример #21
0
 def test_get_by_uid(self):
     self.add_w_h()
     aa = MWikiHist.get_by_uid(self.uid)
     assert aa.user_name == self.username
Пример #22
0
def run_edit_diff(*args):
    email_cnt = '''<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <style type="text/css">
        table.diff {font-family:Courier; border:medium;}
        .diff_header {background-color:#e0e0e0}
        td.diff_header {text-align:right}
        .diff_next {background-color:#c0c0c0}
        .diff_add {background-color:#aaffaa}
        .diff_chg {background-color:#ffff77}
        .diff_sub {background-color:#ffaaaa}
    </style></head><body>'''

    idx = 1

    email_cnt = email_cnt + '<table border=1>'

    mpost = MPost()
    mposthist = MPostHist()

    for key in router_post.keys():
        recent_posts = mpost.query_recent_edited(tools.timestamp() -
                                                 time_limit,
                                                 kind=key)
        for recent_post in recent_posts:
            hist_rec = mposthist.get_last(recent_post.uid)
            if hist_rec:
                foo_str = '''
                    <tr><td>{0}</td><td>{1}</td><td class="diff_chg">Edit</td><td>{2}</td>
                    <td><a href="{3}">{3}</a></td></tr>
                    '''.format(
                    idx, recent_post.user_name, recent_post.title,
                    os.path.join(SITE_CFG['site_url'], router_post[key],
                                 recent_post.uid))
                email_cnt = email_cnt + foo_str
            else:
                foo_str = '''
                    <tr><td>{0}</td><td>{1}</td><td class="diff_add">New </td><td>{2}</td>
                    <td><a href="{3}">{3}</a></td></tr>
                    '''.format(
                    idx, recent_post.user_name, recent_post.title,
                    os.path.join(SITE_CFG['site_url'], router_post[key],
                                 recent_post.uid))
                email_cnt = email_cnt + foo_str
            idx = idx + 1

    ## wiki
    mpost = MWiki()
    mposthist = MWikiHist()

    recent_posts = mpost.query_recent_edited(tools.timestamp() - time_limit)
    for recent_post in recent_posts:
        hist_rec = mposthist.get_last(recent_post.uid)
        if hist_rec:
            foo_str = '''
                    <tr><td>{0}</td><td>{1}</td><td class="diff_chg">Edit</td><td>{2}</td>
                    <td><a href="{3}">{3}</a></td></tr>
                    '''.format(
                idx, recent_post.user_name, recent_post.title,
                os.path.join(SITE_CFG['site_url'], 'wiki', recent_post.title))
            email_cnt = email_cnt + foo_str
        else:
            foo_str = '''
                    <tr><td>{0}</td><td>{1}</td><td class="diff_add">New </td><td>{2}</td>
                    <td><a href="{3}">{3}</a></td></tr>
                    '''.format(
                idx, recent_post.user_name, recent_post.title,
                os.path.join(SITE_CFG['site_url'], 'wiki', recent_post.title))
            email_cnt = email_cnt + foo_str
        idx = idx + 1

    ## page.
    recent_posts = mpost.query_recent_edited(tools.timestamp() - time_limit,
                                             kind='2')
    for recent_post in recent_posts:
        hist_rec = mposthist.get_last(recent_post.uid)
        if hist_rec:
            foo_str = '''
                    <tr><td>{0}</td><td>{1}</td><td class="diff_chg">Edit</td><td>{2}</td>
                    <td><a href="{3}">{3}</a></td></tr>
                    '''.format(
                idx, recent_post.user_name, recent_post.title,
                os.path.join(SITE_CFG['site_url'], 'page', recent_post.uid))
            email_cnt = email_cnt + foo_str
        else:
            foo_str = '''
                    <tr><td>{0}</td><td>{1}</td><td class="diff_add">New </td><td>{2}</td>
                    <td><a href="{3}">{3}</a></td></tr>
                    '''.format(
                idx, recent_post.user_name, recent_post.title,
                os.path.join(SITE_CFG['site_url'], 'page', recent_post.uid))
            email_cnt = email_cnt + foo_str
        idx = idx + 1

    email_cnt = email_cnt + '</table>'

    ###########################################################

    diff_str = get_diff_str()

    if len(diff_str) < 20000:
        email_cnt = email_cnt + diff_str
    email_cnt = email_cnt + '''</body></html>'''

    if idx > 1:
        send_mail(post_emails, "{0}|{1}|{2}".format(SMTP_CFG['name'], '文档更新情况',
                                                    datestr), email_cnt)
Пример #23
0
 def tearDown(self):
     print("function teardown")
     MUser.delete(self.user_uid)
     MWiki.delete(self.wiki_uid)
     MWikiHist.delete(self.uid)
Пример #24
0
 def test_update_cnt(self):
     post_data = {'user_name': 'giser', 'cnt_md': 'asdf'}
     MWikiHist.update_cnt(self.userinfo['uid'], post_data)
     assert True
Пример #25
0
 def test_delete(self):
     self.add_w_h()
     assert self.uid != ''
     aa = MWikiHist.delete(self.uid)
     assert aa
     self.tearDown()
Пример #26
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))
Пример #27
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])))
Пример #28
0
 def initialize(self):
     self.init()
     self.mpost = MWiki()
     self.mposthist = MWikiHist()
     self.tmpl_dir = 'wiki_man'
Пример #29
0
def Test():
    assert MWikiHist()
Пример #30
0
def run_edit_diff():
    email_cnt = '''<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <style type="text/css">
        table.diff {font-family:Courier; border:medium;}
        .diff_header {background-color:#e0e0e0}
        td.diff_header {text-align:right}
        .diff_next {background-color:#c0c0c0}
        .diff_add {background-color:#aaffaa}
        .diff_chg {background-color:#ffff77}
        .diff_sub {background-color:#ffaaaa}
    </style></head><body>'''

    idx = 1

    email_cnt = email_cnt + '<table border=1>'

    mpost = MPost()
    mposthist = MPostHist()

    recent_posts = mpost.query_recent_edited(tools.timestamp() - 24 * 60 * 60)
    for recent_post in recent_posts:
        hist_rec = mposthist.get_last(recent_post.uid)
        if hist_rec:
            foo_str = '''
                <tr><td>{0}</td><td>{1}</td><td class="diff_chg">Edit</td><td>{2}</td>
                <td><a href="{3}">{3}</a></td></tr>
                '''.format(
                idx, recent_post.user_name, recent_post.title,
                os.path.join(site_url, 'post', recent_post.uid + '.html'))
            email_cnt = email_cnt + foo_str
        else:
            foo_str = '''
                <tr><td>{0}</td><td>{1}</td><td class="diff_add">New </td><td>{2}</td>
                <td><a href="{3}">{3}</a></td></tr>
                '''.format(
                idx, recent_post.user_name, recent_post.title,
                os.path.join(site_url, 'post', recent_post.uid + '.html'))
            email_cnt = email_cnt + foo_str
        idx = idx + 1

    recent_posts = mpost.query_recent_edited(tools.timestamp() - 24 * 60 * 60,
                                             kind='2')
    for recent_post in recent_posts:
        hist_rec = mposthist.get_last(recent_post.uid)
        if hist_rec:
            foo_str = '''
                <tr><td>{0}</td><td>{1}</td><td class="diff_chg">Edit</td><td>{2}</td>
                <td><a href="{3}">{3}</a></td></tr>
                '''.format(
                idx, recent_post.user_name, recent_post.title,
                os.path.join(site_url, router_post['2'], recent_post.uid))
            email_cnt = email_cnt + foo_str
        else:
            foo_str = '''
                <tr><td>{0}</td><td>{1}</td><td class="diff_add">New </td><td>{2}</td>
                <td><a href="{3}">{3}</a></td></tr>
                '''.format(
                idx, recent_post.user_name, recent_post.title,
                os.path.join(site_url, router_post['2'], recent_post.uid))
            email_cnt = email_cnt + foo_str
        idx = idx + 1

    mpost = MWiki()
    mposthist = MWikiHist()

    recent_posts = mpost.query_recent_edited(tools.timestamp() - 24 * 60 * 60)
    for recent_post in recent_posts:
        hist_rec = mposthist.get_last(recent_post.uid)
        if hist_rec:
            foo_str = '''
                    <tr><td>{0}</td><td>{1}</td><td class="diff_chg">Edit</td><td>{2}</td>
                    <td><a href="{3}">{3}</a></td></tr>
                    '''.format(
                idx, recent_post.user_name, recent_post.title,
                os.path.join(site_url, 'wiki', recent_post.title))
            email_cnt = email_cnt + foo_str
        else:
            foo_str = '''
                    <tr><td>{0}</td><td>{1}</td><td class="diff_add">New </td><td>{2}</td>
                    <td><a href="{3}">{3}</a></td></tr>
                    '''.format(
                idx, recent_post.user_name, recent_post.title,
                os.path.join(site_url, 'wiki', recent_post.title))
            email_cnt = email_cnt + foo_str
        idx = idx + 1

    recent_posts = mpost.query_recent_edited(tools.timestamp() - 24 * 60 * 60,
                                             kind='2')
    for recent_post in recent_posts:
        hist_rec = mposthist.get_last(recent_post.uid)
        if hist_rec:
            foo_str = '''
                    <tr><td>{0}</td><td>{1}</td><td class="diff_chg">Edit</td><td>{2}</td>
                    <td><a href="{3}">{3}</a></td></tr>
                    '''.format(
                idx, recent_post.user_name, recent_post.title,
                os.path.join(site_url, 'page', recent_post.uid + '.html'))
            email_cnt = email_cnt + foo_str
        else:
            foo_str = '''
                    <tr><td>{0}</td><td>{1}</td><td class="diff_add">New </td><td>{2}</td>
                    <td><a href="{3}">{3}</a></td></tr>
                    '''.format(
                idx, recent_post.user_name, recent_post.title,
                os.path.join(site_url, 'page', recent_post.uid + '.html'))
            email_cnt = email_cnt + foo_str
        idx = idx + 1

    email_cnt = email_cnt + '</table>'

    mpost = MPost()
    mposthist = MPostHist()
    diff_str = ''
    ######################################################
    recent_posts = mpost.query_recent_edited(tools.timestamp() - 24 * 60 * 60)
    for recent_post in recent_posts:
        hist_rec = mposthist.get_last(recent_post.uid)
        if hist_rec:
            print('=' * 10)
            print(recent_post.title)

            raw_title = hist_rec.title
            new_title = recent_post.title

            infobox = diff_table(raw_title, new_title)

            # if len(test) > 1:
            # start = test.find('<table class="diff"')  # 起点记录查询位置
            # end = test.find('</table>')
            # infobox = test[start:end] + '</table>'
            # if ('diff_add' in infobox) or ('diff_chg' in infobox) or ('diff_sub' in infobox):
            diff_str = diff_str + '<h2 style="color:red; font-size:larger; font-weight:70;">TITLE: {0}</h2>'.format(
                recent_post.title) + infobox

            test = diff_table(hist_rec.cnt_md, recent_post.cnt_md)
            print(test)
            # if len(test) >1 :
            # start = test.find('<table class="diff"')  # 起点记录查询位置
            # end = test.find('</table>')

            # infobox = test[start:end] + '</table>'
            # if ('diff_add' in infobox) or ('diff_chg' in infobox) or ('diff_sub' in infobox):
            diff_str = diff_str + '<h3>CONTENT</h3>'.format(
                recent_post.title) + test + '</hr>'
        else:
            continue
    ######################################################
    recent_posts = mpost.query_recent_edited(tools.timestamp() - 24 * 60 * 60,
                                             kind='2')
    for recent_post in recent_posts:
        hist_rec = mposthist.get_last(recent_post.uid)
        if hist_rec:
            print('=' * 10)

            print(recent_post.title)

            raw_title = hist_rec.title
            new_title = recent_post.title

            infobox = diff_table(raw_title, new_title)
            # infobox = test[start:end] + '</table>'
            # if ('diff_add' in infobox) or ('diff_chg' in infobox) or ('diff_sub' in infobox):
            diff_str = diff_str + '<h2 style="color:red; font-size:larger; font-weight:70;">TITLE: {0}</h2>'.format(
                recent_post.title) + infobox

            infobox = diff_table(hist_rec.cnt_md, recent_post.cnt_md)

            diff_str = diff_str + '<h3>CONTENT</h3>'.format(
                recent_post.title) + infobox + '</hr>'
        else:
            continue
    ###########################################################
    if len(diff_str) < 20000:
        email_cnt = email_cnt + diff_str
    email_cnt = email_cnt + '''<table class="diff" summary="Legends">
        <tr> <th colspan="2"> Legends </th> </tr>
        <tr> <td> <table border="" summary="Colors">
                      <tr><th> Colors </th> </tr>
                      <tr><td class="diff_add">&nbsp;Added&nbsp;</td></tr>
                      <tr><td class="diff_chg">Changed</td> </tr>
                      <tr><td class="diff_sub">Deleted</td> </tr>
                  </table></td>
             <td> <table border="" summary="Links">
                      <tr><th colspan="2"> Links </th> </tr>
                      <tr><td>(f)irst change</td> </tr>
                      <tr><td>(n)ext change</td> </tr>
                      <tr><td>(t)op</td> </tr>
                  </table></td> </tr>
    </table></body>'''

    # print (email_cnt)
    print('edit diff count:', idx)
    if idx > 1:
        send_mail(post_emails, "{0}|{1}|{2}".format(smtp_cfg['name'], '文档更新情况',
                                                    datestr), email_cnt)