Esempio n. 1
0
 def render(self, limit):
     self.mcat = MInforCatalog()
     all_cats = self.mcat.query_field_count(limit)
     kwd = {
         'cats': all_cats,
     }
     return self.render_string('infor/modules/app_menu.html', kwd=kwd)
Esempio n. 2
0
 def initialize(self):
     self.init()
     self.mpost = MPost()
     self.mcat = MInforCatalog()
     # self.cats = self.mcat.query_all()
     # self.mpost2catalog = MPost2Catalog()
     self.ysearch = yunsearch()
Esempio n. 3
0
 def render(self):
     self.mcat = MInforCatalog()
     parentlist = self.mcat.get_parent_list()
     kwd = {
         'parentlist': parentlist,
         'parentid': self.parentid,
     }
     return self.render_string('infor/modules/banner.html', kwd=kwd)
Esempio n. 4
0
 def initialize(self, hinfo=''):
     self.init()
     self.mevaluation = MEvaluation()
     self.mapp2catalog = MApp2Catalog()
     self.mapp2tag = MApp2Label()
     self.minfo = MApp()
     self.musage = MUsage()
     self.mcat = MInforCatalog()
     self.mrel = MAppRel()
     self.mreply = MApp2Reply()
Esempio n. 5
0
 def initialize(self):
     self.init()
     self.mappcat = MInforCatalog()
     self.mevaluation = MEvaluation()
     self.mapp2catalog = MApp2Catalog()
     self.mapp2tag = MApp2Label()
     self.mapp = MApp()
     self.musage = MUsage()
     self.mtag = MInforCatalog()
     self.mrel = MAppRel()
     self.mreply = MApp2Reply()
     if 'app_url_name' in cfg:
         self.app_url_name = cfg['app_url_name']
     else:
         self.app_url_name = 'info'
Esempio n. 6
0
 def initialize(self):
     self.init()
     self.mappcat = MInforCatalog()
     self.mevaluation = MEvaluation()
     self.mapp2catalog = MApp2Catalog()
     self.mapp2tag = MApp2Label()
     self.mapp = MApp()
     self.musage = MUsage()
     self.mtag = MInforCatalog()
     self.mrel = MAppRel()
     self.mreply = MApp2Reply()
     if 'app_url_name' in cfg:
         self.app_url_name = cfg['app_url_name']
     else:
         self.app_url_name = 'info'
Esempio n. 7
0
 def render(self, limit):
     self.mcat = MInforCatalog()
     all_cats = self.mcat.query_field_count(limit)
     kwd = {
         'cats': all_cats,
     }
     return self.render_string('infor/modules/app_menu.html', kwd=kwd)
Esempio n. 8
0
 def initialize(self):
     self.init()
     self.muser = MUser()
     self.mclass = MPycateCatalog()
     if self.get_current_user():
         self.userinfo = self.muser.get_by_id(self.get_current_user())
     else:
         self.userinfo = None
Esempio n. 9
0
 def initialize(self):
     self.init()
     self.muser = MUser()
     self.mclass = MPycateCatalog()
     if self.get_current_user():
         self.userinfo = self.muser.get_by_id(self.get_current_user())
     else:
         self.userinfo = None
Esempio n. 10
0
 def render(self):
     self.mcat = MInforCatalog()
     parentlist = self.mcat.get_parent_list()
     kwd = {
         'parentlist': parentlist,
         'parentid': self.parentid,
     }
     return self.render_string('infor/modules/banner.html', kwd=kwd)
Esempio n. 11
0
 def initialize(self, hinfo=''):
     self.init()
     self.mevaluation = MEvaluation()
     self.mapp2catalog = MApp2Catalog()
     self.mapp2tag = MApp2Label()
     self.minfo = MApp()
     self.musage = MUsage()
     self.mcat = MInforCatalog()
     self.mrel = MAppRel()
     self.mreply = MApp2Reply()
Esempio n. 12
0
class BannerModule(tornado.web.UIModule):
    def __init__(self, parentid=''):
        self.parentid = parentid

    def render(self):
        self.mcat = MInforCatalog()
        parentlist = self.mcat.get_parent_list()
        kwd = {
            'parentlist': parentlist,
            'parentid': self.parentid,
        }
        return self.render_string('infor/modules/banner.html', kwd=kwd)
Esempio n. 13
0
class BannerModule(tornado.web.UIModule):
    def __init__(self, parentid=''):
        self.parentid = parentid

    def render(self):
        self.mcat = MInforCatalog()
        parentlist = self.mcat.get_parent_list()
        kwd = {
            'parentlist': parentlist,
            'parentid': self.parentid,
        }
        return self.render_string('infor/modules/banner.html', kwd=kwd)
Esempio n. 14
0
 def initialize(self, hinfo=''):
     self.init()
     self.minforcatalog = MInforCatalog()
Esempio n. 15
0
class widget_search(tornado.web.UIModule):
    def render(self, ):
        self.mcat = MInforCatalog()

        return self.render_string('widget/widget_search.html',
                                  cat_enum=self.mcat.query_pcat())
