Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 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/')
Ejemplo n.º 4
0
Archivo: index.py Proyecto: supor/vlog
 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/')
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
0
 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
Ejemplo n.º 8
0
 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