def upload(self, upload_file, filename, abspath=False): file_md5 = md5(upload_file) path, filename, create = self.get_filename(filename, file_md5) if create: with open(path, 'wb') as f: f.write(upload_file) url_path = self.url_format.format(filename) self.option.set_option(filename, url_path) if abspath: return path return urllib.quote(url_path)
def upload(self, upload_file, filename, abspath = False): file_md5 = md5(upload_file) path, filename, create = self.get_filename(filename, file_md5) if create: with open(path, 'wb') as f: f.write(upload_file) url_path = self.url_format.format(filename) self.option.set_option(filename, url_path) if abspath: return path return urllib.quote(url_path)
def get(self, index): index = index if index else 1 data = Logic.note.get_notes(index) notes = data.get("data") pageinfo = data.get("pageinfo") gravatar = None if self.uid and self.username: admin = Logic.user.check_has_admin().get("email") gravatar = md5(admin) self.render("notes.jinja", notes = notes, title = u"便签", gravatar = gravatar, pageinfo = pageinfo, basepath = r'/notes/p/')
def get(self, index): index = index if index else 1 data = Logic.note.get_notes(index) notes = data.get("data") pageinfo = data.get("pageinfo") gravatar = None if self.uid and self.username: admin = Logic.user.check_has_admin().get("email") gravatar = md5(admin) self.render("notes.jinja", notes=notes, title=u"便签", gravatar=gravatar, pageinfo=pageinfo, basepath=r'/notes/p/')
def get_filename(self, filename, file_md5, num = None): newfilename = filename if num: split = filename.split('.') if len(split) >= 2: newfilename = '.'.join(split[0:-1]) + str(num) +'.'+ split[-1] else: newfilename = filename + str(num) path = os.path.join(self.root, newfilename) if os.path.exists(path): with open(path, 'rb') as f: old_md5 = md5(f.read()) if old_md5 == file_md5: return path, newfilename, False num = num+1 if num else 1 return self.get_filename(filename, num) return path, newfilename, True
def get_filename(self, filename, file_md5, num=None): newfilename = filename if num: split = filename.split('.') if len(split) >= 2: newfilename = '.'.join( split[0:-1]) + str(num) + '.' + split[-1] else: newfilename = filename + str(num) path = os.path.join(self.root, newfilename) if os.path.exists(path): with open(path, 'rb') as f: old_md5 = md5(f.read()) if old_md5 == file_md5: return path, newfilename, False num = num + 1 if num else 1 return self.get_filename(filename, num) return path, newfilename, True
def _insert_info(self, comment): email = comment.get('email', '') comment['gravatar'] = md5(email) content = comment.get('content') comment['short_content'] = utf8sub(content, 0, 20) return comment