Esempio n. 16
0
class MetaHandler(BaseHandler):
    def initialize(self):
        self.init()
        self.mappcat = MInforCatalog()
        self.mevaluation = MEvaluation()
        self.mapp2catalog = MApp2Catalog()
        self.mapp2tag = MApp2Label()
        self.mapp = MApp()
        self.musage = MUsage()
        self.mtag = MInforCatalog()
        self.mrel = MAppRel()
        self.mreply = MApp2Reply()
        if 'app_url_name' in cfg:
            self.app_url_name = cfg['app_url_name']
        else:
            self.app_url_name = 'info'

    def get(self, url_str=''):

        url_arr = self.parse_url(url_str)

        if url_arr[0] == 'cat_add':
            self.user_to_add(url_arr[1])
        elif url_arr[0] == 'catalog':
            self.catalog()
        elif len(url_arr) == 1 and len(url_str) == 4:
            self.redirect('/{0}/{1}'.format(self.app_url_name, url_arr[0]))
        elif len(url_arr) == 2:
            if url_arr[0] == 'edit':
                self.to_edit_app(url_arr[1])
            elif url_arr[0] == 'add':
                self.to_add_app(url_arr[1])
            elif url_arr[0] == 'delete':
                self.to_del_app(url_arr[1])


            else:
                '''
                从相关计算中过来的。
                '''
                self.mrel.update_relation(url_arr[1], url_arr[0])
                self.redirect('/{0}/{1}'.format(self.app_url_name, url_arr[0]))
        else:
            kwd = {
                'title': '',
                '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] == 'to_add':
            self.add()
        elif url_arr[0] == 'rel':
            if self.get_current_user():
                self.add_relation(url_arr[1])
            else:
                self.redirect('/user/login')
        elif url_arr[0] == 'comment_add':
            self.add_comment(url_arr[1])
        elif url_arr[0] == 'edit':
            self.update(url_arr[1])
        elif url_arr[0] == 'add':
            self.add(url_arr[1])
        else:
            return False

    def catalog(self):
        self.render('infor/app/catalog.html',
                    userinfo=self.userinfo,
                    kwd={'uid': '',}
                    )

    @tornado.web.authenticated
    def user_to_add(self, catid):

        uid = tools.get_uu4d()
        while self.mapp.get_by_uid(uid):
            uid = tools.get_uu4d()
        kwd = {
            'uid': uid,
            'userid': self.userinfo.user_name,
            'def_cat_uid': catid,
            'parentname': self.mtag.get_by_id(catid[:2] + '00').name,
            'catname': self.mtag.get_by_id(catid).name,
        }
        self.render('autogen/add/add_{0}.html'.format(catid),
                    userinfo=self.userinfo,
                    kwd=kwd)

    def check_priv(self, userinfo, cat_id):
        cat_rec = self.mappcat.get_by_uid(cat_id)
        priv_mask_idx = cat_rec.priv_mask.index('1')
        priv_dic = {'ADD': False, 'EDIT': False, 'DELETE': False, 'ADMIN': False}
        if userinfo.privilege[priv_mask_idx] >= '1':
            priv_dic['ADD'] = True
        if userinfo.privilege[priv_mask_idx] >= '2':
            priv_dic['EDIT'] = True
        if userinfo.privilege[priv_mask_idx] >= '4':
            priv_dic['DELETE'] = True
        if userinfo.privilege[priv_mask_idx] >= '8':
            priv_dic['ADMIN'] = True
        return priv_dic

    @tornado.web.authenticated
    def to_add_app(self, uid):
        if self.mapp.get_by_uid(uid):
            self.redirect('/{0}/edit/{1}'.format(self.app_url_name, uid))
        else:
            self.render('infor/app/add.html',
                        tag_infos=self.mtag.query_all(),
                        userinfo=self.userinfo,
                        kwd={'uid': uid,}
                        )

    @tornado.web.authenticated
    def to_del_app(self, uid):
        current_infor = self.mapp.get_by_uid(uid)
        if self.check_priv(self.userinfo, current_infor.extinfo['def_cat_uid'])['DELETE']:
            pass
        else:
            return False

        if self.mapp.delete(uid):
            self.redirect('/list/{0}'.format(current_infor.extinfo['def_cat_uid']))
        else:
            self.redirect('/info/{0}'.format(uid))

    @tornado.web.authenticated
    def to_edit_app(self, infoid):

        rec_info = self.mapp.get_by_uid(infoid)

        if rec_info:
            pass
        else:
            self.render('html/404.html')
            return
        if 'def_cat_uid' in rec_info.extinfo:
            catid = rec_info.extinfo['def_cat_uid']
        else:
            catid = ''

        kwd = {
            'def_cat_uid': catid,
            'parentname': self.mtag.get_by_id(catid[:2] + '00').name if catid != '' else '',
            'catname': self.mtag.get_by_id(catid).name if catid != '' else '',
            'parentlist': self.mtag.get_parent_list(),
            'userip': self.request.remote_ip
        }

        if catid:
            tmpl = 'autogen/edit/edit_{0}.html'.format(catid)
        else:
            tmpl = 'infor/app/edit.html'

        self.render(tmpl,
                    kwd=kwd,
                    calc_info=rec_info,
                    post_info=rec_info,
                    userinfo=self.userinfo,
                    app_info=rec_info,
                    unescape=tornado.escape.xhtml_unescape,
                    cat_enum=self.mappcat.get_qian2(catid[:2]),
                    tag_infos=self.mappcat.query_all(by_order=True),
                    app2tag_info=self.mapp2catalog.query_by_entry_uid(infoid),
                    app2label_info=self.mapp2tag.get_by_id(infoid), )

    @tornado.web.authenticated
    def update(self, uid):
        post_data = {}
        ext_dic = {}
        for key in self.request.arguments:
            if key.startswith('ext_') or key.startswith('tag_'):
                ext_dic[key] = self.get_argument(key)
            else:
                post_data[key] = self.get_arguments(key)

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

        current_info = self.mapp.get_by_uid(uid)

        if current_info.user_name == self.userinfo.user_name:
            pass
        elif self.userinfo.privilege[4] >= '1':
            pass
        elif 'def_cat_uid' in post_data and self.check_priv(self.userinfo, post_data['def_cat_uid'][0])['EDIT']:
            pass
        else:
            return False

        ext_dic['def_uid'] = str(uid)
        if 'def_cat_uid' in post_data:
            ext_dic['def_cat_uid'] = post_data['def_cat_uid'][0]
            ext_dic['def_cat_pid'] = '{0}00'.format(post_data['def_cat_uid'][0][:2])

        ext_dic['def_tag_arr'] = [x.strip() for x in post_data['tags'][0].strip().strip(',').split(',')]
        ext_dic = self.extra_data(ext_dic, post_data)
        self.mapp.modify_meta(uid,
                              post_data,
                              extinfo=ext_dic)
        self.update_catalog(uid)
        self.update_tag(uid)
        self.redirect('/{0}/{1}'.format(self.app_url_name, uid))

    @tornado.web.authenticated
    def add(self, uid=''):

        ext_dic = {}
        post_data = {}
        for key in self.request.arguments:
            if key.startswith('ext_') or key.startswith('tag_'):
                ext_dic[key] = self.get_argument(key)
            else:
                post_data[key] = self.get_arguments(key)

        if self.check_priv(self.userinfo, post_data['def_cat_uid'][0])['ADD']:
            pass
        else:
            return False

        if uid == '':
            uid = tools.get_uu4d()
            while self.mapp.get_by_uid(uid):
                uid = tools.get_uu4d()
            post_data['uid'][0] = uid

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

        ext_dic['def_uid'] = str(uid)
        if 'def_cat_uid' in post_data:
            ext_dic['def_cat_pid'] = '{0}00'.format(post_data['def_cat_uid'][0][:2])
            ext_dic['def_cat_uid'] = post_data['def_cat_uid'][0]

        ext_dic['def_tag_arr'] = [x.strip() for x in post_data['tags'][0].strip().strip(',').split(',')]
        ext_dic = self.extra_data(ext_dic, post_data)
        print(post_data)
        self.mapp.modify_meta(ext_dic['def_uid'],
                              post_data,
                              extinfo=ext_dic)
        self.update_catalog(ext_dic['def_uid'])
        self.update_tag(ext_dic['def_uid'])

        self.redirect('/list/{0}'.format(ext_dic['def_cat_uid']))

    @tornado.web.authenticated
    def extra_data(self, ext_dic, post_data):
        '''
        The additional information.
        :param post_data:
        :return: directory.
        '''
        return ext_dic

    @tornado.web.authenticated
    def update_tag(self, signature):

        post_data = {}
        for key in self.request.arguments:
            post_data[key] = self.get_arguments(key)
        current_tag_infos = self.mapp2tag.get_by_id(signature)
        tags_arr = [x.strip() for x in post_data['tags'][0].split(',')]
        for tag_name in tags_arr:
            if tag_name == '':
                pass
            else:
                self.mapp2tag.add_record(signature, tag_name, 1)

        for cur_info in current_tag_infos:
            if cur_info.tag.name in tags_arr:
                pass
            else:
                self.mapp2tag.remove_relation(signature, cur_info.tag)

    @tornado.web.authenticated
    def update_catalog(self, signature):
        post_data = {}
        for key in self.request.arguments:
            post_data[key] = self.get_arguments(key)
        current_catalog_infos = self.mapp2catalog.query_by_entry_uid(signature)

        new_tag_arr = []
        for idx, key in enumerate(['cat_1', 'cat_2', 'cat_3', 'cat_4', 'cat_5', 'def_cat_uid']):
            if key in post_data:
                vv = post_data[key][0]
                if vv == '':
                    pass
                else:
                    new_tag_arr.append(vv)
                    self.mapp2catalog.add_record(signature, vv, idx)
            else:
                pass

        for cur_info in current_catalog_infos:
            if str(cur_info.catalog.uid).strip() in new_tag_arr:
                pass
            else:
                self.mapp2catalog.remove_relation(signature, cur_info.catalog)

    @tornado.web.authenticated
    def add_comment(self, id_post):
        post_data = {}
        for key in self.request.arguments:
            post_data[key] = self.get_arguments(key)
        post_data['user_id'] = self.userinfo.uid
        post_data['user_name'] = self.userinfo.user_name
        comment_uid = self.mreply.insert_data(post_data, id_post)
        if comment_uid:
            output = {
                'pinglun': comment_uid,
            }
        else:
            output = {
                'pinglun': 0,
            }
        return json.dump(output, self)

    def add_relation(self, f_uid, t_uid):
        if False == self.mapp.get_by_uid(t_uid):
            return False
        if f_uid == t_uid:
            '''
            关联其本身
            '''
            return False
        self.mrel.add_relation(f_uid, t_uid, 2)
        self.mrel.add_relation(t_uid, f_uid, 1)
        return True
Esempio n. 17
0
class widget_search(tornado.web.UIModule):
    def render(self, ):
        self.mcat = MInforCatalog()

        return self.render_string('widget/widget_search.html', cat_enum = self.mcat.query_pcat())
Esempio n. 18
0
 def initialize(self, hinfo=''):
     self.init()
     self.template_dir_name = 'infor'
     self.minfo = MInfor()
     self.mcat = MCatalog()
     self.mappcat = MInforCatalog()
Esempio n. 19
0
 def render(self, uid_with_str):
     self.mcat = MInforCatalog()
     recs = self.mcat.query_uid_starts_with(uid_with_str)
     # return ''
     return self.render_string('infor/modules/catalog_of.html', recs=recs)
Esempio n. 20
0
    def initialize(self):
        self.init()

        self.mequa = MApp()
        self.mtag = MInforCatalog()
        self.mapp2tag = MApp2Catalog()
Esempio n. 21
0
class MaintainPycateCategoryHandler(BaseHandler):
    def initialize(self):
        self.init()
        self.muser = MUser()
        self.mclass = MPycateCatalog()
        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=''):
        url_arr = self.parse_url(url_str)

        if url_str == 'add':
            self.to_add_class()
        elif url_str == 'list':
            self.recent()
        elif url_str == 'refresh':
            self.refresh()
        elif url_arr[0] == 'modify':
            self.to_modify(url_arr[1])
        elif url_arr[0] == 'delete':
            self.delete(url_arr[1])

        else:
            kwd = {
                'info': '页面未找到',
            }
            self.render('html/404.html', kwd=kwd)

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

        if len(url_arr) == 1 and url_str.endswith('.html'):
            self.add_post()

        if url_arr[0] == 'modify':
            self.update(url_arr[1])
        elif url_str == 'add':
            self.user_add_class()
        else:
            self.redirect('html/404.html')

    def recent(self):
        kwd = {
            'pager': '',
            'unescape': tornado.escape.xhtml_unescape,
            'title': '最近文档',
        }
        self.render('doc/maintain/pycatecategory/category_list.html',
                    kwd=kwd,
                    view=self.mclass.query_recent(),
                    format_date=tools.format_date,
                    userinfo=self.userinfo,
                    )

    def refresh(self):

        kwd = {
            'pager': '',
            'title': '最近文档',
        }
        self.render('doc/maintain/pycatecategory/category_list.html',
                    kwd=kwd,
                    userinfo=self.userinfo,
                    view=self.mclass.query_dated(10),
                    format_date=tools.format_date,
                    unescape=tornado.escape.xhtml_unescape, )

    def get_random(self):
        return self.mclass.query_random()

    def wiki(self, uid):
        dbdate = self.mclass.get_by_id(uid)
        if dbdate:

            self.viewit(uid)
        else:

            self.to_add(uid)

    def to_add_class(self, ):
        kwd = {
            'pager': '',
            'uid': '',
        }
        self.render('doc/maintain/pycatecategory/category_add.html',
                    topmenu='',
                    kwd=kwd,
                    userinfo=self.userinfo,
                    )

    @tornado.web.authenticated
    def to_add(self, uid):
        if self.is_admin():
            pass
        else:
            return False
        kwd = {
            'uid': uid,
            'pager': '',
        }
        self.render('doc/maintain/pycatecategory/list.html',
                    kwd=kwd,
                    )

    @tornado.web.authenticated
    def update(self, uid):
        if self.is_admin():
            pass
        else:
            return False
        raw_data = self.mclass.get_by_id(uid)

        post_data = {}
        for key in self.request.arguments:
            post_data[key] = self.get_arguments(key)
        post_data['user_name'] = self.get_current_user()

        self.mclass.update(uid, post_data)

        self.redirect('/maintain/pycatecategory/list'.format(uid))

    @tornado.web.authenticated
    def to_modify(self, id_rec):
        a = self.mclass.get_by_id(id_rec)
        # 用户具有管理权限,或文章是用户自己发布的。
        if self.is_admin():
            pass
        else:
            return False

        kwd = {
            'pager': '',

        }
        self.render('doc/maintain/pycatecategory/category_edit.html',
                    kwd=kwd,
                    unescape=tornado.escape.xhtml_unescape,
                    dbrec=a,
                    userinfo=self.userinfo,
                    )

    @tornado.web.authenticated
    def viewit(self, post_id):

        rec = self.mclass.get_by_uid(post_id)

        if not rec:
            kwd = {
                'info': '您要找的分类不存在。',
            }
            self.render('html/404.html', kwd=kwd)
            return False

        kwd = {
            'pager': '',
            'editable': self.editable(),

        }

        self.render('doc/maintain/pycatecategory/category_view.html',
                    view=rec,
                    unescape=tornado.escape.xhtml_unescape,
                    kwd=kwd,
                    userinfo=self.userinfo,

                    )

    @tornado.web.authenticated
    def user_add_class(self):
        if self.is_admin():
            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.mclass.insert_data(post_data)

        self.redirect('/maintain/pycatecategory/list'.format())

    @tornado.web.authenticated
    def delete(self, del_id):
        if self.is_admin():
            pass
        else:
            return False
        is_deleted = self.mclass.delete(del_id)
        if is_deleted:
            self.redirect('/maintain/pycatecategory/list')
        else:
            return False
