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)
class SpecialHandler(BaseHandler): 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 def get(self, url_str=""): url_arr = self.parse_url(url_str) if url_str == '': self.index() elif url_str == 'add': self.to_add() elif len(url_arr) == 1: self.list(url_str) elif len(url_arr) == 2 and url_arr[1] == 'edit': self.to_edit(url_arr[0]) elif url_arr[0] == 'delete': self.delete(url_arr[1]) else: self.render('html/404.html') def post(self, url_str=''): url_arr = self.parse_url(url_str) if url_str == 'add': self.add() elif len(url_arr) == 2 and url_arr[1] == 'edit': self.edit(url_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) if 'slug' in post_data: pass else: self.set_status(400) return False 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) if self.mspec.get_by_slug(post_data['slug'][0]) is None: self.mspec.addata(post_data) else: self.set_status(400) return False @tornado.web.authenticated def to_edit(self, uid): spec_rec = self.mspec.get_by_id(uid) self.render('{0}/spec/edit.html'.format(self.tmpl_name), spec_rec=spec_rec, cfg = config.cfg, ) @tornado.web.authenticated def to_add(self): self.render('{0}/spec/add.html'.format(self.tmpl_name)) def list(self, spec_slug): ''' 列出专题信息,按某一分类 ''' page_rec = self.mspec.get_by_slug(spec_slug) kwd = { 'editable': self.editable() } self.render('{0}/spec/list.html'.format(self.tmpl_name), kwd=kwd, spec=page_rec, unescape=tornado.escape.xhtml_unescape, spec_recs=self.mpost.query_by_spec(page_rec.uid), cfg = config.cfg, ) def index(self): kwd = { 'editable': self.editable() } self.render('{0}/spec/index.html'.format(self.tmpl_name), kwd=kwd, spec_recs=self.mspec.get_all(), cfg = config.cfg, ) @tornado.web.authenticated def delete(self, del_id): is_deleted = self.mspec.delete(del_id) if is_deleted: self.redirect('/spec/') else: return False
class SpecHandler(BaseHandler): def initialize(self): self.mpage = MPage() self.mdb = MPost() self.mcat = MCatalog() self.cats = self.mcat.query_all() self.mspec = SpesubModel() 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() self.render('tplite/spec/add.html', cat_recs=uuu) 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) recs = self.mdb.query_by_spec(page_rec.id) kwd = { # 'spec': content, # 'view': recs, 'editable': self.editable() } self.render('tplite/spec/list.html', kwd=kwd, spec=page_rec, unescape=tornado.escape.xhtml_unescape, spec_recs=recs) 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)
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): print('to_add') self.render('tplite/spec/add.html') def list(self, spec_slug): ''' 列出专题信息,按某一分类 ''' page_rec = self.mspec.get_by_slug(spec_slug) 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 = { 'editable': self.editable() } spec_recs = self.mspec.get_all() self.render('tplite/spec/index.html', spec_recs=spec_recs, kwd=kwd)
class SpecialHandler(BaseHandler): 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 def get(self, url_str=""): url_str = url_str.strip() ip_arr = [] if len(url_str) > 0: ip_arr = url_str.split(r'/') if url_str == '': self.index() elif url_str == 'add': self.to_add() elif len(ip_arr) == 1: self.list(url_str) elif len(ip_arr) == 2 and ip_arr[1] == 'edit': self.to_edit(ip_arr[0]) elif ip_arr[0] == 'delete': self.delete(ip_arr[1]) else: self.render('html/404.html') def post(self, input=''): if len(input) > 0: ip_arr = input.split('/') else: return False if 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('{0}/spec/edit.html'.format(self.tmpl_name), spec_rec=spec_rec) @tornado.web.authenticated def to_add(self): self.render('{0}/spec/add.html'.format(self.tmpl_name)) def list(self, spec_slug): ''' 列出专题信息,按某一分类 ''' page_rec = self.mspec.get_by_slug(spec_slug) kwd = {'editable': self.editable()} self.render( '{0}/spec/list.html'.format(self.tmpl_name), kwd=kwd, spec=page_rec, unescape=tornado.escape.xhtml_unescape, spec_recs=self.mpost.query_by_spec(page_rec.uid), ) def index(self): kwd = {'editable': self.editable()} self.render( '{0}/spec/index.html'.format(self.tmpl_name), kwd=kwd, spec_recs=self.mspec.get_all(), ) @tornado.web.authenticated def delete(self, del_id): is_deleted = self.mspec.delete(del_id) if is_deleted: self.redirect('/spec/') else: return False