def get(self): StaticData.init(self) self.title = 'Dashboard Edit' pid = self.get_argument('pid', default=None) if pid == None: page = Page('','') page.pid = None else: page = self.session.query(Page).filter(Page.pid == pid).first() self.render('admin_editpage.html', active2 = 'class="active"', page = page) self.session.close()
def post(self): self.title = 'Dashboard Edit' StaticData.init(self) pid = self.get_argument('pid', default='None') print pid, type(pid) ptitle = self.get_argument('ptitle', default='') pcontent = self.get_argument('pcontent', default='') if pid == 'None': page = Page(ptitle, pcontent) if 'file' in self.request.files: file_dict_list = self.request.files['file'] for file_dict in file_dict_list: filename = nameRewrite(file_dict["filename"]).encode('utf8') data = file_dict["body"] image = Image.open(StringIO(data)) image.save(page_path + filename, quality=150) ''' with open(page_path + filename, 'w') as f: f.write(data) print filename''' page.ppic = '/static/page/' + filename self.session.add(page) self.session.commit() else: page = self.session.query(Page).filter(Page.pid == pid).first() page.ptitle = ptitle page.pcontent = pcontent if 'file' in self.request.files: file_dict_list = self.request.files['file'] for file_dict in file_dict_list: filename = nameRewrite(file_dict["filename"]).encode('utf8') if page.ppic[:len(filename)-10] != '/static/page/' + filename[:len(filename)-10]: print page.ppic[:len(filename)-10],'/static/page/' + filename[:len(filename)-10] data = file_dict["body"] image = Image.open(StringIO(data)) image.save(avatar_path + filename, quality=150) page.ppic = '/static/page/' + filename page.pchgtime = datetime.now() self.session.commit() self.write('<script language="javascript">alert("提交成功");self.location="/admin/editpage"</script>') self.session.close()