Esempio n. 22
0
class InforTagHandler(BaseHandler):
    '''
    List the infos by the slug of the catalog.
    '''

    def initialize(self):
        self.init()

        self.mequa = MApp()
        self.mtag = MInforCatalog()
        self.mapp2tag = MApp2Catalog()

    def get(self, url_str=''):
        if len(url_str.strip()) == 0:
            return False

        url_arr = self.parse_url(url_str)

        if len(url_arr) == 1:
            self.list(url_str)
        elif len(url_arr) == 2:
            self.list(url_arr[0], url_arr[1])

    def list(self, tag_slug, cur_p=''):
        '''
        根据 cat_handler.py 中的 def view_cat_new(self, cat_slug, cur_p = '')
        :param tag_slug:
        :return:
        '''
        if cur_p == '' or cur_p == '-1':
            current_page_number = 1
        else:
            current_page_number = int(cur_p)
        taginfo = self.mtag.get_by_slug(tag_slug)
        num_of_tag = self.mapp2tag.count_of_certain_catalog(taginfo.uid)
        page_num = int(num_of_tag / config.page_num) + 1
        print(page_num)
        tag_name = taginfo.name

        kwd = {
            'tag_name': tag_name,
            'tag_slug': tag_slug,

            'title': tag_name,
        }

        self.render('infor/tag/list.html',
                    tag_name=tag_name,
                    infos=self.mapp2tag.query_pager_by_slug(tag_slug, current_page_number),
                    unescape=tornado.escape.xhtml_unescape,
                    kwd=kwd,
                    pager=self.gen_pager_bootstrap(tag_slug, page_num, current_page_number),
                    userinfo=self.userinfo,
                    )

    def gen_pager_bootstrap(self, cat_slug, page_num, current):
        # cat_slug 分类
        # page_num 页面总数
        # current 当前页面
        if page_num == 1:
            return ''

        pager_shouye = '''
        <li class=" {0}">
        <a  href="/tag/{1}">&lt;&lt; 首页</a>
                    </li>'''.format('hidden' if current <= 1 else '', cat_slug)

        pager_pre = '''
                    <li class=" {0}">
                    <a  href="/tag/{1}/{2}">&lt; 前页</a>
                    </li>
                    '''.format('hidden' if current <= 1 else '', cat_slug, current - 1)
        pager_mid = ''
        for ind in range(0, page_num):
            tmp_mid = '''
                    <li class="{0}">
                    <a  href="/tag/{1}/{2}">{2}</a></li>
                    '''.format('active' if ind + 1 == current else '', cat_slug, ind + 1)
            pager_mid += tmp_mid
        pager_next = '''
                    <li class=" {0}">
                    <a  href="/tag/{1}/{2}">后页 &gt;</a>
                    </li>
                    '''.format('hidden' if current >= page_num else '', cat_slug, current + 1)
        pager_last = '''
                    <li class=" {0}">
                    <a  href="/tag/{1}/{2}">末页
                        &gt;&gt;</a>
                    </li>
                    '''.format('hidden' if current >= page_num else '', cat_slug, page_num)
        pager = pager_shouye + pager_pre + pager_mid + pager_next + pager_last
        return (pager)

    def gen_pager(self, cat_slug, page_num, current):
        # cat_slug 分类
        # page_num 页面总数
        # current 当前页面
        if page_num == 1:
            return ''

        pager_shouye = '''
        <li class="pure-menu-item first {0}">
        <a class="pure-menu-link" href="/tag/{1}">&lt;&lt; 首页</a>
                    </li>'''.format('hidden' if current <= 1 else '', cat_slug)

        pager_pre = '''
                    <li class="pure-menu-item previous {0}">
                    <a class="pure-menu-link" href="/tag/{1}/{2}">&lt; 前页</a>
                    </li>
                    '''.format('hidden' if current <= 1 else '', cat_slug, current - 1)
        pager_mid = ''
        for ind in range(0, page_num):
            tmp_mid = '''
                    <li class="pure-menu-item page {0}">
                    <a class="pure-menu-link" href="/tag/{1}/{2}">{2}</a></li>
                    '''.format('selected' if ind + 1 == current else '', cat_slug, ind + 1)
            pager_mid += tmp_mid
        pager_next = '''
                    <li class="pure-menu-item next {0}">
                    <a class="pure-menu-link" href="/tag/{1}/{2}">后页 &gt;</a>
                    </li>
                    '''.format('hidden' if current >= page_num else '', cat_slug, current + 1)
        pager_last = '''
                    <li class="pure-menu-item last {0}">
                    <a class="pure-menu-link" href="/tag/{1}/{2}">末页
                        &gt;&gt;</a>
                    </li>
                    '''.format('hidden' if current >= page_num else '', cat_slug, page_num)
        pager = pager_shouye + pager_pre + pager_mid + pager_next + pager_last
        return (pager)
Esempio n. 23
0
 def initialize(self, hinfo=''):
     self.init()
     self.template_dir_name = 'infor'
     self.minfo = MInfor()
     self.mcat = MCatalog()
     self.mappcat = MInforCatalog()
