示例#1
0
 def POST(self, path):
     issue = web.ctx.site.get(path)
     audios = get_files('music'+issue.key)
     x = web.input(audio={}, overwrite=0)
     if x['audio'].filename:
         filename = '_'.join(os.path.basename(x['audio'].filename).split('\\')[-1].split())
     else:
         return render.show_audios(issue, audios, 'Please select a file to upload')
     dir_path = os.path.join('static/music', x['issue.key'].lstrip('/')) #Path is a directory where we save particular file. 
     file_path = os.path.join(dir_path, filename.lstrip('/'))
     filedata = x['audio'].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_audios(issue, audios, msg)
     else:
         f = open(file_path, 'w')
         f.write(filedata)
         f.close()
         msg = "File is saved."
         return web.seeother('/dashboard'+path+'/audio')
示例#2
0
 def GET(self, path):
         issue = web.ctx.site.get(path)
         audios = get_files('music'+issue.key)
         return render.show_audios(issue, audios)