Пример #1
0
 def delete(self, fileid):
     try:
         userfile = DBSession.query(UserFile).filter_by(id=fileid).one()
     except:
         return redirect("/")
     DBSession.delete(userfile)
     return redirect("/")
Пример #2
0
 def view(self, fileid):
     try:
         userfile = DBSession.query(UserFile).filter_by(id=fileid).one()
     except:
         redirect("/")
     content_types = {
         'display': {'.png': 'image/jpeg', '.jpeg':'image/jpeg', '.jpg':'image/jpeg', '.gif':'image/jpeg', '.txt': 'text/plain'},
         'download': {'.pdf':'application/pdf', '.zip':'application/zip', '.rar':'application/x-rar-compressed'}
     }
     for file_type in content_types['display']:
         if userfile.filename.endswith(file_type):
             response.headers["Content-Type"] = content_types['display'][file_type]
     for file_type in content_types['download']:
         if userfile.filename.endswith(file_type):
             response.headers["Content-Type"] = content_types['download'][file_type]
             response.headers["Content-Disposition"] = 'attachment; filename="'+userfile.filename+'"'
     if userfile.filename.find(".") == -1:
         response.headers["Content-Type"] = "text/plain"
     return userfile.filecontent
Пример #3
0
 def index(self):
     current_files = DBSession.query(UserFile).all()
     return dict(current_files=current_files)
Пример #4
0
 def test_query_obj(self):
     obj = DBSession.query(self.klass).one()
     for key, value in self.attrs.iteritems():
         assert_equals(getattr(obj, key), value)