コード例 #1
0
ファイル: wiki_handler.py プロジェクト: net4nt/TorCMS
class WikiHandler(BaseHandler):
    def initialize(self):
        self.init()
        self.muser = MUser()
        self.mwiki = MWiki()
        self.mcat = MCatalog()
        self.cats = self.mcat.query_all()
        self.mspec = SpesubModel()
        self.specs = self.mspec.get_all()
        self.mwiki_hist = MWikiHist()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None

    def get(self, url_str=''):
        if url_str == '':
            return
        url_arr = url_str.split(r'/')

        if url_str == 'recent':
            self.recent()
        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, input=''):
        if input == '':
            return
        url_arr = input.split(r'/')
        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('{0}/wiki/wiki_list.html'.format(self.tmpl_name),
                    kwd=kwd,
                    view=self.mwiki.query_recent(),
                    format_date=tools.format_date, )

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

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

    @tornado.web.authenticated
    def to_add(self, title):
        kwd = {
            'cats': self.cats,
            'specs': self.specs,
            'title': title,
            'pager': '',
        }
        self.render('{0}/wiki/wiki_add.html'.format(self.tmpl_name), kwd=kwd, )

    @tornado.web.authenticated
    def update(self, uid):
        raw_data = self.mwiki.get_by_id(uid)
        if self.userinfo.privilege[2] == '1' 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.userinfo.privilege[2] == '1' or wiki_rec.user_name == self.get_current_user():
            pass
        else:
            return False

        kwd = {
            'pager': '',
            'cats': self.cats,
            'specs': self.specs,
        }
        self.render('{0}/wiki/wiki_edit.html'.format(self.tmpl_name),
                    kwd=kwd,
                    unescape=tornado.escape.xhtml_unescape,
                    tag_infos=self.mcat.query_all(),
                    dbrec=wiki_rec,
                    )

    def viewit(self, view):
        kwd = {
            'pager': '',
            'editable': self.editable(),
        }

        self.render('{0}/wiki/wiki_view.html'.format(self.tmpl_name),
                    view=view,
                    unescape=tornado.escape.xhtml_unescape,
                    kwd=kwd,
                    userinfo=self.userinfo, )

    @tornado.web.authenticated
    def wikinsert(self):
        if self.userinfo.privilege[1] == '1':
            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()
        tt = self.mwiki.get_by_wiki(post_data['title'][0])
        if tt is None:
            self.mwiki.insert_data(post_data)

        self.redirect('/wiki/{0}'.format(tornado.escape.url_escape(post_data['title'][0])))
