예제 #1
0
class SimpleWidgetTestCase(unittest.TestCase):
    def setUp(self):
        self.muser = MUser()

        payload1 = {
            'user_name': 'giser1',
            'user_pass': '******',
        }
        self.r1 = requests.post('http://127.0.0.1:8088/user/regist', payload1)
        payload1 = {
            'user_name': 'giser1',
            'user_pass': '******',
            'user_email': 'sadf',
        }
        self.r2 = requests.post('http://127.0.0.1:8088/user/regist', payload1)

        payload3 = {
            'user_name': 'giser1',
            'user_pass': '******',
            'user_email': '*****@*****.**',
        }
        self.r3 = requests.post('http://127.0.0.1:8088/user/regist', payload3)
        # 相同用户名注册
        self.r55 = requests.post('http://127.0.0.1:8088/user/regist', payload3)

        self.r4 = requests.post('http://127.0.0.1:8088/user/login', payload3)

        payload4 = {
            'user_name': 'giser1',
            'user_pass': '******',
        }
        self.r5 = requests.post('http://127.0.0.1:8088/user/login', payload4)

    def tearDown(self):
        self.muser.delete_by_user_name('giser1')
class AdminHandler(tornado.web.RequestHandler):
    def initialize(self):
        self.mpost = MPost()
        self.mcat = MCatalog()
        self.muser = MUser()
        self.mpage = MPage()
        self.mlink = MLink()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None

    def get_current_user(self):
        return self.get_secure_cookie("user")

    def get(self, input=''):
        if input == '':
            self.index()
        else:
            self.render('html/404.html')

    @tornado.web.authenticated
    def index(self):
        self.render('admin/admin_index.html',
                    user_info=self.muser.get_by_id(self.get_current_user())
                    )
예제 #3
0
    def initialize(self):
        self.mapp = MApp()
        self.mpost = MPost()
        self.rel_post2app = MRelPost2App()
        self.rel_app2post = MRelApp2Post()
        self.muser = MUser()

        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None
            self.mvip = None
예제 #4
0
    def initialize(self):
        self.muser = MUser()

        self.mequa = MApp()
        self.mtag = MAppLabel()
        self.mapp2tag = MApp2Label()

        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None
        self.tmpl_sig = app_template_name
예제 #5
0
 def initialize(self):
     self.muser = MUser()
     self.mwiki = MWiki()
     self.mcat = MCatalog()
     self.cats = self.mcat.query_all()
     self.mspec = SpesubModel()
     self.specs = self.mspec.get_all()
     self.mwiki_hist = MWikiHist()
     if self.get_current_user():
         self.userinfo = self.muser.get_by_id(self.get_current_user())
     else:
         self.userinfo = None
예제 #6
0
 def initialize(self):
     self.init()
     self.muser = MUser()
     self.mpage = MPage()
     self.mpost = MPost()
     self.mcat = MCatalog()
     self.cats = self.mcat.query_all()
     self.mspec = SpesubModel()
     if self.get_current_user():
         self.userinfo = self.muser.get_by_id(self.get_current_user())
     else:
         self.userinfo = None
예제 #7
0
    def initialize(self):
        self.muser = MUser()
        self.mpost = MPost()
        self.mcat = MCatalog()
        self.cats = self.mcat.query_all()
        self.mspec = SpesubModel()
        self.specs = self.mspec.get_all()
        self.mpost_hist = MPostHist()
        self.mpost2catalog = MPost2Catalog()
        self.mreply = MReply()

        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None
예제 #8
0
    def initialize(self):
        self.mevaluation = MEvaluation()
        self.mapp2catalog = MApp2Catalog()
        self.mapp2tag = MApp2Label()
        self.mapp = MApp()
        self.musage = MUsage()
        self.mtag = MAppCatalog()
        self.muser = MUser()
        self.mrel = MAppRel()
        self.mreply = MApp2Reply()

        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None
예제 #9
0
class AppIndexHandler(BaseHandler):
    def initialize(self):
        self.mpost = MPost()
        self.mcat = MCatalog()
        self.muser = MUser()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None
        self.tmpl_sig = app_template_name

    def get(self, input=''):
        if input == '':
            self.index()
        else:
            self.render('html/404.html')

    def index(self):
        cstr = tools.get_uuid()
        self.set_cookie('user_pass', cstr)
        kwd = {
            'cookie_str': cstr
        }
        self.render('{0}/index/index.html'.format(self.tmpl_sig),
                    kwd=kwd,
                    userinfo=self.userinfo,
                    catalog_info=self.mcat.query_all(by_order=True)
                    )
예제 #10
0
class ReplyHandler(BaseHandler):
    def initialize(self):
        self.init()
        self.muser = MUser()
        self.mreply = MReply()
        self.mreply2user = MReply2User()
        self.mpost2reply = MPost2Reply()

        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_arr[0] == 'get':
            self.get_by_id(url_arr[1])

    def get_by_id(self, reply_id):
        reply = self.mreply.get_reply_by_uid(reply_id)
        self.render('{0}/reply/show_reply.html'.format(self.tmpl_name),
                    cnt=reply.cnt_html,
                    username=reply.user_name,
                    date=reply.date,
                    vote=reply.vote,
                    uid=reply.uid,
                    userinfo=self.userinfo,
                    unescape=tornado.escape.xhtml_unescape,
                    )
예제 #11
0
class IndexHandler(tornado.web.RequestHandler):
    def initialize(self):
        self.mpost = MPost()
        self.mcat = MCatalog()
        self.muser = MUser()
        self.mpage = MPage()
        self.mlink = MLink()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None

    def get_current_user(self):
        return self.get_secure_cookie("user")

    def get(self, input=''):
        if input == '':
            self.index()
        else:
            self.render('html/404.html')

    def index(self):
        cstr = tools.get_uuid()
        self.set_cookie('user_pass', cstr)
        kwd = {'cookie_str': cstr}
        self.render(
            'index/index.html',
            kwd=kwd,
            userinfo=self.userinfo,
            catalog_info=self.mcat.query_all(by_order=True),
            link=self.mlink.query_all(),
            unescape=tornado.escape.xhtml_unescape,
        )
예제 #12
0
파일: index_app.py 프로젝트: wyf379/maplet
class AppIndexHandler(BaseHandler):
    def initialize(self):
        self.mpost = MPost()
        self.mcat = MCatalog()
        self.muser = MUser()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None
        self.tmpl_sig = app_template_name

    def get(self, input=''):
        if input == '':
            self.index()
        else:
            self.render('html/404.html')

    def index(self):
        cstr = tools.get_uuid()
        self.set_cookie('user_pass', cstr)
        kwd = {'cookie_str': cstr}
        self.render('{0}/index/index.html'.format(self.tmpl_sig),
                    kwd=kwd,
                    userinfo=self.userinfo,
                    catalog_info=self.mcat.query_all(by_order=True))
