def like(file_id): # FIXME: if the object isn't found redirect adding an error parameter DB.update("photos", {"_id": ObjectId(file_id)}, {'$inc': { "counter_like": 1 }}) # FIXME: add some return return {}
def create_app(config=None): app = Flask(__name__) session = Session() app.config['SESSION_TYPE'] = 'filesystem' app.config['SECRET_KEY'] = SECRET_KEY app.config.from_object("app.config") session.init_app(app) DB.init() Bootstrap(app) register_blueprints(app) return app
def review(action, filename): if action == "accept": print("file " + filename + " accepted") # FIXME: if the object isn't found redirect adding an error parameter DB.update("photos", {"filename": filename}, {'$set': { "accepted": True }}) elif action == "reject": print("file " + filename + " rejected") # FIXME: if the object isn't found redirect adding an error parameter DB.delete("photos", {"filename": filename}) return redirect(url_for('main.pending'))
def insert(self): inserted_id = DB.insert(collection='photos', data=self.json()) if inserted_id: # FIXME: Images must be stored on Amazon S3 # self.photo_data.save(path.join('/tmp/uploads', self.uuid_filename)) return True return False
def pending(): collection = DB.collection("photos") photos = collection.find({'accepted': False}).sort('_id', 1) count = photos.count() return render_template('album.html', photos=photos, storage_url=str(S3_LOCATION), total=count, to_review=True)
def login(): (success, resp) = DB.validate("users", { 'email': request.form['email'], 'password': request.form['password'] }) if success: session['email'] = request.form['email'] return redirect(url_for('main.index', user_id=resp)) return render_template('sign-in.html', error=resp)
def index(): if 'email' in session: photos_collection = DB.collection("photos") if photos_collection.count() == 0: return render_template('album.html', total=0, to_review=False) sort_arg = request.args.get("sort") sort_filter = "created_at" sort_direction = -1 if sort_arg: if sort_arg.lower() == "oldest": sort_direction = 1 if sort_arg.lower() == "rating": sort_filter = "counter_like" sort_direction = -1 sort_params = [(sort_filter, sort_direction)] query = {'accepted': True} photos_id = DB.find_sort("photos", query, sort_params) if photos_id.count() == 0: return render_template('album.html', total=0, to_review=False) # request.headers["Cache-Control"] = "no-cache, no-store, must-revalidate" # request.headers["Pragma"] = "no-cache" # request.headers["Expires"] = "0" # request.headers['Cache-Control'] = 'public, max-age=0' api_address = str(API_ADDRESS) + ':' + str(PORT) return render_template('album.html', photos=photos_id, api_address=api_address, storage_url=str(S3_LOCATION), total=photos_id.count(), to_review=False) return render_template('sign-in.html')
def insert(self): result = DB.insert("users", data=self.json()) if result.inserted_id: return True return False