def upload_photo(): user = getUser(USERNAME) points = getUserPoints(USERNAME) form = UploadForm(request.form) action = request.form['action'] ps = photoNum() if request.method == 'POST' and form.validate(): file = request.files['file'] if file and allowed_file(file.filename): square = form.square.data title = form.title.data description = form.description.data weather = form.weather.data type = None if(weather in GOOD): type = 'good' else: type ='bad' parsename = str(square) + '.jpg' filename = secure_filename(parsename) path = UPLOAD_FOLDER + type + "/" + filename file.save(path) photo = Photo(title, user.userid, 0, description, path, square,type,weather) db_session.add(photo) ex = photoExists(type,square) if ex==False: flash('+50 points. The new photo was successfully posted.') points +=50 else: flash('+20 points. The new photo was successfully updated.') points +=20 db_session.query(User).filter_by(userid=USERNAME).update({'points': points}) db_session.commit() return redirect(url_for('home')) return render_template('upload.html',type=action, points=points, user=user, form=form, ps=ps, load=ps/CAPACITY)