예제 #13
0
    def setUp(self):
        self.muser = MUser()

        payload1 = {
            'user_name': 'giser1',
            'user_pass': '******',
        }
        self.r1 = requests.post('http://127.0.0.1:8088/user/regist', payload1)
        payload1 = {
            'user_name': 'giser1',
            'user_pass': '******',
            'user_email': 'sadf',
        }
        self.r2 = requests.post('http://127.0.0.1:8088/user/regist', payload1)

        payload3 = {
            'user_name': 'giser1',
            'user_pass': '******',
            'user_email': '*****@*****.**',
        }
        self.r3 = requests.post('http://127.0.0.1:8088/user/regist', payload3)
        # 相同用户名注册
        self.r55 = requests.post('http://127.0.0.1:8088/user/regist', payload3)

        self.r4 = requests.post('http://127.0.0.1:8088/user/login', payload3)

        payload4 = {
            'user_name': 'giser1',
            'user_pass': '******',
        }
        self.r5 = requests.post('http://127.0.0.1:8088/user/login', payload4)
예제 #14
0
class BaseHandler(tornado.web.RequestHandler, TemplateRendring):

    def init(self):
        self.tmpl_name= config.torlite_template_name
        self.muser = MUser()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None

    def parse_url(self, url_str):
        url_str = url_str.strip()
        url_arr = [] if len(url_str) == 0 else url_str.split('/')
        return url_arr
    def get_current_user(self):
        return self.get_secure_cookie("user")

    def editable(self):
        # Deprecated.
        if self.get_current_user():
            return 1
        else:
            return 0

    def render_jinja2(self, template_name, **kwargs):
        kwargs.update({
            'settings': self.settings,
            'STATIC_URL': self.settings.get('static_url_prefix', '/static/'),
            'request': self.request,
            'current_user': self.current_user,
            'xsrf_token': self.xsrf_token,
            'xsrf_form_html': self.xsrf_form_html,
        })
        content = self.render_template(template_name, **kwargs)
        self.write(content)
예제 #15
0
class ReplyHandler(BaseHandler):
    def initialize(self):
        self.init()
        self.muser = MUser()
        self.mreply = MReply()
        self.mreply2user = MReply2User()
        self.mpost2reply = MPost2Reply()

        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None

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

        if url_arr[0] == 'get':
            self.get_by_id(url_arr[1])

    def get_by_id(self, reply_id):
        reply = self.mreply.get_reply_by_uid(reply_id)
        self.render('{0}/reply/show_reply.html'.format(self.tmpl_name),
                    cnt=reply.cnt_html,
                    username=reply.user_name,
                    date=reply.date,
                    vote=reply.vote,
                    uid=reply.uid,
                    userinfo=self.userinfo,
                    unescape=tornado.escape.xhtml_unescape,
                    )
예제 #16
0
 def init(self):
     self.tmpl_name= config.torlite_template_name
     self.muser = MUser()
     if self.get_current_user():
         self.userinfo = self.muser.get_by_id(self.get_current_user())
     else:
         self.userinfo = None
예제 #17
0
class ListHandler(BaseHandler):
    def initialize(self):
        self.mequa = MApp()
        self.musage = MUsage()
        self.muser = MUser()
        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 == 'app':
            self.list_app()

    def list_app(self):
        kwd = {
            'pager': '',
            'title': '最近使用的运算应用',
        }
        self.render(
            'app_theme/calc/list_app.html',
            kwd=kwd,
            userinfo=self.userinfo,
        )
예제 #18
0
파일: geojson.py 프로젝트: ironhot/maplet
 def initialize(self):
     self.mjson = MJson()
     self.muser = MUser()
     if self.get_current_user():
         self.userinfo = self.muser.get_by_id(self.get_current_user())
     else:
         self.userinfo = None
예제 #19
0
 def initialize(self):
     self.mapplication = MApp()
     self.muser = MUser()
     if self.get_current_user():
         self.userinfo = self.muser.get_by_id(self.get_current_user())
     else:
         self.userinfo = None
예제 #20
0
class PycateBaseHandler(tornado.web.RequestHandler):
    def init_condition(self):
        self.muser = MUser()

        userid = self.get_secure_cookie('user')
        if userid is None:
            self.user_name = ''
        else:
            self.user_name = userid.decode('utf-8')




        self.city_name = 'changchun'


        self.minfo = MInfo(self.city_name)
        self.mcity = MCity()
        # self.muser_info = MUserInfo(self.user_name)

        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None



    def get_current_user(self):
        return self.get_secure_cookie("user")
예제 #21
0
파일: index.py 프로젝트: Ryan007/TorCMS
class IndexHandler(tornado.web.RequestHandler):
    def initialize(self):
        self.mpost = MPost()
        self.mcat = MCatalog()
        self.muser = MUser()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None

    def get_current_user(self):
        return self.get_secure_cookie("user")

    def get(self, input=''):
        if input == '':
            self.index()
        else:
            self.render('html/404.html')

    def index(self):
        cstr = tools.get_uuid()
        self.set_cookie('user_pass', cstr)
        kwd = {
            'cookie_str': cstr
        }
        self.render('tplite/index/index.html',
                    kwd = kwd,
                    userinfo=self.userinfo,
                    catalog_info  = self.mcat.query_all( by_order=True)
                    )
예제 #22
0
class LabelHandler(BaseHandler):
    def initialize(self):
        self.init()
        self.muser = MUser()
        self.mequa = MPost()
        self.mtag = MLabel()
        self.mapp2tag = MPost2Label()
        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 len(url_arr) == 1:
            self.list(url_str)
        elif len(url_arr) == 2:
            self.list(url_arr[0], url_arr[1])
        else:
            return False

    # def post(self, url_str=''):
    #     if len(url_str) > 0:
    #         url_arr = url_str.split('/')
    #     else:
    #         return False
    #
    #     if url_arr[0] == 'edit':
    #         self.edit(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 == '':
            current_page_number = 1
        else:
            current_page_number = int(cur_p)

        current_page_number = 1 if current_page_number < 1 else current_page_number

        pager_num = int(self.mapp2tag.total_number(tag_slug) / config.page_num)
        tag_name = ''
        kwd = {
            'tag_name': tag_name,
            'tag_slug': tag_slug,
            'title': tag_name,
        }

        self.render('{0}/label/list.html'.format(self.tmpl_name),
                    infos=self.mapp2tag.query_pager_by_slug(tag_slug, current_page_number),
                    unescape=tornado.escape.xhtml_unescape,
                    kwd=kwd,
                    userinfo=self.userinfo,
                    pager=tools.gen_pager_bootstrap_url('/label/{0}'.format(tag_slug), pager_num, current_page_number),
                    cfg = config.cfg,
                    )
