def delete(id): record = db_session.query(File).get(id) if record is not None: handler = get_handler_instance(record) handler.delete() db_session.delete(record) db_session.commit() return '', 204 return '', 404
def get_file_data(limit=50, offset=0): files = [] if current_user.is_authenticated: query = db_session.query(File) else: query = db_session.query(File).filter_by(access='public') files = query.order_by(File.id.desc()).limit(limit).offset(offset).all() json = [] handlers = [] for record in files: json.append(file_json(record)) handlers.append(get_handler_instance(record)) return (json, handlers)
def view(key): record = db_session.query(File).filter_by(key=key).first() if record is not None and can_view_file(record): record.views += 1 db_session.add(record) db_session.commit() handler = get_handler_instance(record) return render_template( handler.template, current_path="%s%s" % (app.config['ROOT_WEB_PATH'], request.path), static_web_path=app.config['STATIC_WEB_PATH'], upload_web_path=app.config['UPLOAD_WEB_PATH'], root_web_path=app.config['ROOT_WEB_PATH'], handler=handler, ) abort(404)
db_session.add(user) db_session.commit() print 'User created: %r' % user.id if sys.argv[1] == 'init_db': from spice import app from spice.database import init_db init_db() print "Database init" if sys.argv[1] == 'process': from spice.models import File from spice.database import db_session from spice.handlers import get_handler_instance files = db_session.query(File).order_by(File.id.desc()).all() for record in files: handler = get_handler_instance(record) handler.process() db_session.add(handler.record) db_session.commit() else: from spice import app app.run(debug=True, host='0.0.0.0', port=8080) import spice.views