示例#1
0
class MaintainCategoryHandler(BaseHandler):
    def initialize(self):
        self.init()
        self.mclass = MCatalog()
        self.tmpl_router = 'maintain_category'


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

        if url_str == 'add':
            self.to_add()
        elif url_str == 'list':
            self.list_catalog()
        elif url_arr[0] == 'modify':
            self.to_modify(url_arr[1])

        elif url_arr[0] == 'delete':

            self.delete_by_uid(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] == 'modify':
            self.update(url_arr[1])
        elif url_str == 'add':
            self.add_catalog()
        elif url_arr[0] == 'add':

            self.p_add_catalog()
        else:
            self.redirect('html/404.html')

    def list_catalog(self):
        kwd = {
            'pager': '',
            'unescape': tornado.escape.xhtml_unescape,
            'title': '最近文档',
        }
        self.render('{0}/{1}/category_list.html'.format(self.tmpl_name, self.tmpl_router),
                    kwd=kwd,
                    view=self.mclass.query_all(by_order=True),
                    format_date=tools.format_date,
                    userinfo=self.userinfo,
                    cfg=config.cfg
                    )

    @tornado.web.authenticated
    def to_add(self):
        kwd = {
            'pager': '',
            'uid': '',
        }
        self.render('{0}/{1}/category_add.html'.format(self.tmpl_name, self.tmpl_router),
                    topmenu='',
                    kwd=kwd,
                    userinfo=self.userinfo,
                    cfg=config.cfg
                    )

    @tornado.web.authenticated
    def update(self, uid):
        raw_data = self.mclass.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()

        if self.tmpl_router == "maintain_category":
            self.mclass.update(uid, post_data)
            self.redirect('/maintain/category/list'.format(uid))
        else:
            if self.mclass.update(uid, post_data):

                output = {
                    'addinfo ': 1,
                }
            else:
                output = {
                    'addinfo ': 0,
                }
            return json.dump(output, self)

    @tornado.web.authenticated
    def to_modify(self, id_rec):
        a = self.mclass.get_by_id(id_rec)
        if self.userinfo.privilege[4] == '1':
            pass
        else:
            return False

        kwd = {
            'pager': '',

        }
        self.render('{0}/{1}/category_edit.html'.format(self.tmpl_name, self.tmpl_router),
                    kwd=kwd,
                    unescape=tornado.escape.xhtml_unescape,
                    dbrec=a,
                    userinfo=self.userinfo,
                    cfg=config.cfg,
                    )

    @tornado.web.authenticated
    def add_post(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()
        id_post = post_data['uid'][0]
        cur_post_rec = self.mclass.get_by_id(id_post)
        if cur_post_rec is None:
            uid = self.mclass.insert_data(id_post, post_data)

        self.redirect('/maintain/category/list'.format(id_post))

    @tornado.web.authenticated
    def p_add_catalog(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()

        cur_uid = tools.get_uudd(2)
        while self.mclass.get_by_id(cur_uid):
            cur_uid = tools.get_uudd(2)

        if self.mclass.insert_data(post_data['uid'], post_data):

            output = {
                'addinfo ': 1,
            }
        else:
            output = {
                'addinfo ': 0,
            }
        return json.dump(output, self)

    @tornado.web.authenticated
    def add_catalog(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()

        cur_uid = tools.get_uudd(2)
        while self.mclass.get_by_id(cur_uid):
            cur_uid = tools.get_uudd(2)

        uid = self.mclass.insert_data(cur_uid, post_data)

        self.redirect('/maintain/category/list'.format(cur_uid))

    @tornado.web.authenticated
    def delete_by_uid(self, del_id):
        if self.tmpl_router == "maintain_category":
            is_deleted = self.mclass.delete(del_id)

            if is_deleted:
                self.redirect('/maintain/category/list')
            else:
                return False
        else:
            if self.mclass.delete(del_id):
                output = {
                    'del_category': 1
                }
            else:
                output = {
                    'del_category': 0,
                }

            return json.dump(output, self)
示例#2
0
class MaintainCategoryHandler(BaseHandler):
    def initialize(self):
        self.init()
        self.mclass = MCatalog()
        self.tmpl_router = 'maintain_category'

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

        if url_str == 'add':
            self.to_add()
        elif url_str == 'list':
            self.list_catalog()
        elif url_arr[0] == 'modify':
            self.to_modify(url_arr[1])

        elif url_arr[0] == 'delete':

            self.delete_by_uid(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)
        print(url_str)
        if url_arr[0] == 'modify':
            self.update(url_arr[1])
        elif url_str == 'add':
            self.p_add_catalog()
        elif url_arr[0] == 'add':

            self.p_add_catalog()
        else:
            self.redirect('html/404.html')

    def list_catalog(self):
        kwd = {
            'pager': '',
            'unescape': tornado.escape.xhtml_unescape,
            'title': '最近文档',
        }
        self.render('doc/{0}/category_list.html'.format(self.tmpl_router),
                    kwd=kwd,
                    view=self.mclass.query_all(by_order=True),
                    format_date=tools.format_date,
                    userinfo=self.userinfo,
                    cfg=config.cfg)

    @tornado.web.authenticated
    def to_add(self):
        if self.check_doc_priv(self.userinfo)['ADD']:
            pass
        else:
            return False
        kwd = {
            'pager': '',
            'uid': '',
        }
        self.render('doc/{0}/category_add.html'.format(self.tmpl_router),
                    topmenu='',
                    kwd=kwd,
                    userinfo=self.userinfo,
                    cfg=config.cfg)

    def __could_edit(self, uid):
        raw_data = self.mclass.get_by_id(uid)
        if not raw_data:

            return False
        if self.check_doc_priv(
                self.userinfo
        )['EDIT'] or raw_data.id_user == self.userinfo.user_name:
            return True
        else:
            return False

    @tornado.web.authenticated
    def update(self, uid):
        if self.__could_edit(uid):
            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.tmpl_router == "maintain_category":
            self.mclass.update(uid, post_data)
            self.redirect('/maintain/category/list'.format(uid))
        else:
            if self.mclass.update(uid, post_data):

                output = {
                    'addinfo ': 1,
                }
            else:
                output = {
                    'addinfo ': 0,
                }
            return json.dump(output, self)

    @tornado.web.authenticated
    def to_modify(self, id_rec):
        if self.__could_edit(id_rec):
            pass
        else:
            return False
        a = self.mclass.get_by_id(id_rec)
        kwd = {
            'pager': '',
        }
        self.render(
            'doc/{0}/category_edit.html'.format(self.tmpl_router),
            kwd=kwd,
            unescape=tornado.escape.xhtml_unescape,
            dbrec=a,
            userinfo=self.userinfo,
            cfg=config.cfg,
        )

    @tornado.web.authenticated
    def add_post(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()
        id_post = post_data['uid'][0]
        cur_post_rec = self.mclass.get_by_id(id_post)
        if cur_post_rec is None:
            uid = self.mclass.insert_data(id_post, post_data)

        self.redirect('/maintain/category/list'.format(id_post))

    @tornado.web.authenticated
    def p_add_catalog(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()

        cur_uid = tools.get_uudd(2)
        while self.mclass.get_by_id(cur_uid):
            cur_uid = tools.get_uudd(2)

        if self.mclass.insert_data(post_data['uid'][0], post_data):

            output = {
                'addinfo ': 1,
            }
        else:
            output = {
                'addinfo ': 0,
            }
        return json.dump(output, self)

    @tornado.web.authenticated
    def add_catalog(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()

        cur_uid = tools.get_uudd(2)
        while self.mclass.get_by_id(cur_uid):
            cur_uid = tools.get_uudd(2)

        uid = self.mclass.insert_data(cur_uid, post_data)

        self.redirect('/maintain/category/list'.format(cur_uid))

    @tornado.web.authenticated
    def delete_by_uid(self, del_id):
        if self.check_doc_priv(self.userinfo)['DELETE']:
            pass
        else:
            return False
        if self.tmpl_router == "maintain_category":
            is_deleted = self.mclass.delete(del_id)

            if is_deleted:
                self.redirect('/maintain/category/list')
            else:
                return False
        else:
            if self.mclass.delete(del_id):
                output = {'del_category': 1}
            else:
                output = {
                    'del_category': 0,
                }

            return json.dump(output, self)
示例#3
0
for key in out_dic:

    if key.endswith('00'):
        uid = key[1:]
        print(uid)
        cur_dic = out_dic[key]
        porder = cur_dic['order']
        cat_dic = {
            'uid': uid,
            'slug': [cur_dic['slug']],
            'name': [cur_dic['name']],
            'count': [0],
            'order':[porder * 100],
        }

        mcat.insert_data(uid, cat_dic)
    else:
        sub_arr = out_dic[key]
        pid = key[1:3]

        for sub_dic in sub_arr:
            print('x' * 10)
            print(sub_dic)
            # cur_dic = sub_dic
            porder = out_dic['z' + pid + '00']['order']
        
            for key in sub_dic:
                
                uid = key[1:]