예제 #23
0
파일: index.py 프로젝트: vaveee/TorCMS
class IndexHandler(BaseHandler):
    def initialize(self):
        self.mpost = MPost()
        self.mcat = MCatalog()
        self.muser = MUser()
        self.mpage = MPage()
        self.mlink = MLink()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None

    def get_current_user(self):
        return self.get_secure_cookie("user")

    def get(self, input=''):
        if input == '':
            self.index()
        else:
            self.render('html/404.html')

    def index(self):
        cstr = tools.get_uuid()
        self.set_cookie('user_pass', cstr)
        kwd = {
            'cookie_str': cstr
        }
        self.render('index/index.html',
                    userinfo=self.userinfo,
                    catalog_info=self.mcat.query_all(by_order=True),
                    link= self.mlink.query_all(),
                    unescape=tornado.escape.xhtml_unescape,
                    cfg = config.cfg,
                    kwd=kwd,)
예제 #24
0
 def initialize(self):
     self.mequa = MApp()
     self.musage = MUsage()
     self.muser = MUser()
     if self.get_current_user():
         self.userinfo = self.muser.get_by_id(self.get_current_user())
     else:
         self.userinfo = None
예제 #25
0
    def initialize(self):
        self.mchart = MChart()
        self.muser = MUser()

        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None
예제 #26
0
 def initialize(self):
     self.init()
     self.muser = MUser()
     self.mlink = MLink()
     if self.get_current_user():
         self.userinfo = self.muser.get_by_id(self.get_current_user())
     else:
         self.userinfo = None
예제 #27
0
파일: index.py 프로젝트: Ryan007/TorCMS
 def initialize(self):
     self.mpost = MPost()
     self.mcat = MCatalog()
     self.muser = MUser()
     if self.get_current_user():
         self.userinfo = self.muser.get_by_id(self.get_current_user())
     else:
         self.userinfo = None
예제 #28
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
예제 #29
0
 def initialize(self):
     self.init()
     self.muser = MUser()
     self.mclass = MCatalog()
     self.tmpl_router = 'category_ajax'
     if self.get_current_user():
         self.userinfo = self.muser.get_by_id(self.get_current_user())
     else:
         self.userinfo = None
예제 #30
0
 def initialize(self):
     self.mpost = MPost()
     self.mcat = MCatalog()
     self.muser = MUser()
     if self.get_current_user():
         self.userinfo = self.muser.get_by_id(self.get_current_user())
     else:
         self.userinfo = None
     self.tmpl_sig = app_template_name
예제 #31
0
    def initialize(self):
        self.muser = MUser()
        self.mreply = MReply()
        self.mreply2user = MReply2User()

        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None
예제 #32
0
    def __init__(self):

        self.tab = TabUsage
        try:
            TabUsage.create_table()
        except:
            pass
        self.mapp2catalog = MApp2Catalog()
        self.muser = MUser()
예제 #33
0
 def initialize(self):
     self.muser = MUser()
     self.mequa = MPost()
     self.mtag = MLabel()
     self.mapp2tag = MPost2Label()
     if self.get_current_user():
         self.userinfo = self.muser.get_by_id(self.get_current_user())
     else:
         self.userinfo = None
예제 #34
0
 def initialize(self):
     self.mequa = MApp()
     self.musage = MUsage()
     self.muser = MUser()
     self.mrel = MAppRel()
     self.mcollect = MEvaluation()
     if self.get_current_user():
         self.userinfo = self.muser.get_by_id(self.get_current_user())
     else:
         self.userinfo = None
예제 #35
0
    def initialize(self):
        self.muser = MUser()

        self.mequa = MApp()
        self.mtag = MAppCatalog()
        self.mapp2tag = MApp2Catalog()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None
예제 #36
0
    def initialize(self):
        self.init()
        self.muser = MUser()
        self.mpost = MPost()
        self.mcat = MCatalog()
        self.cats = self.mcat.query_all()
        self.mspec = SpesubModel()
        self.specs = self.mspec.get_all()
        self.mpost_hist = MPostHist()
        self.mpost2catalog = MPost2Catalog()
        self.mpost2reply = MPost2Reply()
        self.mapp2tag = MPost2Label()
        self.mrel = MRelation()
        self.tmpl_router = 'post_ajax'

        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None
 def initialize(self):
     self.init()
     self.muser = MUser()
     self.user_name = self.get_current_user()
     self.tmpl_router = 'link_ajax'
     self.mlink = MLink()
     if self.get_current_user():
         self.userinfo = self.muser.get_by_id(self.get_current_user())
     else:
         self.userinfo = None
예제 #38
0
 def initialize(self):
     self.init()
     self.muser = MUser()
     self.mpost = MPost()
     self.mcat = MCatalog()
     self.cats = self.mcat.query_all()
     self.mpost2catalog = MPost2Catalog()
     if self.get_current_user():
         self.userinfo = self.muser.get_by_id(self.get_current_user())
     else:
         self.userinfo = None
예제 #39
0
 def initialize(self):
     self.muser = MUser()
     self.mpage = MPage()
     self.mdb = MPost()
     self.mcat = MCatalog()
     self.cats = self.mcat.query_all()
     self.mspec = SpesubModel()
     if self.get_current_user():
         self.userinfo = self.muser.get_by_id(self.get_current_user())
     else:
         self.userinfo = None