Esempio n. 24
0
class InfoListHandler(BaseHandler):
    def initialize(self, hinfo=''):
        self.init()
        self.template_dir_name = 'infor'
        self.minfo = MInfor()
        self.mcat = MCatalog()
        self.mappcat = MInforCatalog()

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

        if len(url_str) == 4:
            self.list(url_str)
        elif len(url_str) > 4:
            self.echo_html(url_str)
        else:
            self.render('html/404.html', kwd={})

    def gen_redis_kw(self):
        condition = {}
        if self.get_current_user():
            redis_kw = redisvr.smembers(config.redis_kw +
                                        self.userinfo.user_name)
        else:
            redis_kw = []

        kw_condition_arr = []
        for x in redis_kw:
            kw_condition_arr.append(x.decode('utf-8'))
        if redis_kw:
            condition['def_tag_arr'] = kw_condition_arr
        return condition

    def echo_html(self, url_str):

        condition = self.gen_redis_kw()

        url_arr = self.parse_url(url_str)
        sig = url_arr[0]

        num = (len(url_arr) - 2) // 2

        if sig.endswith('00'):
            condition['def_cat_pid'] = sig
        else:
            condition['def_cat_uid'] = sig

        fenye_num = 1
        for ii in range(num):
            ckey = url_arr[ii * 2 + 2]

            tval = url_arr[ii * 2 + 3]
            if tval == '0':
                continue
            if ckey == 'fenye':
                # 分页参数。单独处理。
                fenye_num = int(tval)
                continue

            else:
                cval = tval
            ckey = 'tag_' + ckey
            condition[ckey] = cval

        print(condition)
        if url_arr[1] == 'con':
            infos = self.minfo.get_list_fenye(condition, fenye_num)
            self.echo_html_list_str(sig, infos)
        elif url_arr[1] == 'num':
            allinfos = self.minfo.get_list(condition)
            self.echo_html_fenye_str(allinfos.count(), fenye_num)

    def echo_html_list_str(self, list_type, infos):
        '''
        生成 list 后的 HTML 格式的字符串
        '''
        zhiding_str = ''
        tuiguang_str = ''
        imgname = 'fixed/zhanwei.png'

        kwd = {
            'imgname': imgname,
            'zhiding': zhiding_str,
            'tuiguang': tuiguang_str,
        }
        self.render('autogen/infolist/infolist_{1}.html'.format(
            self.template_dir_name, list_type),
                    userinfo=self.userinfo,
                    kwd=kwd,
                    html2text=html2text,
                    unescape=tornado.escape.xhtml_unescape,
                    post_infos=infos,
                    widget_info=kwd)

    def echo_html_fenye_str(self, rec_num, fenye_num):
        '''
        生成分页的导航
        '''

        pagination_num = int(math.ceil(rec_num * 1.0 / 10))

        if pagination_num == 1 or pagination_num == 0:
            fenye_str = ''

        elif pagination_num > 1:
            pager_mid = ''
            pager_pre = ''
            pager_next = ''
            fenye_str = '<ul class="pagination">'
            if fenye_num > 1:
                pager_pre = ''' <li class="{0}" name='fenye' onclick='change(this);'
                  value='{1}'><a>上一页</a></li>'''.format('', fenye_num - 1)
            if fenye_num > 5:
                cur_num = fenye_num - 4
            else:
                cur_num = 1

            if pagination_num > 10:
                show_num = cur_num + 10
            else:
                show_num = pagination_num

            for num in range(cur_num, show_num):
                if num == fenye_num:
                    checkstr = 'active'
                else:
                    checkstr = ''

                tmp_str_df = '''

                  <li class="{0}" name='fenye' onclick='change(this);'
                  value='{1}'><a>{1}</a></li>'''.format(checkstr, num)

                pager_mid += tmp_str_df
            if fenye_num < pagination_num:
                pager_next = '''

                  <li class="{0}" name='fenye' onclick='change(this);'
                  value='{1}'><a>下一页</a></li>'''.format('', fenye_num + 1)

            fenye_str += pager_pre + pager_mid + pager_next
            fenye_str += '</ul>'

        else:
            pass
        self.write(fenye_str)

    def list(self, input):
        '''
        页面打开后的渲染方法,不包含 list 的查询结果与分页导航
        '''
        condition = self.gen_redis_kw()

        sig = input
        bread_title = ''
        bread_crumb_nav_str = '<li>当前位置:<a href="/">信息</a></li>'

        if input.endswith('00'):
            parent_id = input
            parent_catname = self.mcat.get_by_id(parent_id).name
            condition['parentid'] = [parent_id]
            catname = self.mcat.get_by_id(sig).name
            bread_crumb_nav_str += '<li><a href="/list/{0}">{1}</a></li>'.format(
                sig, catname)
            bread_title = '{1}'.format(sig, catname)

        else:
            condition['catid'] = [sig]
            parent_id = sig[:2] + '00'
            parent_catname = self.mcat.get_by_id(parent_id).name
            catname = self.mcat.get_by_id(sig).name
            bread_crumb_nav_str += '<li><a href="/list/{0}">{1}</a></li>'.format(
                parent_id, parent_catname)

            bread_crumb_nav_str += '<li><a href="/list/{0}">{1}</a></li>'.format(
                sig, catname)
            bread_title += '{1} - '.format(parent_id, parent_catname)
            bread_title += '{1}'.format(sig, catname)

        num = self.minfo.get_num_condition(condition)

        kwd = {
            'catid': input,
            'daohangstr': bread_crumb_nav_str,
            'breadtilte': bread_title,
            'parentid': parent_id,
            'parentlist': self.mcat.get_parent_list(),
            'condition': condition,
            'catname': catname,
            'rec_num': num,
        }

        cat_rec = self.mappcat.get_by_uid(input)
        priv_mask_idx = cat_rec.priv_mask.index('1')

        if self.get_current_user():
            redis_kw = redisvr.smembers(config.redis_kw +
                                        self.userinfo.user_name)
        else:
            redis_kw = []
        kw_condition_arr = []
        for x in redis_kw:
            kw_condition_arr.append(x.decode('utf-8'))
        self.render(
            'autogen/list/list_{1}.html'.format(self.template_dir_name, input),
            userinfo=self.userinfo,
            kwd=kwd,
            widget_info=kwd,
            condition_arr=kw_condition_arr,
            cat_enum=self.mappcat.get_qian2(parent_id[:2]),
            priv_mask_idx=priv_mask_idx,
        )
Esempio n. 25
0
class InfoPublishHandler(BaseHandler):
    def initialize(self, hinfo=''):
        self.init()
        self.minforcatalog = MInforCatalog()

    def get(self, url_str=''):
        url_arr = self.parse_url(url_str)
        if url_str == '':
            self.view_class1()
        elif len(url_str) == 4:
            self.view_class2(url_str)
        elif len(url_str) == 5:
            self.echo_class2(url_str)
        elif len(url_arr) == 2 and url_arr[1] == 'vip':
            self.view_class2(url_arr[0], 1)

    @tornado.web.authenticated
    def echo_class2(self, input=''):
        '''
        弹出的二级发布菜单
        '''
        fatherid = input[1:]
        self.write(self.format_class2(fatherid))

    @tornado.web.authenticated
    def format_class2(self, fatherid):
        dbdata = self.minforcatalog.get_qian2(fatherid[:2])
        outstr = '<ul class="list-group">'
        for rec in dbdata:
            if rec.uid.endswith('00'):
                continue
            priv_mask_idx = rec.priv_mask.index('1')
            if self.userinfo.privilege[priv_mask_idx] >= '1':
                outstr += '''
            <a href="/meta/cat_add/{0}" class="btn btn-primary" style="display: inline-block;margin:3px;" >{1}</a>
            '''.format(rec.uid, rec.name)
        outstr += '</ul>'
        return (outstr)

    @tornado.web.authenticated
    def view_class1(self):
        dbdata = self.minforcatalog.get_parent_list()
        class1str = ''
        for rec in dbdata:
            priv_mask_idx = rec.priv_mask.index('1')
            if self.userinfo.privilege[priv_mask_idx] >= '1':
                class1str += '''
             <a onclick="select('/publish/2{0}');" class="btn btn-primary" style="display: inline-block;margin:3px;" >{1}</a>
            '''.format(rec.uid, rec.name)

        kwd = {
            'class1str': class1str,
            'parentid': '0',
            'parentlist': self.minforcatalog.get_parent_list(),
        }
        self.render('infor/publish/publish.html',
                    userinfo=self.userinfo,
                    kwd=kwd)

    @tornado.web.authenticated
    def view_class2(self, fatherid=''):
        '''
        从第二级分类发布
        :param fatherid:
        :return:
        '''
        if self.is_admin():
            pass
        else:
            return False
        fatherid = fatherid[:2] + '00'
        kwd = {
            'class1str': self.format_class2(fatherid),
            'parentid': '0',
            'parentlist': self.minforcatalog.get_parent_list(),
        }
        self.render('infor/publish/publish2.html',
                    userinfo=self.userinfo,
                    kwd=kwd)
