def initialize(self): self.mpic = MEntry()
class EntityHandler(tornado.web.RequestHandler): def initialize(self): self.mpic = MEntry() def get(self, url_str=''): if url_str == '': return if url_str == 'add': self.to_add() elif (url_str == 'list' or url_str == ''): self.list() elif len(url_str) > 36: self.view(url_str) else: self.render('html/404.html') def post(self, url_str=''): if url_str == '': return if url_str == 'add' or url_str == '': self.add_pic() else: self.render('/html/404.html') def list(self): recs = self.mpic.getall() kwd = { 'pager': '', } self.render('tplite/entry/entry_list.html', imgs=recs, kwd=kwd) def to_add(self): kwd = { 'pager': '', } self.render('tplite/entry/entry_add.html', kwd=kwd) def add_pic(self): post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) file_dict_list = self.request.files['file'] for file_dict in file_dict_list: filename = file_dict["filename"] (qian, hou) = os.path.splitext(filename) signature = str(uuid.uuid1()) outfilename = '{0}{1}'.format(signature, hou) outpath = 'static/upload/{0}'.format(signature[:2]) if os.path.exists(outpath): pass else: os.mkdir(outpath) with open(os.path.join(outpath, outfilename), "wb") as f: f.write(file_dict["body"]) path_save = os.path.join(signature[:2], outfilename) self.mpic.insert_data(signature, path_save) self.redirect('/entry/{0}'.format(path_save)) def view(self, outfilename): kwd = { 'pager': '', } self.render('tplite/entry/entry_view.html', filename=outfilename, kwd=kwd)
def initialize(self): self.mpic = MEntry() self.tmpl_name = config.torlite_template_name
def initialize(self): self.mpic = MEntry() self.tmpl_name= config.torlite_template_name
class EntityHandler(tornado.web.RequestHandler): def initialize(self): self.mpic = MEntry() self.tmpl_name = config.torlite_template_name def get(self, url_str=''): if url_str == '': return if url_str == 'add': self.to_add() elif (url_str == 'list' or url_str == ''): self.list() elif len(url_str) > 36: self.view(url_str) else: self.render('html/404.html') def post(self, url_str=''): if url_str == 'add' or url_str == '': print('got it') self.add_pic() else: self.render('/html/404.html') def list(self): recs = self.mpic.getall() kwd = { 'pager': '', } self.render('{0}/entry/entry_list.html'.format(self.tmpl_name), imgs=recs, kwd=kwd) def to_add(self): kwd = { 'pager': '', } self.render('{0}/entry/entry_add.html'.format(self.tmpl_name), kwd=kwd) def add_pic(self): post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) file_dict_list = self.request.files['file'] for file_dict in file_dict_list: filename = file_dict["filename"] (qian, hou) = os.path.splitext(filename) signature = str(uuid.uuid1()) outfilename = '{0}{1}'.format(signature, hou) outpath = 'static/upload/{0}'.format(signature[:2]) if os.path.exists(outpath): pass else: os.mkdir(outpath) with open(os.path.join(outpath, outfilename), "wb") as f: f.write(file_dict["body"]) path_save = os.path.join(signature[:2], outfilename) self.mpic.insert_data(signature, path_save) self.redirect('/entry/{0}'.format(path_save)) def view(self, outfilename): kwd = { 'pager': '', } self.render('{0}/entry/entry_view.html'.format(self.tmpl_name), filename=outfilename, kwd=kwd)