예제 #40
0
class LabelHandler(BaseHandler):
    def initialize(self):
        self.init()
        self.muser = MUser()
        self.mequa = MPost()
        self.mtag = MLabel()
        self.mapp2tag = MPost2Label()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None

    def get(self, input=''):
        if len(input) > 0:
            url_arr = input.split(r'/')

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

    def post(self, url_str=''):
        if len(url_str) > 0:
            url_arr = url_str.split('/')
        if url_arr[0] == 'edit':
            self.edit(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 == '':
            current_page_number = 1
        else:
            current_page_number = int(cur_p)

        pager_num = int(self.mapp2tag.total_number(tag_slug) / config.page_num)
        tag_name = ''
        kwd = {
            'tag_name': tag_name,
            'tag_slug': tag_slug,
            'title': tag_name,
        }

        self.render('{0}/label/list.html'.format(self.tmpl_name),
                    infos=self.mapp2tag.query_pager_by_slug(tag_slug, current_page_number),
                    unescape=tornado.escape.xhtml_unescape,
                    kwd=kwd,
                    userinfo=self.userinfo,
                    pager=tools.gen_pager_bootstrap_url('/label/{0}'.format(tag_slug), pager_num, current_page_number),

                    )
예제 #41
0
    def initialize(self):
        self.muser = MUser()

        self.mequa = MApp()
        self.mtag = MAppLabel()
        self.mapp2tag = MApp2Label()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None
        self.tmpl_sig = app_template_name
예제 #42
0
    def initialize(self):
        # analyzer = ChineseAnalyzer()
        # schema = Schema(title=TEXT(stored=True, analyzer = analyzer), path=ID(stored=True), content=TEXT(stored=True, analyzer=analyzer))
        # ix = config.ix
        # self.searcher = config.searcher
        # self.parser = config.parser
        # self.parser = QueryParser("content", schema=ix.schema)

        self.muser = MUser()
        self.mpost = MPost()
        self.mcat = MCatalog()
        self.cats = self.mcat.query_all()
        self.mspec = SpesubModel()
        self.specs = self.mspec.get_all()
        self.mpost_hist = MPostHist()
        self.mpost2catalog = MPost2Catalog()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None
예제 #43
0
 def initialize(self):
     self.mequa = MApp()
     self.musage = MUsage()
     self.muser = MUser()
     self.mrel = MAppRel()
     self.mcollect = MCollect()
     if self.get_current_user():
         self.userinfo = self.muser.get_by_id(self.get_current_user())
     else:
         self.userinfo = None
     self.tmpl_sig = app_template_name
예제 #44
0
class App2ReplyHandler(Post2ReplyHandler):
    def initialize(self):
        self.muser = MUser()
        self.mreply = MReply()
        self.mreply2user = MReply2User()
        self.mpost2reply = MApp2Reply()

        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None
예제 #45
0
class LinkAjaxHandler(LinkHandler):
    def initialize(self):
        self.init()
        self.muser = MUser()
        self.user_name = self.get_current_user()
        self.tmpl_router = 'link_ajax'
        self.mlink = MLink()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None
예제 #46
0
class SearchHandler(BaseHandler):
    def initialize(self):
        self.init()
        self.muser = MUser()
        self.mpost = MPost()
        self.mcat = MCatalog()
        self.cats = self.mcat.query_all()
        self.mspec = SpesubModel()
        self.specs = self.mspec.get_all()
        self.mpost_hist = MPostHist()
        self.mpost2catalog = MPost2Catalog()
        self.ysearch = yunsearch()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None

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

    def post(self, url_str=''):
        keyword = self.get_argument('keyword')
        self.search(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': '',
        }
        self.render(
            '{0}/search/search.html'.format(self.tmpl_name),
            kwd=kwd,
            srecs=results,
            pager=tools.gen_pager_bootstrap_url('/search/{0}'.format(keyword),
                                                page_num, p_index),
        )
예제 #47
0
class SearchHandler(BaseHandler):
    def initialize(self):
        # analyzer = ChineseAnalyzer()
        # schema = Schema(title=TEXT(stored=True, analyzer = analyzer), path=ID(stored=True), content=TEXT(stored=True, analyzer=analyzer))
        # ix = config.ix
        # self.searcher = config.searcher
        # self.parser = config.parser
        # self.parser = QueryParser("content", schema=ix.schema)

        self.muser = MUser()
        self.mpost = MPost()
        self.mcat = MCatalog()
        self.cats = self.mcat.query_all()
        self.mspec = SpesubModel()
        self.specs = self.mspec.get_all()
        self.mpost_hist = MPostHist()
        self.mpost2catalog = MPost2Catalog()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None

    def get(self, url_str=''):

        if url_str == '':
            return
        elif len(url_str) > 0:
            self.search(url_str)
        else:
            kwd = {
                'info': '页面未找到',
            }
            self.render('html/404.html', kwd=kwd)

    def post(self, url_str=''):
        keyword = self.get_argument('keyword')
        self.search(keyword)

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

    def search(self, keyword):
        results = whoosh_search(keyword, 20)
        # reswhoosh_search.keyworde limit=3limit=30)
        kwd = {'title': '查找结果'}
        self.render(
            'tplite/search/search.html',
            kwd=kwd,
            srecs=results,
        )
예제 #48
0
class CategoryHandler(BaseHandler):
    def initialize(self):
        self.init()
        self.muser = MUser()
        self.mpost = MPost()
        self.mcat = MCatalog()
        self.cats = self.mcat.query_all()
        self.mspec = SpesubModel()
        self.specs = self.mspec.get_all()
        self.mpost2catalog = MPost2Catalog()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None

    def get(self, input=''):
        if len(input) > 0:
            ip_arr = input.split(r'/')
        if input == '':
            pass
        elif len(ip_arr) == 1:
            self.list_catalog(input)
        elif len(ip_arr) == 2:
            self.list_catalog(ip_arr[0], ip_arr[1])
        else:
            self.render('html/404.html')

    def list_catalog(self, cat_slug, cur_p=''):
        if cur_p == '':
            current_page_num = 1
        else:
            current_page_num = int(cur_p)

        cat_rec = self.mcat.get_by_slug(cat_slug)
        num_of_cat = self.mpost2catalog.catalog_record_number(cat_rec.uid)
        page_num = int(num_of_cat / config.page_num) + 1
        cat_name = cat_rec.name
        kwd = {
            'cat_name': cat_name,
            'cat_slug': cat_slug,
            'unescape': tornado.escape.xhtml_unescape,
            'title': cat_name,
        }

        self.render('{0}/catalog/list.html'.format(self.tmpl_name),
                    infos=self.mpost2catalog.query_pager_by_slug(cat_slug, current_page_num),
                    pager=tools.gen_pager_purecss('/category/{0}'.format(cat_slug), page_num, current_page_num),
                    userinfo=self.userinfo,
                    kwd=kwd)

    def get_random(self):
        return self.mpost.query_random()
예제 #49
0
class MapOverlayHandler(BaseHandler):
    def initialize(self):
        self.mequa = MApp()
        self.muser = MUser()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None

    def get(self, url_str=''):
        if len(url_str) > 0:
            url_arr = url_str.split('/')
        else:
            url_arr = []
        if len(url_arr) > 1:
            self.show_overlay(url_arr)
        else:
            kwd = {
                'title': '',
                'info': '',
            }
            self.render('html/404.html', kwd=kwd)

    def show_overlay(self, app_arr):
        '''
        打开App.
        '''
        app_info_arr = []
        for app_rr in app_arr:
            app_info_arr.append(self.mequa.get_by_uid(app_rr))
        kwd = {
            'url': 1,
            "cookie_str": '',
        }
        if 'fullscreen' in self.request.arguments:
            tmpl = 'app_theme/overlay/overlay_full.html'
        else:
            tmpl = 'app_theme/overlay/overlay.html'
        self.render(
            tmpl,
            topmenu='',
            kwd=kwd,
            userinfo=self.userinfo,
            unescape=tornado.escape.xhtml_unescape,
            app_arr=app_info_arr,
            app_str='/'.join(app_arr),
            wcs_svr=config.wcs_svr,
        )
예제 #50
0
class BaseHandler(tornado.web.RequestHandler, TemplateRendring):
    def init(self):
        self.tmpl_name = config.torlite_template_name
        self.muser = MUser()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None

    def parse_url(self, url_str):
        url_str = url_str.strip()
        url_arr = [] if len(url_str) == 0 else url_str.split('/')
        return url_arr

    def get_current_user(self):
        return self.get_secure_cookie("user")

    def editable(self):
        # Deprecated.
        if self.get_current_user():
            return 1
        else:
            return 0

    def render_jinja2(self, template_name, **kwargs):
        kwargs.update({
            'settings':
            self.settings,
            'STATIC_URL':
            self.settings.get('static_url_prefix', '/static/'),
            'request':
            self.request,
            'current_user':
            self.current_user,
            'xsrf_token':
            self.xsrf_token,
            'xsrf_form_html':
            self.xsrf_form_html,
        })
        content = self.render_template(template_name, **kwargs)
        self.write(content)
예제 #51
0
class EvaluationHandler(BaseHandler):
    def initialize(self):
        self.mequa = MApp()
        self.musage = MUsage()
        self.muser = MUser()
        self.mrel = MAppRel()
        self.mcollect = MEvaluation()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None


    def get(self, url_str=''):
        if len(url_str) > 0:
            url_arr = url_str.split(r'/')
        else:
            return False

        # 形如  /evalucate/0123/1
        if len(url_arr) == 2 and len(url_arr[0]) == 4 and ( url_arr[1] in ['0', '1']):
            if self.get_current_user():
                self.add_or_update(url_arr[0], url_arr[1])
            else:
                self.set_status('403')
                return False
        return None



    @tornado.web.authenticated
    def add_or_update(self, app_id, value):
        self.mcollect.add_or_update(self.userinfo.uid, app_id, value)

        out_dic = {
            'eval0': self.mcollect.app_evaluation_count(app_id, 0),
            'eval1': self.mcollect.app_evaluation_count(app_id, 1)
        }
        uu = json.dumps(out_dic)
        self.write(uu)
예제 #52
0
class LayoutHandler(BaseHandler):
    def initialize(self):
        self.mequa = MApp()
        self.muser = MUser()
        self.mlayout = MLayout()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None

    def get(self, url_str):

        if len(url_str) > 0:
            url_arr = url_str.split('/')

        if len(url_arr) == 2:
            if url_arr[0] == 'delete':
                self.delete(url_arr[1])

    @tornado.web.authenticated
    def delete(self, uid):
        self.mlayout.delete_by_uid(uid)

    def post(self, url_str=''):
        if url_str == 'save':
            self.save_layout()

    @tornado.web.authenticated
    def save_layout(self):
        post_data = {}
        for key in self.request.arguments:
            post_data[key] = self.get_arguments(key)
        if 'zoom' in post_data:
            pass
        else:
            self.set_status(403)
            return
        post_data['user'] = self.userinfo.uid
        self.mlayout.add_or_update(post_data)
예제 #53
0
class CollectHandler(
        BaseHandler, ):
    def initialize(self):
        self.mequa = MApp()
        self.musage = MUsage()
        self.muser = MUser()
        self.mrel = MAppRel()
        self.mcollect = MCollect()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None
        self.tmpl_sig = app_template_name

    def get(self, url_str=''):
        if len(url_str) > 0:
            url_arr = url_str.split('/')
        else:
            return False
        if url_str == 'list':
            self.list()
        elif len(url_arr) == 1 and len(url_str) == 4:
            if self.get_current_user():
                self.add_or_update(url_str)
            else:
                self.set_status('403')
                return False

    @tornado.web.authenticated
    def add_or_update(self, app_id):
        self.mcollect.add_or_update(self.userinfo.uid, app_id)

    @tornado.web.authenticated
    def list(self):
        self.render(
            '{0}/collect/list.html'.format(self.tmpl_sig),
            recs_collect=self.mcollect.query_recent(self.userinfo.uid, 20),
            userinfo=self.userinfo,
        )
예제 #54
0
class SpecHandler(BaseHandler):
    def initialize(self):
        self.muser = MUser()
        self.mpage = MPage()
        self.mdb = MPost()
        self.mcat = MCatalog()
        self.cats = self.mcat.query_all()
        self.mspec = SpesubModel()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None

    def get(self, input=''):
        if len(input) > 0:
            ip_arr = input.split(r'/')
        if input == '':
            self.index()
        elif input == 'add':
            self.to_add()
        elif len(ip_arr) == 1:
            self.list(input)
        elif len(ip_arr) == 2 and ip_arr[1] == 'edit':
            self.to_edit(ip_arr[0])
        else:
            self.render('/html/404.html')

    def post(self, input=''):
        if len(input) > 0:
            ip_arr = input.split(r'/')
        if input == '':
            pass
        elif input == 'add':
            self.add()
        elif len(ip_arr) == 2 and ip_arr[1] == 'edit':
            self.edit(ip_arr[0])
        else:
            self.render('/html/404.html')
        self.redirect('/spec/')

    @tornado.web.authenticated
    def edit(self, uid):
        post_data = {}
        for key in self.request.arguments:
            post_data[key] = self.get_arguments(key)
        self.mspec.update(uid, post_data)

    @tornado.web.authenticated
    def add(self):
        post_data = {}
        for key in self.request.arguments:
            post_data[key] = self.get_arguments(key)

        self.mspec.addata(post_data)

    @tornado.web.authenticated
    def to_edit(self, uid):
        spec_rec = self.mspec.get_by_id(uid)
        self.render('tplite/spec/edit.html', spec_rec=spec_rec)

    @tornado.web.authenticated
    def to_add(self):
        # spec_rec = self.mspec.get_by_id(uid)
        # uuu = self.mcat.query_all()
        print('to_add')
        self.render('tplite/spec/add.html')

    def list(self, spec_slug):
        '''
        列出专题信息,按某一分类
        '''
        page_rec = self.mspec.get_by_slug(spec_slug)
        # content = self.mpage.get_by_wiki(page_rec.name)

        # if content is None:
        # re_url = '/page/{0}'.format(tornado.escape.url_escape(page_rec.name))
        #     self.redirect(re_url)

        kwd = {'editable': self.editable()}
        self.render(
            'tplite/spec/list.html',
            kwd=kwd,
            spec=page_rec,
            unescape=tornado.escape.xhtml_unescape,
            spec_recs=self.mdb.query_by_spec(page_rec.uid),
        )

    def index(self):
        kwd = {
            # 'spec': content,
            # 'view': recs,
            'editable': self.editable()
        }
        spec_recs = self.mspec.get_all()
        self.render('tplite/spec/index.html', spec_recs=spec_recs, kwd=kwd)
예제 #55
0
파일: geojson.py 프로젝트: wmk223/maplet
class GeoJsonHandler(BaseHandler):
    def initialize(self):
        self.mjson = MJson()
        self.muser = MUser()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None

    def get(self, url_str=''):
        if len(url_str) > 0:
            url_arr = url_str.split('/')

        if len(url_arr) == 1:
            rec = self.mjson.get_by_id(url_str)

            # 这里主要是检查一下保存成了个什么鬼。结果还是差强人意。
            # print('=' * 50)
            # xx = json.dumps(rec.json, indent=1)
            # print(xx)
            # for xx in rec.json.keys():
            #     print(rec.json[xx])
            # print('=' * 50)
            # print(rec.json)
            # print('=' * 50)
            if rec:
                return json.dump(rec.json, self)
            else:
                return False
        elif len(url_arr) == 2:
            if url_arr[0] == 'download':
                self.download(url_arr[1])
            if url_arr[0] == 'delete':
                self.delete(url_arr[1])

    @tornado.web.authenticated
    def delete(self, uid):
        self.mjson.delete_by_uid(uid)

    @tornado.web.authenticated
    def download(self, pa_str):

        uid = pa_str.split('_')[-1].split('.')[0]

        self.set_header('Content-Type', 'application/force-download')
        # self.set_header('Content-Disposition', 'attachment; filename=%s' % file_name)
        rec = self.mjson.get_by_id(uid)

        geojson = rec.json

        out_arr = []
        for key in geojson.keys():
            out_arr = out_arr + geojson[key]['features']

        out_dic = {"type": "FeatureCollection", "features": out_arr}

        if rec:
            return json.dump(out_dic, self)

    def post(self, url_str=''):

        if len(url_str) > 0:
            url_arr = url_str.split('/')
        if len(url_arr) == 2:
            if self.get_current_user():
                self.add_data(url_arr)
            else:
                self.set_status('403')
                return False
        else:
            self.set_status('403')
            return False

    @tornado.web.authenticated
    def add_data(self, url_arr):

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

        geojson_str = post_data['geojson'][0]

        xx = json.loads(geojson_str)

        out_dic = {}
        index = 0

        for x in xx['features']:
            bcbc = x['geometry']
            if 'features' in bcbc:
                # 判断是否是空的数据。空的数据保存到数据库,加载的时候,会出现问题。
                if bcbc['features'][0]['geometry']['coordinates'] in [[],
                                                                      [[None]]
                                                                      ]:
                    continue
            else:
                # 这里处理新加的数据。与已有的数据不一样。
                if bcbc['coordinates'] in [[], [[None]]]:
                    continue

                bcbc = {
                    'features': [{
                        'geometry': bcbc,
                        "properties": {},
                        "type": "Feature"
                    }],
                    'type':
                    "FeatureCollection"
                }

            out_dic[index] = bcbc
            index = index + 1

        if len(url_arr[1]) == 4:
            uid = url_arr[1]
            return_dic = {'sig': ''}

            cur_info = self.mjson.get_by_id(uid)

            # 用户的数据,不以允许其他人保存。
            if cur_info.user.uid == self.userinfo.uid:
                pass
            else:
                return_dic['status'] = 0
                return json.dump(return_dic, self)
        else:
            uid = tools.get_uu4d()
            while self.mjson.get_by_id(uid):
                uid = tools.get_uu4d()
            return_dic = {'sig': uid}

        try:
            self.mjson.add_or_update(uid, self.userinfo.uid, url_arr[0],
                                     out_dic)
            return_dic['status'] = 1
            return json.dump(return_dic, self)
        except:
            self.set_status(400)
            return False
예제 #56
0
class MapOverlayHandler(BaseHandler):
    def initialize(self):
        self.mapplication = MApp()
        self.muser = MUser()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None

    def get(self, url_str=''):
        if len(url_str) > 0:
            url_arr = url_str.split('/')
        else:
            url_arr = []
        if len(url_arr) > 1:
            self.show_overlay(url_arr)
        else:
            kwd = {
                'title': '',
                'info': '',
            }
            self.render('html/404.html', kwd=kwd)

    def show_overlay(self, app_arr):
        '''
        打开App.
        '''
        app_info_arr = []
        lon_arr = []
        lat_arr = []
        zoom_max_arr = []
        zoom_min_arr = []
        zoom_current_zrr = []

        # self.set_secure_cookie('over_kay', app_arr)

        for app_rr in app_arr:
            c_ap = self.mapplication.get_by_uid(app_rr)
            app_info_arr.append(c_ap)
            lon_arr.append(c_ap.lon)
            lat_arr.append(c_ap.lat)
            zoom_max_arr.append(c_ap.zoom_max)
            zoom_min_arr.append(c_ap.zoom_min)
            zoom_current_zrr.append(c_ap.zoom_current)

        kwd = {'url': 1,
               "cookie_str": '',
               'lon': average(lon_arr),
               'lat': average(lat_arr),
               'zoom_max': max(zoom_max_arr),
               'zoom_min': min(zoom_min_arr),
               'zoom_current': int(average(zoom_current_zrr)),
               }
        if 'fullscreen' in self.request.arguments:
            tmpl = 'app_theme/overlay/overlay_full.html'
        else:
            tmpl = 'app_theme/overlay/overlay.html'
        self.render(tmpl,
                    topmenu='',
                    kwd=kwd,
                    userinfo=self.userinfo,
                    unescape=tornado.escape.xhtml_unescape,
                    app_arr=app_info_arr,
                    app_str='/'.join(app_arr),
                    wcs_svr=config.wcs_svr,
                    )
예제 #57
0
class ReplyHandler(BaseHandler):
    def initialize(self):
        self.muser = MUser()
        self.mreply = MReply()
        self.mreply2user = MReply2User()

        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None

    def get(self, url_str=''):

        if url_str == '':
            return
        url_arr = url_str.split(r'/')

        if url_arr[0] == 'delete_reply':
            self.delete_by_id(url_arr[1])
        elif url_arr[0] == 'get':
            self.get_by_id(url_arr[1])
        elif url_arr[0] == 'zan':
            self.zan(url_arr[1])

    def get_by_id(self, reply_id):
        reply = self.mreply.get_reply_by_uid(reply_id)

        self.render(
            'tplite/reply/show_reply.html',
            cnt=reply.cnt_md,
            username=reply.user_name,
            date=reply.date,
            vote=reply.vote,
            uid=reply.uid,
            userinfo=self.userinfo,
        )

    # @tornado.web.authenticated
    # def add_one(self, id_reply):
    # # post_data = {}
    # # for key in self.request.arguments:
    # # post_data[key] = self.get_arguments(key)
    # # post_data['user_id'] = self.userinfo.uid
    #
    #     cur_count = self.mreply2user.insert_data(self.userinfo.uid, id_reply)
    #     if cur_count:
    #         self.mreply.update_vote(id_reply, cur_count)
    #
    #     out_dic = {'zan_count': cur_count}
    #     return json.dump(out_dic)

    @tornado.web.authenticated
    def zan(self, id_reply):
        post_data = {}
        for key in self.request.arguments:
            post_data[key] = self.get_arguments(key)
        post_data['user_id'] = self.userinfo.uid

        # zs = CabUser2Reply.select().where(CabUser2Reply.reply_id == id_reply).count()
        cur_count = self.mreply2user.insert_data(self.userinfo.uid, id_reply)

        if cur_count:
            self.mreply.update_vote(id_reply, cur_count)
            output = {
                'text_zan': cur_count,
            }
        else:
            output = {
                'text_zan': 0,
            }

        return json.dump(output, self)

    def delete_by_id(self, del_id):

        is_deleted = self.mreply2user.delete(del_id)

        # self.redirect('/post/{0}.html'.format(del_id))
        if is_deleted:

            output = {'del_zan': 1}
        else:
            output = {
                'del_zan': 0,
            }

        return json.dump(output, self)
예제 #58
0
class ChartHandler(BaseHandler):
    def initialize(self):
        self.mchart = MChart()
        self.muser = MUser()

        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 len(url_arr) == 1:
            self.show_geojson(url_str)
        elif len(url_arr) == 2:
            if url_arr[0] == 'add':
                self.to_add(url_arr[1])
            elif url_arr[0] == 'edit':
                self.to_edit(url_arr[1])

    def post(self, url_str=''):

        url_arr = self.parse_url(url_str)

        if len(url_arr) == 1:
            pass
        elif len(url_arr) == 2:
            if url_arr[0] == 'add':
                self.add(url_arr[1])
            elif url_arr[0] == 'edit':
                self.add(url_arr[1])

    def show_geojson(self, chart_id):

        chart_info = self.mchart.get_by_id(chart_id)

        if chart_info:
            pass
        else:
            self.redirect('/chart/add/{0}'.format(chart_id))
        kwd = {
            'pager': '',
            'url': self.request.uri,
            'tdesc': '',
            'login': 1 if self.get_current_user() else 0,

        }

        self.render('chart/view.html'.format(chart_id),
                    unescape=tornado.escape.xhtml_unescape,
                    chart_info=chart_info,
                    userinfo=self.userinfo, )
        # self.render('chart/h{0}.html'.format(chart_id),
        #             unescape=tornado.escape.xhtml_unescape,
        #             chart_info=chart_info,
        #             userinfo=self.userinfo, )

    @tornado.web.authenticated
    def to_add(self, chart_id):
        self.render('chart/add.html',
                    uid=chart_id)

    @tornado.web.authenticated
    def to_edit(self, chart_id):
        chart_info = self.mchart.get_by_id(chart_id)
        self.render('chart/edit.html',
                    unescape=tornado.escape.xhtml_unescape,
                    chart_info=chart_info,
                    )

    @tornado.web.authenticated
    def add(self, chart_id):
        if self.userinfo.privilege[4] == '1':
            pass
        else:
            return False
        post_data = {}
        for key in self.request.arguments:
            post_data[key] = self.get_arguments(key)

        self.mchart.add_or_update(chart_id, post_data)
        self.redirect('/chart/{0}'.format(chart_id))
예제 #59
0
class PostHandler(BaseHandler):
    def initialize(self):
        self.init()
        self.muser = MUser()
        self.mpost = MPost()
        self.mcat = MCatalog()
        self.cats = self.mcat.query_all()
        self.mspec = SpesubModel()
        self.specs = self.mspec.get_all()
        self.mpost_hist = MPostHist()
        self.mpost2catalog = MPost2Catalog()
        self.mpost2reply = MPost2Reply()
        self.mapp2tag = MPost2Label()
        self.mrel = MRelation()
        self.tmpl_router = 'post'

        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None

    def get(self, url_str=''):

        if url_str == '':
            self.recent()
        url_arr = url_str.split('/')

        if len(url_arr) == 1 and url_str.endswith('.html'):
            self.wiki(url_str.split('.')[0])

        elif url_str == 'add_document':
            self.to_add_document()
        elif url_str == 'recent':
            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=''):
        if url_str == '':
            return
        url_arr = url_str.split('/')

        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_document':
            self.user_add_post()
        elif url_arr[0] == 'add_document':
            self.user_add_post()
        else:
            self.redirect('/html/404.html')

    def recent(self, with_catalog=True, with_date=True):
        kwd = {
            'pager': '',
            'unescape': tornado.escape.xhtml_unescape,
            'title': '最近文档',
            'with_catalog': with_catalog,
            'with_date': with_date,
        }
        self.render('{0}/{1}/post_list.html'.format(self.tmpl_name, self.tmpl_router),
                    kwd=kwd,
                    view=self.mpost.query_recent(),
                    view_all=self.mpost.query_all(),
                    format_date=tools.format_date,
                    userinfo=self.userinfo,
                    )

    def refresh(self):

        kwd = {
            'pager': '',
            'title': '最近文档',
        }
        self.render('{0}/{1}/post_list.html'.format(self.tmpl_name, self.tmpl_router),
                    kwd=kwd,
                    userinfo=self.userinfo,
                    view=self.mpost.query_dated(10),
                    format_date=tools.format_date,
                    unescape=tornado.escape.xhtml_unescape, )

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

    def wiki(self, uid):
        dbdate = self.mpost.get_by_id(uid)
        if dbdate:
            self.mpost.update_view_count_by_uid(dbdate.uid)
            self.viewit(uid)
        else:

            self.to_add(uid)

    def to_add_document(self, ):
        kwd = {
            'pager': '',
            'cats': self.cats,
            'specs': self.specs,
            'uid': '',

        }
        self.render('{0}/{1}/post_add.html'.format(self.tmpl_name, self.tmpl_router),
                    topmenu='',
                    kwd=kwd,
                    tag_infos=self.mcat.query_all(),
                    userinfo=self.userinfo,
                    )

    @tornado.web.authenticated
    def to_add(self, uid):
        kwd = {
            'cats': self.cats,
            'specs': self.specs,
            'uid': uid,
            'pager': '',
        }
        self.render('{0}/{1}/post_add.html'.format(self.tmpl_name, self.tmpl_router),
                    kwd=kwd,
                    tag_infos=self.mcat.query_all(), )

    @tornado.web.authenticated
    def update(self, uid):
        raw_data = self.mpost.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()
        is_update_time = True if post_data['is_update_time'][0] == '1' else False
        self.update_tag(uid)
        self.mpost.update(uid, post_data, update_time=is_update_time)
        self.update_catalog(uid)
        self.mpost_hist.insert_data(raw_data)
        self.redirect('/post/{0}.html'.format(uid))

    def update_tag(self, signature):
        if self.userinfo.privilege[4] == '1':
            pass
        else:
            return False
        post_data = {}
        for key in self.request.arguments:
            post_data[key] = self.get_arguments(key)

        if 'tags' in post_data:
            pass
        else:
            return False
        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, uid):

        raw_data = self.mpost.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)

        current_infos = self.mpost2catalog.query_by_id(uid)
        new_tag_arr = []
        for key in ['tag1', 'tag2', 'tag3', 'tag4', 'tag5']:
            if key in post_data:
                pass
            else:
                continue
            if post_data[key][0] == '':
                pass
            else:
                new_tag_arr.append(int(post_data[key][0]))
                self.mpost2catalog.add_record(uid, post_data[key][0], int(key[-1]))

        for cur_info in current_infos:
            if cur_info.catalog.uid not in new_tag_arr:
                self.mpost2catalog.remove_relation(uid, cur_info.catalog)
                # .delete(cur_info.uid)

    @tornado.web.authenticated
    def to_modify(self, id_rec):
        a = self.mpost.get_by_id(id_rec)
        # 用户具有管理权限,
        # 或
        # 文章是用户自己发布的。
        if self.userinfo.privilege[2] == '1' or a.user_name == self.get_current_user():
            pass
        else:
            return False

        id_spec = a.id_spec
        kwd = {
            'pager': '',
            'cats': self.cats,
            'specs': self.specs,
            'id_spec': id_spec,
        }
        self.render('{0}/{1}/post_edit.html'.format(self.tmpl_name, self.tmpl_router),
                    kwd=kwd,
                    unescape=tornado.escape.xhtml_unescape,
                    tag_infos=self.mcat.query_all(),
                    app2label_info=self.mapp2tag.get_by_id(id_rec),
                    app2tag_info=self.mpost2catalog.query_by_id(id_rec),
                    dbrec=a,
                    userinfo=self.userinfo,
                    )

    def get_cat_str(self, cats):
        cat_arr = cats.split(',')
        out_str = ''
        for xx in self.cats:
            if str(xx.uid) in cat_arr:
                tmp_str = '''<li><a href="/category/{0}" style="margin:10px auto;"> {1} </a></li>
                '''.format(xx.slug, tornado.escape.xhtml_escape(xx.name))
                out_str += tmp_str

        return (out_str)

    def get_cat_name(self, id_cat):
        for x in self.cats:
            if x['id_cat'] == id_cat:
                return (x['name'])

    def viewit(self, post_id):

        last_post_id = self.get_secure_cookie('last_post_uid')
        if last_post_id:
            last_post_id = last_post_id.decode('utf-8')
        self.set_secure_cookie('last_post_uid', post_id)

        if last_post_id and self.mpost.get_by_id(last_post_id):
            self.add_relation(last_post_id, post_id)

        cats = self.mpost2catalog.query_catalog(post_id)
        replys = self.mpost2reply.get_by_id(post_id)
        tag_info = self.mapp2tag.get_by_id(post_id)

        rec = self.mpost.get_by_id(post_id)

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

        if cats.count() == 0:
            cat_id = ''
        else:
            cat_id = cats.get().catalog
        kwd = {
            'pager': '',
            'editable': self.editable(),
            'cat_id': cat_id
        }

        self.render('{0}/{1}/post_view.html'.format(self.tmpl_name, self.tmpl_router),
                    view=rec,
                    unescape=tornado.escape.xhtml_unescape,
                    kwd=kwd,
                    userinfo=self.userinfo,
                    tag_info=tag_info,
                    relations=self.mrel.get_app_relations(rec.uid),
                    replys=replys,

                    )

    def add_relation(self, f_uid, t_uid):
        if False == self.mpost.get_by_id(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

    @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.mpost.get_by_id(id_post)
        if cur_post_rec is None:
            uid = self.mpost.insert_data(id_post, post_data)
            self.update_tag(uid)
            self.update_catalog(uid)
        self.redirect('/post/{0}.html'.format(id_post))

    @tornado.web.authenticated
    def user_add_post(self):
        if self.userinfo.privilege[1] == '1':
            pass
        else:
            return False
        post_data = {}
        print(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_uu5d()
        while self.mpost.get_by_id(cur_uid):
            cur_uid = tools.get_uu5d()

        uid = self.mpost.insert_data(cur_uid, post_data)
        self.update_tag(uid)
        self.update_catalog(uid)
        self.redirect('/post/{0}.html'.format(cur_uid))

    @tornado.web.authenticated
    def delete(self, del_id):
        is_deleted = self.mpost.delete(del_id)
        if self.tmpl_router == "post":
            if is_deleted:
                self.redirect('/post/recent')
            else:
                return False
        else:

            if is_deleted:
                output = {
                    'del_info ': 1,
                }
            else:
                output = {
                    'del_info ': 0,
                }
            return json.dump(output, self)
예제 #60
0
class Post2ReplyHandler(BaseHandler):
    def initialize(self):
        self.init()
        self.muser = MUser()
        self.mreply = MReply()
        self.mreply2user = MReply2User()
        self.mpost2reply = MPost2Reply()

        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None

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

        if url_arr[0] == 'delete_reply':
            self.delete(url_arr[1])
        elif url_arr[0] == 'zan':
            self.zan(url_arr[1])

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

        if url_arr[0] == 'add':
            self.add_comment(url_arr[1])

    @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)

        if comment_uid:
            self.mpost2reply.insert_data(id_post, comment_uid)
            output = {
                'pinglun': comment_uid,
            }
        else:
            output = {
                'pinglun': 0,
            }

        return json.dump(output, self)

    @tornado.web.authenticated
    def zan(self, id_reply):
        post_data = {}
        for key in self.request.arguments:
            post_data[key] = self.get_arguments(key)
        post_data['user_id'] = self.userinfo.uid

        cur_count = self.mreply2user.insert_data(self.userinfo.uid, id_reply)

        if cur_count:
            self.mreply.update_vote(id_reply, cur_count)
            output = {
                'text_zan': cur_count,
            }
        else:
            output = {
                'text_zan': 0,
            }

        return json.dump(output, self)

    def delete(self, del_id):
        if self.mreply2user.delete(del_id):
            output = {'del_zan': 1}
        else:
            output = {
                'del_zan': 0,
            }

        return json.dump(output, self)