def commit(self): s = Session() session['messages'] = [] paths = [] message = request.params.get("message", "Web commit") db_files = s.query(Upload).filter(Upload.status == u"Moderated").all() for db_file in db_files: destination = get_path(None, db_file.destination) if destination == "Invalid path": session['messages'] += ["Invalid destination for the file %s" % db_file.name] session.save() return redirect_to(url_for(controller="moderation")) currentpath = os.path.join(get_path("moderation"), db_file.new_name) #os.sep is to fix a bug shutil.move(currentpath, destination+os.sep) oldpath = os.path.join(destination, db_file.new_name) path = os.path.join(destination, db_file.name) os.rename(oldpath, path) #TODO error handling path = os.path.join(db_file.destination, db_file.name) add(path, Session()) paths += [path] session['messages'] += ["%s is commit" % db_file.name] session.save() s.delete(db_file) s.commit() commit(paths, message, session['user'], Session()) return redirect_to(url_for(controller="moderation"))
def rejected(self): s = Session() new_name = request.params.get('name', None) if new_name is None: abort(404) db_file = s.query(Upload).get(new_name) if db_file is None: session['messages'] = ["Invalid file"] session.save() return redirect_to(url_for(controller="moderation")) path = os.path.join(get_path("moderation"), db_file.new_name) #TODO error handeling if os.path.exists(path): os.remove(path) s.delete(db_file) s.commit() session['messages'] = ["File rejected"] session.save() return redirect_to(url_for(controller="moderation"))
def commit(self): s = Session() session['messages'] = [] paths = [] message = request.params.get("message", "Web commit") db_files = s.query(Upload).filter(Upload.status == u"Moderated").all() for db_file in db_files: destination = get_path(None, db_file.destination) if destination == "Invalid path": session['messages'] += [ "Invalid destination for the file %s" % db_file.name ] session.save() return redirect_to(url_for(controller="moderation")) currentpath = os.path.join(get_path("moderation"), db_file.new_name) #os.sep is to fix a bug shutil.move(currentpath, destination + os.sep) oldpath = os.path.join(destination, db_file.new_name) path = os.path.join(destination, db_file.name) os.rename(oldpath, path) #TODO error handling path = os.path.join(db_file.destination, db_file.name) add(path, Session()) paths += [path] session['messages'] += ["%s is commit" % db_file.name] session.save() s.delete(db_file) s.commit() commit(paths, message, session['user'], Session()) return redirect_to(url_for(controller="moderation"))
def servefile(self, new_name, name): path = get_path("moderation") extList = ["jpeg", "jpg", "png", "gif"] s = Session() db_file = s.query(Upload).get(new_name) if db_file is None: abort(404) file_type = db_file.file_type.strip('.') if file_type in extList: response.content_type = "image/" + file_type else: response.content_type = "application/octet-stream" path = os.path.join(path, new_name) f = open(path, 'r') return f