コード例 #2
0
class WikiHandler(BaseHandler):
    def initialize(self):
        self.init()
        self.mwiki = MWiki()
        self.mcat = MCatalog()
        self.cats = self.mcat.query_all()
        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(
            '{0}/wiki/wiki_list.html'.format(self.tmpl_name),
            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(
            '{0}/wiki/wiki_list.html'.format(self.tmpl_name),
            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):
        kwd = {
            'cats': self.cats,
            'title': title,
            'pager': '',
        }
        self.render(
            '{0}/wiki/wiki_add.html'.format(self.tmpl_name),
            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.userinfo.privilege[
                2] == '1' 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.userinfo.privilege[
                2] == '1' or wiki_rec.user_name == self.get_current_user():
            pass
        else:
            return False

        kwd = {
            'pager': '',
            'cats': self.cats,
        }
        self.render(
            '{0}/wiki/wiki_edit.html'.format(self.tmpl_name),
            kwd=kwd,
            unescape=tornado.escape.xhtml_unescape,
            tag_infos=self.mcat.query_all(),
            dbrec=wiki_rec,
            cfg=config.cfg,
            userinfo=self.userinfo,
        )

    def viewit(self, view):
        kwd = {
            'pager': '',
            'editable': self.editable(),
        }

        self.render(
            '{0}/wiki/wiki_view.html'.format(self.tmpl_name),
            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.userinfo.privilege[1] == '1':
            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()
        tt = self.mwiki.get_by_wiki(post_data['title'][0])
        if tt is None:
            self.mwiki.insert_data(post_data)

        self.redirect('/wiki/{0}'.format(
            tornado.escape.url_escape(post_data['title'][0])))
コード例 #3
0
ファイル: wiki_handler.py プロジェクト: ifcheung2012/TorCMS
class WikiHandler(BaseHandler):
    def initialize(self):
        self.muser = MUser()
        self.mwiki = MWiki()
        self.mcat = MCatalog()
        self.cats = self.mcat.query_all()
        self.mspec = SpesubModel()
        self.specs = self.mspec.get_all()
        self.mwiki_hist = MWikiHist()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None

    def get(self, url_str=''):
        if url_str == '':
            return
        url_arr = url_str.split(r'/')

        if url_str == 'find':
            self.to_find()
        # elif url_arr[0] == 'find':
        # self.find(url_arr[1])
        elif url_str == 'recent':
            self.recent()
        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, input=''):
        if input == '':
            return
        url_arr = input.split(r'/')
        if url_arr[0] == 'edit':
            self.update(url_arr[1])
        elif url_arr[0] == 'add':
            self.wikinsert()
        else:
            self.redirect('static/404.html')

    def to_find(self, ):
        kwd = {
            'pager': '',
        }
        self.render('tplite/post/find.html', topmenu='', kwd=kwd)

    def recent(self):
        kwd = {
            'pager': '',
            'unescape': tornado.escape.xhtml_unescape,
            'title': '最近文档',
        }
        self.render(
            'tplite/wiki/all.html'.format(input),
            kwd=kwd,
            view=self.mwiki.query_recent(),
            format_date=tools.format_date,
        )

    def refresh(self):
        kwd = {
            'pager': '',
            'unescape': tornado.escape.xhtml_unescape,
            'title': '最近文档',
        }
        self.render(
            'tplite/wiki/all.html'.format(input),
            kwd=kwd,
            view=self.mwiki.query_dated(16),
            format_date=tools.format_date,
        )

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

    @tornado.web.authenticated
    def to_add(self, title):
        kwd = {
            'cats': self.cats,
            'specs': self.specs,
            'title': title,
            'pager': '',
        }
        self.render(
            'tplite/wiki/addwiki.html',
            kwd=kwd,
        )

    @tornado.web.authenticated
    def update(self, uid):
        raw_data = self.mwiki.get_by_id(uid)
        if self.userinfo.privilege[
                2] == '1' 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):
        a = self.mwiki.get_by_id(id_rec)
        # 用户具有管理权限,
        # 或
        # 文章是用户自己发布的。
        if self.userinfo.privilege[
                2] == '1' or a.user_name == self.get_current_user():
            pass
        else:
            return False

        kwd = {
            'pager': '',
            'cats': self.cats,
            'specs': self.specs,
        }
        self.render(
            'tplite/wiki/modify.html',
            kwd=kwd,
            unescape=tornado.escape.xhtml_unescape,
            tag_infos=self.mcat.query_all(),
            dbrec=a,
        )

    def viewit(self, view):
        # cats = self.mpost2catalog.query_catalog(post_id)
        kwd = {
            'pager': '',
            'editable': self.editable(),
        }

        self.render(
            'tplite/wiki/viewiki.html',
            view=view,
            unescape=tornado.escape.xhtml_unescape,
            kwd=kwd,
            userinfo=self.userinfo,
        )

    @tornado.web.authenticated
    def wikinsert(self):
        if self.userinfo.privilege[1] == '1':
            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()
        tt = self.mwiki.get_by_wiki(post_data['title'][0])
        if tt is None:
            uid = self.mwiki.insert_data(post_data)

        self.redirect('/wiki/{0}'.format(
            tornado.escape.url_escape(post_data['title'][0])))
コード例 #4
0
ファイル: wiki_handler.py プロジェクト: Geoion/TorCMS
class WikiHandler(BaseHandler):
    def initialize(self):
        self.muser = MUser()
        self.mwiki = MWiki()
        self.mcat = MCatalog()
        self.cats = self.mcat.query_all()
        self.mspec = SpesubModel()
        self.specs = self.mspec.get_all()
        self.mwiki_hist = MWikiHist()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None

    def get(self, url_str=""):
        if url_str == "":
            return
        url_arr = url_str.split(r"/")

        if url_str == "find":
            self.to_find()
        # elif url_arr[0] == 'find':
        # self.find(url_arr[1])
        elif url_str == "recent":
            self.recent()
        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, input=""):
        if input == "":
            return
        url_arr = input.split(r"/")
        if url_arr[0] == "edit":
            self.update(url_arr[1])
        elif url_arr[0] == "add":
            self.wikinsert()
        else:
            self.redirect("static/404.html")

    def to_find(self,):
        kwd = {"pager": ""}
        self.render("tplite/post/find.html", topmenu="", kwd=kwd)

    def recent(self):
        kwd = {"pager": "", "unescape": tornado.escape.xhtml_unescape, "title": "最近文档"}
        self.render(
            "tplite/wiki/all.html".format(input), kwd=kwd, view=self.mwiki.query_recent(), format_date=tools.format_date
        )

    def refresh(self):
        kwd = {"pager": "", "unescape": tornado.escape.xhtml_unescape, "title": "最近文档"}
        self.render(
            "tplite/wiki/all.html".format(input),
            kwd=kwd,
            view=self.mwiki.query_dated(16),
            format_date=tools.format_date,
        )

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

    @tornado.web.authenticated
    def to_add(self, title):
        kwd = {"cats": self.cats, "specs": self.specs, "title": title, "pager": ""}
        self.render("tplite/wiki/addwiki.html", kwd=kwd)

    @tornado.web.authenticated
    def update(self, uid):
        raw_data = self.mwiki.get_by_id(uid)
        if self.userinfo.privilege[2] == "1" 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.userinfo.privilege[2] == "1" or wiki_rec.user_name == self.get_current_user():
            pass
        else:
            return False

        kwd = {"pager": "", "cats": self.cats, "specs": self.specs}
        self.render(
            "tplite/wiki/modify.html",
            kwd=kwd,
            unescape=tornado.escape.xhtml_unescape,
            tag_infos=self.mcat.query_all(),
            dbrec=wiki_rec,
        )

    def viewit(self, view):
        # cats = self.mpost2catalog.query_catalog(post_id)
        kwd = {"pager": "", "editable": self.editable()}

        self.render(
            "tplite/wiki/viewiki.html",
            view=view,
            unescape=tornado.escape.xhtml_unescape,
            kwd=kwd,
            userinfo=self.userinfo,
        )

    @tornado.web.authenticated
    def wikinsert(self):
        if self.userinfo.privilege[1] == "1":
            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()
        tt = self.mwiki.get_by_wiki(post_data["title"][0])
        if tt is None:
            uid = self.mwiki.insert_data(post_data)

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