예제 #1
0
 def POST(self, path):
     issue = web.ctx.site.get(path)
     images = get_files('images'+issue.key)
     x = web.input(image={}, overwrite=0)
     if x['image'].filename:
         filename = '_'.join(os.path.basename(x['image'].filename).split('\\')[-1].split())
     else:
         return render.show_images(issue, images, 'Please select a file to upload')
     dir_path = os.path.join('static/images', x['issue.key'].lstrip('/')) #Path is a directory where we save particular file. 
     file_path = os.path.join(dir_path, filename.lstrip('/'))
     filedata = x['image'].value
     if not os.path.isdir(dir_path):
         os.makedirs(dir_path)
     if not int(x['overwrite']) and os.path.isfile(file_path):
         msg = "NOTE: File with this name already exists. Check overwrite and try again"
         return render.show_images(issue, images, msg)
     else:
         f = open(file_path, 'w')
         f.write(filedata)
         f.close()
         msg = "File is saved."
         return web.seeother('/dashboard'+path+'/images')
예제 #2
0
 def GET(self, path):
         issue = web.ctx.site.get(path)
         images = get_files('images'+issue.key)
         return render.show_images(issue, images)