def post(self, username): user = auth(session, required=True) if not 'avatar' in request.files: return {}, 400 upload = request.files['avatar'] revision = Revision() revision.add(upload) existing = Revision.query.filter( Revision.hash == revision.hash ).first() if existing: # We already have this file user.avatar = existing if not existing in user.revisions: user.revisions.append(existing) db.session.add(existing) else: user.avatar = revision user.revisions.append(revision) db.session.add(revision) db.session.add(user) db.session.commit() return redirect("/")
def post(self, username): user = auth(session, required=True) if not 'revision' in request.files: return {}, 400 upload = request.files['revision'] revision = Revision() revision.add(upload) if user.public: revision.public = True existing = Revision.query.filter( Revision.hash == revision.hash ).first() if existing: # We already have this file if not existing in user.revisions: user.revisions.append(existing) db.session.add(existing) else: user.revisions.append(revision) db.session.add(revision) db.session.add(user) db.session.commit() if revision.public: threads = [] for router in app.routes.values(): threads.append(gevent.spawn(router.__setitem__, revision, revision)) gevent.joinall(threads) return redirect("/")