Esempio n. 26
0
class MetaHandler(BaseHandler):
    def initialize(self):
        self.init()
        self.mappcat = MInforCatalog()
        self.mevaluation = MEvaluation()
        self.mapp2catalog = MApp2Catalog()
        self.mapp2tag = MApp2Label()
        self.mapp = MApp()
        self.musage = MUsage()
        self.mtag = MInforCatalog()
        self.mrel = MAppRel()
        self.mreply = MApp2Reply()
        if 'app_url_name' in cfg:
            self.app_url_name = cfg['app_url_name']
        else:
            self.app_url_name = 'info'

    def get(self, url_str=''):

        url_arr = self.parse_url(url_str)

        if url_arr[0] == 'cat_add':
            self.user_to_add(url_arr[1])
        elif url_arr[0] == 'catalog':
            self.catalog()
        elif len(url_arr) == 1 and len(url_str) == 4:
            self.redirect('/{0}/{1}'.format(self.app_url_name, url_arr[0]))
        elif len(url_arr) == 2:
            if url_arr[0] == 'edit':
                self.to_edit_app(url_arr[1])
            elif url_arr[0] == 'add':
                self.to_add_app(url_arr[1])
            elif url_arr[0] == 'delete':
                self.to_del_app(url_arr[1])

            else:
                '''
                从相关计算中过来的。
                '''
                self.mrel.update_relation(url_arr[1], url_arr[0])
                self.redirect('/{0}/{1}'.format(self.app_url_name, url_arr[0]))
        else:
            kwd = {
                'title': '',
                '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] == 'to_add':
            self.add()
        elif url_arr[0] == 'rel':
            if self.get_current_user():
                self.add_relation(url_arr[1])
            else:
                self.redirect('/user/login')
        elif url_arr[0] == 'comment_add':
            self.add_comment(url_arr[1])
        elif url_arr[0] == 'edit':
            self.update(url_arr[1])
        elif url_arr[0] == 'add':
            self.add(url_arr[1])
        else:
            return False

    def catalog(self):
        self.render('infor/app/catalog.html',
                    userinfo=self.userinfo,
                    kwd={
                        'uid': '',
                    })

    @tornado.web.authenticated
    def user_to_add(self, catid):

        uid = tools.get_uu4d()
        while self.mapp.get_by_uid(uid):
            uid = tools.get_uu4d()
        kwd = {
            'uid': uid,
            'userid': self.userinfo.user_name,
            'def_cat_uid': catid,
            'parentname': self.mtag.get_by_id(catid[:2] + '00').name,
            'catname': self.mtag.get_by_id(catid).name,
        }
        self.render('autogen/add/add_{0}.html'.format(catid),
                    userinfo=self.userinfo,
                    kwd=kwd)

    def check_priv(self, userinfo, cat_id):
        cat_rec = self.mappcat.get_by_uid(cat_id)
        priv_mask_idx = cat_rec.priv_mask.index('1')
        priv_dic = {
            'ADD': False,
            'EDIT': False,
            'DELETE': False,
            'ADMIN': False
        }
        if userinfo.privilege[priv_mask_idx] >= '1':
            priv_dic['ADD'] = True
        if userinfo.privilege[priv_mask_idx] >= '2':
            priv_dic['EDIT'] = True
        if userinfo.privilege[priv_mask_idx] >= '4':
            priv_dic['DELETE'] = True
        if userinfo.privilege[priv_mask_idx] >= '8':
            priv_dic['ADMIN'] = True
        return priv_dic

    @tornado.web.authenticated
    def to_add_app(self, uid):
        if self.mapp.get_by_uid(uid):
            self.redirect('/{0}/edit/{1}'.format(self.app_url_name, uid))
        else:
            self.render('infor/app/add.html',
                        tag_infos=self.mtag.query_all(),
                        userinfo=self.userinfo,
                        kwd={
                            'uid': uid,
                        })

    @tornado.web.authenticated
    def to_del_app(self, uid):
        current_infor = self.mapp.get_by_uid(uid)
        if self.check_priv(self.userinfo,
                           current_infor.extinfo['def_cat_uid'])['DELETE']:
            pass
        else:
            return False

        if self.mapp.delete(uid):
            self.redirect('/list/{0}'.format(
                current_infor.extinfo['def_cat_uid']))
        else:
            self.redirect('/info/{0}'.format(uid))

    @tornado.web.authenticated
    def to_edit_app(self, infoid):

        rec_info = self.mapp.get_by_uid(infoid)

        if rec_info:
            pass
        else:
            self.render('html/404.html')
            return
        if 'def_cat_uid' in rec_info.extinfo:
            catid = rec_info.extinfo['def_cat_uid']
        else:
            catid = ''

        kwd = {
            'def_cat_uid':
            catid,
            'parentname':
            self.mtag.get_by_id(catid[:2] + '00').name if catid != '' else '',
            'catname':
            self.mtag.get_by_id(catid).name if catid != '' else '',
            'parentlist':
            self.mtag.get_parent_list(),
            'userip':
            self.request.remote_ip
        }

        if catid:
            tmpl = 'autogen/edit/edit_{0}.html'.format(catid)
        else:
            tmpl = 'infor/app/edit.html'

        self.render(
            tmpl,
            kwd=kwd,
            calc_info=rec_info,
            post_info=rec_info,
            userinfo=self.userinfo,
            app_info=rec_info,
            unescape=tornado.escape.xhtml_unescape,
            cat_enum=self.mappcat.get_qian2(catid[:2]),
            tag_infos=self.mappcat.query_all(by_order=True),
            app2tag_info=self.mapp2catalog.query_by_entry_uid(infoid),
            app2label_info=self.mapp2tag.get_by_id(infoid),
        )

    @tornado.web.authenticated
    def update(self, uid):
        post_data = {}
        ext_dic = {}
        for key in self.request.arguments:
            if key.startswith('ext_') or key.startswith('tag_'):
                ext_dic[key] = self.get_argument(key)
            else:
                post_data[key] = self.get_arguments(key)

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

        current_info = self.mapp.get_by_uid(uid)

        if current_info.user_name == self.userinfo.user_name:
            pass
        elif self.userinfo.privilege[4] >= '1':
            pass
        elif 'def_cat_uid' in post_data and self.check_priv(
                self.userinfo, post_data['def_cat_uid'][0])['EDIT']:
            pass
        else:
            return False

        ext_dic['def_uid'] = str(uid)
        if 'def_cat_uid' in post_data:
            ext_dic['def_cat_uid'] = post_data['def_cat_uid'][0]
            ext_dic['def_cat_pid'] = '{0}00'.format(
                post_data['def_cat_uid'][0][:2])

        ext_dic['def_tag_arr'] = [
            x.strip()
            for x in post_data['tags'][0].strip().strip(',').split(',')
        ]
        ext_dic = self.extra_data(ext_dic, post_data)
        self.mapp.modify_meta(uid, post_data, extinfo=ext_dic)
        self.update_catalog(uid)
        self.update_tag(uid)
        self.redirect('/{0}/{1}'.format(self.app_url_name, uid))

    @tornado.web.authenticated
    def add(self, uid=''):

        ext_dic = {}
        post_data = {}
        for key in self.request.arguments:
            if key.startswith('ext_') or key.startswith('tag_'):
                ext_dic[key] = self.get_argument(key)
            else:
                post_data[key] = self.get_arguments(key)

        if self.check_priv(self.userinfo, post_data['def_cat_uid'][0])['ADD']:
            pass
        else:
            return False

        if uid == '':
            uid = tools.get_uu4d()
            while self.mapp.get_by_uid(uid):
                uid = tools.get_uu4d()
            post_data['uid'][0] = uid

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

        ext_dic['def_uid'] = str(uid)
        if 'def_cat_uid' in post_data:
            ext_dic['def_cat_pid'] = '{0}00'.format(
                post_data['def_cat_uid'][0][:2])
            ext_dic['def_cat_uid'] = post_data['def_cat_uid'][0]

        ext_dic['def_tag_arr'] = [
            x.strip()
            for x in post_data['tags'][0].strip().strip(',').split(',')
        ]
        ext_dic = self.extra_data(ext_dic, post_data)
        print(post_data)
        self.mapp.modify_meta(ext_dic['def_uid'], post_data, extinfo=ext_dic)
        self.update_catalog(ext_dic['def_uid'])
        self.update_tag(ext_dic['def_uid'])

        self.redirect('/list/{0}'.format(ext_dic['def_cat_uid']))

    @tornado.web.authenticated
    def extra_data(self, ext_dic, post_data):
        '''
        The additional information.
        :param post_data:
        :return: directory.
        '''
        return ext_dic

    @tornado.web.authenticated
    def update_tag(self, signature):

        post_data = {}
        for key in self.request.arguments:
            post_data[key] = self.get_arguments(key)
        current_tag_infos = self.mapp2tag.get_by_id(signature)
        tags_arr = [x.strip() for x in post_data['tags'][0].split(',')]
        for tag_name in tags_arr:
            if tag_name == '':
                pass
            else:
                self.mapp2tag.add_record(signature, tag_name, 1)

        for cur_info in current_tag_infos:
            if cur_info.tag.name in tags_arr:
                pass
            else:
                self.mapp2tag.remove_relation(signature, cur_info.tag)

    @tornado.web.authenticated
    def update_catalog(self, signature):
        post_data = {}
        for key in self.request.arguments:
            post_data[key] = self.get_arguments(key)
        current_catalog_infos = self.mapp2catalog.query_by_entry_uid(signature)

        new_tag_arr = []
        for idx, key in enumerate(
            ['cat_1', 'cat_2', 'cat_3', 'cat_4', 'cat_5', 'def_cat_uid']):
            if key in post_data:
                vv = post_data[key][0]
                if vv == '':
                    pass
                else:
                    new_tag_arr.append(vv)
                    self.mapp2catalog.add_record(signature, vv, idx)
            else:
                pass

        for cur_info in current_catalog_infos:
            if str(cur_info.catalog.uid).strip() in new_tag_arr:
                pass
            else:
                self.mapp2catalog.remove_relation(signature, cur_info.catalog)

    @tornado.web.authenticated
    def add_comment(self, id_post):
        post_data = {}
        for key in self.request.arguments:
            post_data[key] = self.get_arguments(key)
        post_data['user_id'] = self.userinfo.uid
        post_data['user_name'] = self.userinfo.user_name
        comment_uid = self.mreply.insert_data(post_data, id_post)
        if comment_uid:
            output = {
                'pinglun': comment_uid,
            }
        else:
            output = {
                'pinglun': 0,
            }
        return json.dump(output, self)

    def add_relation(self, f_uid, t_uid):
        if False == self.mapp.get_by_uid(t_uid):
            return False
        if f_uid == t_uid:
            '''
            关联其本身
            '''
            return False
        self.mrel.add_relation(f_uid, t_uid, 2)
        self.mrel.add_relation(t_uid, f_uid, 1)
        return True
Esempio n. 27
0
# -*- coding: utf-8
from openpyxl.reader.excel import load_workbook
from torcms.model.minforcatalog import MInforCatalog

wb = load_workbook(filename='./database/meta/info_tags.xlsx')
sheet_ranges_arr = [wb['Sheet1'], wb['Sheet2']]
class_arr = ['D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T']
sig_name_arr = []
mappcat = MInforCatalog()


def uu():
    # 在分类中排序
    order_index = 1
    # 父类索引
    papa_index = 1
    # 子类索引
    c_index = 1
    papa_id = 0
    uid = ''
    p_dic = {}
    # 逐行遍历
    for sheet_ranges in sheet_ranges_arr:

        for row_num in range(3, 48):
            # 父类
            p_cell_val = sheet_ranges['A{0}'.format(row_num)].value
            if p_cell_val and p_cell_val != '':
                cell_arr = p_cell_val.split(',')
                p_uid = cell_arr[0].strip().strip('t')
                priv_mask = cell_arr[1].strip().strip('t')
Esempio n. 28
0
    def render(self, ):
        self.mcat = MInforCatalog()

        return self.render_string('widget/widget_search.html',
                                  cat_enum=self.mcat.query_pcat())
Esempio n. 29
0
 def render(self, uid_with_str):
     self.mcat = MInforCatalog()
     recs = self.mcat.query_uid_starts_with( uid_with_str )
     # return ''
     return self.render_string('infor/modules/catalog_of.html', recs=recs)
Esempio n. 30
0
class InfoHandler(BaseHandler):
    def initialize(self, hinfo=''):
        self.init()
        self.mevaluation = MEvaluation()
        self.mapp2catalog = MApp2Catalog()
        self.mapp2tag = MApp2Label()
        self.minfo = MApp()
        self.musage = MUsage()
        self.mcat = MInforCatalog()
        self.mrel = MAppRel()
        self.mreply = MApp2Reply()

    def get(self, url_str=''):
        url_arr = self.parse_url(url_str)
        if len(url_arr) == 1 and len(url_str) == 4:
            self.view_info(url_str)
        else:
            kwd = {
                'title': '',
                '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] == 'rel':
            if self.get_current_user():
                self.add_relation(url_arr[1], url_arr[2])
            else:
                self.redirect('/user/login')
        elif url_arr[0] == 'comment_add':
            self.add_comment(url_arr[1])
        else:
            return False

    @tornado.web.authenticated
    def add_comment(self, id_post):
        post_data = {}
        for key in self.request.arguments:
            post_data[key] = self.get_arguments(key)
        post_data['user_id'] = self.userinfo.uid
        post_data['user_name'] = self.userinfo.user_name
        comment_uid = self.mreply.insert_data(post_data, id_post)
        if comment_uid:
            output = {
                'pinglun': comment_uid,
            }
        else:
            output = {
                'pinglun': 0,
            }
        return json.dump(output, self)

    def view_info(self, info_id):
        '''
        Render the info
        :param info_id:
        :return: Nonthing.
        '''

        rec = self.minfo.get_by_uid(info_id)

        if rec:
            pass
        else:
            kwd = {
                'info': '您要找的信息不存在。',
            }
            self.render('html/404.html',
                        kwd=kwd,
                        userinfo=self.userinfo, )
            return False

        replys = self.mreply.get_by_id(info_id)
        rel_recs = self.mrel.get_app_relations(rec.uid, 4)
        rand_recs = self.minfo.query_random(4 - rel_recs.count() + 2)
        self.chuli_cookie_relation(info_id)
        cookie_str = tools.get_uuid()

        if 'def_cat_uid' in rec.extinfo:
            catid = rec.extinfo['def_cat_uid']
        else:
            catid = ''

        parent_name = self.mcat.get_by_id(catid[:2] + '00').name if catid != '' else ''
        if catid != '':
            cat_rec = self.mcat.get_by_uid(catid)
            priv_mask_idx = cat_rec.priv_mask.index('1')
            cat_name = cat_rec.name
        else:
            priv_mask_idx = 0
            cat_name = ''

        parentname = '<a href="/list/{0}">{1}</a>'.format(catid[:2] + '00', parent_name)

        catname = '<a href="/list/{0}">{1}</a>'.format(catid, cat_name)

        kwd = {
            'pager': '',
            'url': self.request.uri,
            'cookie_str': cookie_str,
            'daohangstr': '',
            'signature': info_id,
            'tdesc': '',
            'eval_0': self.mevaluation.app_evaluation_count(info_id, 0),
            'eval_1': self.mevaluation.app_evaluation_count(info_id, 1),
            'site_url': config.site_url,
            'login': 1 if self.get_current_user() else 0,
            'has_image': 0,
            'parentlist': self.mcat.get_parent_list(),
            'parentname': parentname,
            'catname': catname,
        }
        self.minfo.view_count_increase(info_id)
        if self.get_current_user():
            self.musage.add_or_update(self.userinfo.uid, info_id)
        self.set_cookie('user_pass', cookie_str)
        tmpl = self.ext_tmpl_name(rec) if self.ext_tmpl_name(rec) else self.get_tmpl_name(rec)
        catid = rec.extinfo['def_cat_uid'] if 'def_cat_uid' in rec.extinfo else None
        print(rec.extinfo)
        self.render(tmpl,
                    kwd=dict(kwd, **self.extra_kwd(rec)),
                    calc_info=rec,
                    userinfo=self.userinfo,
                    relations=rel_recs,
                    rand_recs=rand_recs,
                    unescape=tornado.escape.xhtml_unescape,
                    ad_switch=random.randint(1, 18),
                    tag_info=self.mapp2tag.get_by_id(info_id),
                    recent_apps=self.musage.query_recent(self.get_current_user(), 6)[1:],
                    post_info=rec,
                    replys=replys,
                    cat_enum=self.mcat.get_qian2(catid[:2]) if catid else [],
                    priv_mask_idx=priv_mask_idx,
                    )

    def extra_kwd(self, info_rec):
        '''
        The additional information.
        :param info_rec:
        :return: directory.
        '''
        return {}

    def chuli_cookie_relation(self, app_id):
        '''
        The current Info and the Info viewed last should have some relation.
        And the last viewed Info could be found from cookie.
        :param app_id: the current app
        :return: None
        '''
        last_app_uid = self.get_secure_cookie('use_app_uid')
        if last_app_uid:
            last_app_uid = last_app_uid.decode('utf-8')
        self.set_secure_cookie('use_app_uid', app_id)
        if last_app_uid and self.minfo.get_by_uid(last_app_uid):
            self.add_relation(last_app_uid, app_id)

    def ext_tmpl_name(self, rec):
        return None

    def get_tmpl_name(self, rec):
        '''
        According to the application, each info of it's classification could has different temaplate.
        :param rec: the App record.
        :return: the temaplte path.
        '''
        if 'def_cat_uid' in rec.extinfo and rec.extinfo['def_cat_uid'] != '':
            cat_id = rec.extinfo['def_cat_uid']
        else:
            cat_id = False
        if cat_id:
            tmpl = 'autogen/view/view_{0}.html'.format(cat_id)
        else:
            tmpl = 'infor/app/show_map.html'
        return tmpl

    def add_relation(self, f_uid, t_uid):
        '''
        Add the relation. And the from and to, should have different weight.
        :param f_uid:
        :param t_uid:
        :return: return True if the relation has been succesfully added.
        '''
        if self.minfo.get_by_uid(t_uid):
            pass
        else:
            return False
        if f_uid == t_uid:
            return False
        self.mrel.add_relation(f_uid, t_uid, 2)
        self.mrel.add_relation(t_uid, f_uid, 1)
        return True
Esempio n. 31
0
    def render(self, ):
        self.mcat = MInforCatalog()

        return self.render_string('widget/widget_search.html', cat_enum = self.mcat.query_pcat())
Esempio n. 32
0
class InfoListHandler(BaseHandler):
    def initialize(self, hinfo=''):
        self.init()
        self.template_dir_name = 'infor'
        self.minfo = MInfor()
        self.mcat = MCatalog()
        self.mappcat = MInforCatalog()

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

        if len(url_str) == 4:
            self.list(url_str)
        elif len(url_str) > 4:
            self.echo_html(url_str)
        else:
            self.render('html/404.html', kwd={})

    def gen_redis_kw(self):
        condition = {}
        if self.get_current_user():
            redis_kw = redisvr.smembers(config.redis_kw + self.userinfo.user_name)
        else:
            redis_kw = []

        kw_condition_arr = []
        for x in redis_kw:
            kw_condition_arr.append(x.decode('utf-8'))
        if redis_kw:
            condition['def_tag_arr'] = kw_condition_arr
        return condition

    def echo_html(self, url_str):

        condition = self.gen_redis_kw()

        url_arr = self.parse_url(url_str)
        sig = url_arr[0]

        num = (len(url_arr) - 2) // 2

        if sig.endswith('00'):
            condition['def_cat_pid'] = sig
        else:
            condition['def_cat_uid'] = sig


        fenye_num = 1
        for ii in range(num):
            ckey = url_arr[ii * 2 + 2]

            tval = url_arr[ii * 2 + 3]
            if tval == '0':
                continue
            if ckey == 'fenye':
                # 分页参数。单独处理。
                fenye_num = int(tval)
                continue

            else:
                cval = tval
            ckey = 'tag_' + ckey
            condition[ckey] = cval

        print(condition)
        if url_arr[1] == 'con':
            infos = self.minfo.get_list_fenye(condition, fenye_num)
            self.echo_html_list_str(sig, infos)
        elif url_arr[1] == 'num':
            allinfos = self.minfo.get_list(condition)
            self.echo_html_fenye_str(allinfos.count(), fenye_num)

    def echo_html_list_str(self, list_type, infos):
        '''
        生成 list 后的 HTML 格式的字符串
        '''
        zhiding_str = ''
        tuiguang_str = ''
        imgname = 'fixed/zhanwei.png'

        kwd = {
            'imgname': imgname,
            'zhiding': zhiding_str,
            'tuiguang': tuiguang_str,
        }
        self.render('autogen/infolist/infolist_{1}.html'.format(self.template_dir_name, list_type),
                    userinfo=self.userinfo,
                    kwd=kwd,
                    html2text=html2text,
                    unescape=tornado.escape.xhtml_unescape,
                    post_infos=infos,
                    widget_info=kwd)

    def echo_html_fenye_str(self, rec_num, fenye_num):
        '''
        生成分页的导航
        '''

        pagination_num = int(math.ceil(rec_num * 1.0 / 10))

        if pagination_num == 1 or pagination_num == 0:
            fenye_str = ''

        elif pagination_num > 1:
            pager_mid = ''
            pager_pre = ''
            pager_next = ''
            pager_last = ''
            pager_home = ''
            fenye_str = '<ul class="pagination">'

            if fenye_num > 1:
                pager_home = '''

                  <li class="{0}" name='fenye' onclick='change(this);'
                  value='{1}'><a>首页</a></li>'''.format('', 1)

                pager_pre = ''' <li class="{0}" name='fenye' onclick='change(this);'
                  value='{1}'><a>上一页</a></li>'''.format('', fenye_num - 1)
            if fenye_num > 5:
                cur_num = fenye_num - 4
            else:
                cur_num = 1

            if pagination_num > 10 and cur_num < pagination_num - 10:
                show_num = cur_num + 10

            else:
                show_num = pagination_num + 1

            for num in range(cur_num,show_num):
                if num == fenye_num:
                    checkstr = 'active'
                else:
                    checkstr = ''

                tmp_str_df = '''

                  <li class="{0}" name='fenye' onclick='change(this);'
                  value='{1}'><a>{1}</a></li>'''.format(checkstr, num)

                pager_mid += tmp_str_df
            if fenye_num < pagination_num:
                pager_next = '''

                  <li class="{0}" name='fenye' onclick='change(this);'
                  value='{1}'><a>下一页</a></li>'''.format('', fenye_num + 1)
                pager_last = '''

                  <li class="{0}" name='fenye' onclick='change(this);'
                  value='{1}'><a>末页</a></li>'''.format('', pagination_num)


            fenye_str += pager_home + pager_pre + pager_mid + pager_next + pager_last
            fenye_str += '</ul>'

        else:
            pass
        self.write(fenye_str)

    def list(self, input):
        '''
        页面打开后的渲染方法,不包含 list 的查询结果与分页导航
        '''
        condition = self.gen_redis_kw()

        sig = input
        bread_title = ''
        bread_crumb_nav_str = '<li>当前位置:<a href="/">信息</a></li>'

        if input.endswith('00'):
            parent_id = input
            parent_catname = self.mcat.get_by_id(parent_id).name
            condition['parentid'] = [parent_id]
            catname = self.mcat.get_by_id(sig).name
            bread_crumb_nav_str += '<li><a href="/list/{0}">{1}</a></li>'.format(sig, catname)
            bread_title = '{1}'.format(sig, catname)

        else:
            condition['catid'] = [sig]
            parent_id = sig[:2] + '00'
            parent_catname = self.mcat.get_by_id(parent_id).name
            catname = self.mcat.get_by_id(sig).name
            bread_crumb_nav_str += '<li><a href="/list/{0}">{1}</a></li>'.format(parent_id, parent_catname)

            bread_crumb_nav_str += '<li><a href="/list/{0}">{1}</a></li>'.format(sig, catname)
            bread_title += '{1} - '.format(parent_id, parent_catname)
            bread_title += '{1}'.format(sig, catname)

        num = self.minfo.get_num_condition(condition)

        kwd = {
            'catid': input,
            'daohangstr': bread_crumb_nav_str,
            'breadtilte': bread_title,
            'parentid': parent_id,
            'parentlist': self.mcat.get_parent_list(),
            'condition': condition,
            'catname': catname,
            'rec_num': num,
        }

        cat_rec = self.mappcat.get_by_uid(input)
        priv_mask_idx = cat_rec.priv_mask.index('1')

        if self.get_current_user():
            redis_kw = redisvr.smembers(config.redis_kw + self.userinfo.user_name)
        else:
            redis_kw = []
        kw_condition_arr = []
        for x in redis_kw:
            kw_condition_arr.append(x.decode('utf-8'))
        self.render('autogen/list/list_{1}.html'.format(self.template_dir_name, input),
                    userinfo=self.userinfo,
                    kwd=kwd,
                    widget_info=kwd,
                    condition_arr=kw_condition_arr,
                    cat_enum=self.mappcat.get_qian2(parent_id[:2]),
                    priv_mask_idx=priv_mask_idx,

                    )
Esempio n. 33
0
class InfoHandler(BaseHandler):
    def initialize(self, hinfo=''):
        self.init()
        self.mevaluation = MEvaluation()
        self.mapp2catalog = MApp2Catalog()
        self.mapp2tag = MApp2Label()
        self.minfo = MApp()
        self.musage = MUsage()
        self.mcat = MInforCatalog()
        self.mrel = MAppRel()
        self.mreply = MApp2Reply()

    def get(self, url_str=''):
        url_arr = self.parse_url(url_str)
        if len(url_arr) == 1 and len(url_str) == 4:
            self.view_info(url_str)
        else:
            kwd = {
                'title': '',
                '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] == 'rel':
            if self.get_current_user():
                self.add_relation(url_arr[1], url_arr[2])
            else:
                self.redirect('/user/login')
        elif url_arr[0] == 'comment_add':
            self.add_comment(url_arr[1])
        else:
            return False

    @tornado.web.authenticated
    def add_comment(self, id_post):
        post_data = {}
        for key in self.request.arguments:
            post_data[key] = self.get_arguments(key)
        post_data['user_id'] = self.userinfo.uid
        post_data['user_name'] = self.userinfo.user_name
        comment_uid = self.mreply.insert_data(post_data, id_post)
        if comment_uid:
            output = {
                'pinglun': comment_uid,
            }
        else:
            output = {
                'pinglun': 0,
            }
        return json.dump(output, self)

    def view_info(self, info_id):
        '''
        Render the info
        :param info_id:
        :return: Nonthing.
        '''

        rec = self.minfo.get_by_uid(info_id)

        if rec:
            pass
        else:
            kwd = {
                'info': '您要找的信息不存在。',
            }
            self.render('html/404.html',
                        kwd=kwd,
                        userinfo=self.userinfo, )
            return False

        replys = self.mreply.get_by_id(info_id)
        rel_recs = self.mrel.get_app_relations(rec.uid, 4)
        rand_recs = self.minfo.query_random(4 - rel_recs.count() + 2)
        self.chuli_cookie_relation(info_id)
        cookie_str = tools.get_uuid()

        if 'def_cat_uid' in rec.extinfo:
            catid = rec.extinfo['def_cat_uid']
        else:
            catid = ''

        parent_name = self.mcat.get_by_id(catid[:2] + '00').name if catid != '' else ''
        if catid != '':
            cat_rec = self.mcat.get_by_uid(catid)
            priv_mask_idx = cat_rec.priv_mask.index('1')
            cat_name = cat_rec.name
        else:
            priv_mask_idx = 0
            cat_name = ''

        parentname = '<a href="/list/{0}">{1}</a>'.format(catid[:2] + '00', parent_name)

        catname = '<a href="/list/{0}">{1}</a>'.format(catid, cat_name)

        kwd = {
            'pager': '',
            'url': self.request.uri,
            'cookie_str': cookie_str,
            'daohangstr': '',
            'signature': info_id,
            'tdesc': '',
            'eval_0': self.mevaluation.app_evaluation_count(info_id, 0),
            'eval_1': self.mevaluation.app_evaluation_count(info_id, 1),
            'site_url': config.site_url,
            'login': 1 if self.get_current_user() else 0,
            'has_image': 0,
            'parentlist': self.mcat.get_parent_list(),
            'parentname': parentname,
            'catname': catname,
        }
        self.minfo.view_count_increase(info_id)
        if self.get_current_user():
            self.musage.add_or_update(self.userinfo.uid, info_id)
        self.set_cookie('user_pass', cookie_str)
        tmpl = self.ext_tmpl_name(rec) if self.ext_tmpl_name(rec) else self.get_tmpl_name(rec)
        catid = rec.extinfo['def_cat_uid'] if 'def_cat_uid' in rec.extinfo else None
        print(rec.extinfo)
        self.render(tmpl,
                    kwd=dict(kwd, **self.extra_kwd(rec)),
                    calc_info=rec,
                    userinfo=self.userinfo,
                    relations=rel_recs,
                    rand_recs=rand_recs,
                    unescape=tornado.escape.xhtml_unescape,
                    ad_switch=random.randint(1, 18),
                    tag_info=self.mapp2tag.get_by_id(info_id),
                    recent_apps=self.musage.query_recent(self.get_current_user(), 6)[1:],
                    post_info=rec,
                    replys=replys,
                    cat_enum=self.mcat.get_qian2(catid[:2]) if catid else [],
                    priv_mask_idx=priv_mask_idx,
                    )

    def extra_kwd(self, info_rec):
        '''
        The additional information.
        :param info_rec:
        :return: directory.
        '''
        return {}

    def chuli_cookie_relation(self, app_id):
        '''
        The current Info and the Info viewed last should have some relation.
        And the last viewed Info could be found from cookie.
        :param app_id: the current app
        :return: None
        '''
        last_map_id = self.get_secure_cookie('use_app_uid')
        if last_map_id:
            last_map_id = last_map_id.decode('utf-8')
        self.set_secure_cookie('use_app_uid', app_id)
        if last_map_id and self.minfo.get_by_uid(last_map_id):
            self.add_relation(last_map_id, app_id)

    def ext_tmpl_name(self, rec):
        return None

    def get_tmpl_name(self, rec):
        '''
        According to the application, each info of it's classification could has different temaplate.
        :param rec: the App record.
        :return: the temaplte path.
        '''
        if 'def_cat_uid' in rec.extinfo and rec.extinfo['def_cat_uid'] != '':
            cat_id = rec.extinfo['def_cat_uid']
        else:
            cat_id = False
        if cat_id:
            tmpl = 'autogen/view/view_{0}.html'.format(cat_id)
        else:
            tmpl = 'infor/app/show_map.html'
        return tmpl

    def add_relation(self, f_uid, t_uid):
        '''
        Add the relation. And the from and to, should have different weight.
        :param f_uid:
        :param t_uid:
        :return: return True if the relation has been succesfully added.
        '''
        if self.minfo.get_by_uid(t_uid):
            pass
        else:
            return False
        if f_uid == t_uid:
            return False
        self.mrel.add_relation(f_uid, t_uid, 2)
        self.mrel.add_relation(t_uid, f_uid, 1)
        return True
Esempio n. 34
0
class SearchHandler(BaseHandler):
    def initialize(self):
        self.init()
        self.mpost = MPost()
        self.mcat = MInforCatalog()
        # self.cats = self.mcat.query_all()
        # self.mpost2catalog = MPost2Catalog()
        self.ysearch = yunsearch()

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

        if url_str == '':
            return
        elif len(url_arr) == 2:
            self.search(url_arr[0], int(url_arr[1]))
        elif len(url_arr) == 3:
            self.search_cat(url_arr[0], url_arr[1], int(url_arr[2]))
        else:
            kwd = {
                'info': '页面未找到',
            }
            self.render('html/404.html', kwd=kwd, userinfo=self.userinfo)

    def post(self, url_str=''):
        catid = self.get_argument('searchcat')
        keyword = self.get_argument('keyword')
        if catid == '':
            self.redirect('/search/{0}/1'.format(keyword))
        else:
            self.redirect('/search/{0}/{1}/1'.format(catid, keyword))

    def search(self, keyword, p_index=1):
        res_all = self.ysearch.get_all_num(keyword)
        results = self.ysearch.search_pager(keyword,
                                            page_index=p_index,
                                            doc_per_page=20)
        page_num = int(res_all / 20)
        kwd = {
            'title': '查找结果',
            'pager': '',
            'count': res_all,
            'keyword': keyword,
        }
        self.render(
            'doc/search/search.html',
            kwd=kwd,
            srecs=results,
            pager=self.gen_pager_bootstrap_url('/search/{0}'.format(keyword),
                                               page_num, p_index),
            userinfo=self.userinfo,
            cfg=config.cfg,
        )

    def gen_pager_bootstrap_url(self, cat_slug, page_num, current):
        # cat_slug 分类
        # page_num 页面总数
        # current 当前页面

        if page_num == 1 or page_num == 0:
            pager = ''

        elif page_num > 1:
            pager_mid = ''
            pager_pre = ''
            pager_next = ''
            pager_last = ''
            pager_home = ''

            pager = '<ul class="pagination">'

            if current > 1:
                pager_home = '''

                      <li class="{0}" name='fenye' onclick='change(this);'
                      ><a href="{1}/{2}">首页</a></li>'''.format(
                    '', cat_slug, 1)

                pager_pre = ''' <li class="{0}" name='fenye' onclick='change(this);'>
                    <a href="{1}/{2}">上一页</a></li>'''.format(
                    '', cat_slug, current - 1)
            if current > 5:
                cur_num = current - 4
            else:
                cur_num = 1

            if page_num > 10 and cur_num < page_num - 10:
                show_num = cur_num + 10

            else:
                show_num = page_num + 1

            for num in range(cur_num, show_num):
                if num == current:
                    checkstr = 'active'
                else:
                    checkstr = ''

                tmp_str_df = '''

                      <li class="{0}" name='fenye' onclick='change(this);'>
                      <a href="{1}/{2}">{2}</a></li>'''.format(
                    checkstr, cat_slug, num)

                pager_mid += tmp_str_df
            if current < page_num:
                pager_next = '''

                      <li class="{0}" name='fenye' onclick='change(this);'
                      ><a href="{1}/{2}">下一页</a></li>'''.format(
                    '', cat_slug, current + 1)
                pager_last = '''

                      <li class="{0}" name='fenye' onclick='change(this);'
                     ><a href="{1}/{2}">末页</a></li>'''.format(
                    '', cat_slug, page_num)

            pager += pager_home + pager_pre + pager_mid + pager_next + pager_last
            pager += '</ul>'
        else:
            pass

        return (pager)

    def search_cat(self, catid, keyword, p_index=1):
        res_all = self.ysearch.get_all_num(keyword, catid=catid)
        results = self.ysearch.search_pager(keyword,
                                            catid=catid,
                                            page_index=p_index,
                                            doc_per_page=20)
        page_num = int(res_all / 20)
        kwd = {
            'title':
            '查找结果',
            'pager':
            '',
            'count':
            res_all,
            'keyword':
            keyword,
            'catname':
            '文档' if catid == '0000' else self.mcat.get_by_uid(catid).name,
        }
        self.render(
            'doc/search/search.html',
            kwd=kwd,
            srecs=results,
            pager=self.gen_pager_bootstrap_url(
                '/search/{0}/{1}'.format(catid, keyword), page_num, p_index),
            userinfo=self.userinfo,
            cfg=config.cfg,
        )
Esempio n. 35
0
class MaintainPycateCategoryHandler(BaseHandler):
    def initialize(self):
        self.init()
        self.muser = MUser()
        self.mclass = MPycateCatalog()
        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=''):
        url_arr = self.parse_url(url_str)

        if url_str == 'add':
            self.to_add_class()
        elif url_str == 'list':
            self.recent()
        elif url_str == 'refresh':
            self.refresh()
        elif url_arr[0] == 'modify':
            self.to_modify(url_arr[1])
        elif url_arr[0] == 'delete':
            self.delete(url_arr[1])

        else:
            kwd = {
                'info': '页面未找到',
            }
            self.render('html/404.html', kwd=kwd)

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

        if len(url_arr) == 1 and url_str.endswith('.html'):
            self.add_post()

        if url_arr[0] == 'modify':
            self.update(url_arr[1])
        elif url_str == 'add':
            self.user_add_class()
        else:
            self.redirect('html/404.html')

    def recent(self):
        kwd = {
            'pager': '',
            'unescape': tornado.escape.xhtml_unescape,
            'title': '最近文档',
        }
        self.render(
            'doc/maintain/pycatecategory/category_list.html',
            kwd=kwd,
            view=self.mclass.query_recent(),
            format_date=tools.format_date,
            userinfo=self.userinfo,
        )

    def refresh(self):

        kwd = {
            'pager': '',
            'title': '最近文档',
        }
        self.render(
            'doc/maintain/pycatecategory/category_list.html',
            kwd=kwd,
            userinfo=self.userinfo,
            view=self.mclass.query_dated(10),
            format_date=tools.format_date,
            unescape=tornado.escape.xhtml_unescape,
        )

    def get_random(self):
        return self.mclass.query_random()

    def wiki(self, uid):
        dbdate = self.mclass.get_by_id(uid)
        if dbdate:

            self.viewit(uid)
        else:

            self.to_add(uid)

    def to_add_class(self, ):
        kwd = {
            'pager': '',
            'uid': '',
        }
        self.render(
            'doc/maintain/pycatecategory/category_add.html',
            topmenu='',
            kwd=kwd,
            userinfo=self.userinfo,
        )

    @tornado.web.authenticated
    def to_add(self, uid):
        if self.is_admin():
            pass
        else:
            return False
        kwd = {
            'uid': uid,
            'pager': '',
        }
        self.render(
            'doc/maintain/pycatecategory/list.html',
            kwd=kwd,
        )

    @tornado.web.authenticated
    def update(self, uid):
        if self.is_admin():
            pass
        else:
            return False
        raw_data = self.mclass.get_by_id(uid)

        post_data = {}
        for key in self.request.arguments:
            post_data[key] = self.get_arguments(key)
        post_data['user_name'] = self.get_current_user()

        self.mclass.update(uid, post_data)

        self.redirect('/maintain/pycatecategory/list'.format(uid))

    @tornado.web.authenticated
    def to_modify(self, id_rec):
        a = self.mclass.get_by_id(id_rec)
        # 用户具有管理权限,或文章是用户自己发布的。
        if self.is_admin():
            pass
        else:
            return False

        kwd = {
            'pager': '',
        }
        self.render(
            'doc/maintain/pycatecategory/category_edit.html',
            kwd=kwd,
            unescape=tornado.escape.xhtml_unescape,
            dbrec=a,
            userinfo=self.userinfo,
        )

    @tornado.web.authenticated
    def viewit(self, post_id):

        rec = self.mclass.get_by_uid(post_id)

        if not rec:
            kwd = {
                'info': '您要找的分类不存在。',
            }
            self.render('html/404.html', kwd=kwd)
            return False

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

        self.render(
            'doc/maintain/pycatecategory/category_view.html',
            view=rec,
            unescape=tornado.escape.xhtml_unescape,
            kwd=kwd,
            userinfo=self.userinfo,
        )

    @tornado.web.authenticated
    def user_add_class(self):
        if self.is_admin():
            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.mclass.insert_data(post_data)

        self.redirect('/maintain/pycatecategory/list'.format())

    @tornado.web.authenticated
    def delete(self, del_id):
        if self.is_admin():
            pass
        else:
            return False
        is_deleted = self.mclass.delete(del_id)
        if is_deleted:
            self.redirect('/maintain/pycatecategory/list')
        else:
            return False
Esempio n. 36
0
class SearchHandler(BaseHandler):
    def initialize(self):
        self.init()
        self.mpost = MPost()
        self.mcat = MInforCatalog()
        # self.cats = self.mcat.query_all()
        # self.mpost2catalog = MPost2Catalog()
        self.ysearch = yunsearch()

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

        if url_str == '':
            return
        elif len(url_arr) == 2:
            self.search(url_arr[0], int(url_arr[1]))
        elif len(url_arr) == 3:
            self.search_cat(url_arr[0], url_arr[1], int(url_arr[2]))
        else:
            kwd = {
                'info': '页面未找到',
            }
            self.render('html/404.html', kwd=kwd, userinfo=self.userinfo)

    def post(self, url_str=''):
        catid = self.get_argument('searchcat')
        keyword = self.get_argument('keyword')
        if catid == '':
            self.redirect('/search/{0}/1'.format(keyword))
        else:
            self.redirect('/search/{0}/{1}/1'.format(catid, keyword))

    def search(self, keyword, p_index=1):
        res_all = self.ysearch.get_all_num(keyword)
        results = self.ysearch.search_pager(keyword,
                                            page_index=p_index,
                                            doc_per_page=20)
        page_num = int(res_all / 20)
        kwd = {
            'title': '查找结果',
            'pager': '',
            'count': res_all,
            'keyword': keyword,
        }
        self.render(
            'doc/search/search.html',
            kwd=kwd,
            srecs=results,
            pager=tools.gen_pager_bootstrap_url('/search/{0}'.format(keyword),
                                                page_num, p_index),
            userinfo=self.userinfo,
            cfg=config.cfg,
        )

    def search_cat(self, catid, keyword, p_index=1):
        res_all = self.ysearch.get_all_num(keyword, catid=catid)
        results = self.ysearch.search_pager(keyword,
                                            catid=catid,
                                            page_index=p_index,
                                            doc_per_page=20)
        page_num = int(res_all / 20)
        kwd = {
            'title':
            '查找结果',
            'pager':
            '',
            'count':
            res_all,
            'keyword':
            keyword,
            'catname':
            '文档' if catid == '0000' else self.mcat.get_by_uid(catid).name,
        }
        self.render(
            'doc/search/search.html',
            kwd=kwd,
            srecs=results,
            pager=tools.gen_pager_bootstrap_url(
                '/search/{0}/{1}'.format(catid, keyword), page_num, p_index),
            userinfo=self.userinfo,
            cfg=config.cfg,
        )