def edit_restaurant(id): form = AddRestaurantForm() if request.method == 'POST': if form.validate_on_submit(): if h.post_interval_exists(): return render_template('restaurant_form.html', form=form, id=id) restaurant = Restaurant.query.filter_by(id=id) for entry in form: if entry.id != "csrf_token": restaurant.update({entry.id: form[entry.id].data}) restaurant.update({'last_edited': int(time())}) restaurant.update({'last_editor': session['user_id']}) r = Restaurant.query.get(id) r.editors.append(User.query.get(session['user_id'])) h.update_score(app.config['EDIT_RESTAURANT_SCORE']) db.session.commit() flash('Thank you for your update!') return redirect(url_for('restaurant_profile', id=id)) return render_template('restaurant_form.html', form=form, id=id) if request.method == 'GET': restaurant = Restaurant.query.filter_by(id=id).first() if restaurant is None: abort(404) restaurant = h.rowtodict(restaurant) for entry in form: if entry.id != "csrf_token": form[entry.id].data = str(restaurant[entry.id]) return render_template('restaurant_form.html', form=form, id=id)
def edit_dish(restaurant_id, dish_id): form = AddDishForm() if request.method == 'POST': if form.validate_on_submit(): if h.post_interval_exists(): return render_template('dish_form.html', form=form, id=restaurant_id, dish_id=dish_id) dish = Dish.query.filter_by(id=dish_id) for entry in form: if entry.id in app.config['CONTENTS']: dish.update({entry.id: h.stb(form[entry.id].data)}) elif entry.id == 'price' and form[entry.id].data: dish.update({ entry.id: currency(float(form[entry.id].data), grouping=True) }) elif entry.id != 'csrf_token': dish.update({entry.id: form[entry.id].data}) dish.update({'last_edited': int(time())}) dish.update({'last_editor': session['user_id']}) d = Dish.query.get(dish_id) d.editors.append(User.query.get(session['user_id'])) h.update_score(app.config['EDIT_DISH_SCORE']) db.session.commit() flash('Thank you for your update!') return redirect(url_for('restaurant_profile', id=restaurant_id)) return render_template('dish_form.html', form=form, id=restaurant_id, dish_id=dish_id) if request.method == 'GET': dish = Dish.query.filter_by(id=dish_id).first() restaurant = Restaurant.query.filter_by(id=restaurant_id).first() if dish is None: abort(404) dish = h.rowtodict(dish) for entry in form: if entry.id == 'price': form[entry.id].data = str(dish[entry.id]).replace('$', '').\ replace(',', '') elif entry.id != "csrf_token": form[entry.id].data = str(dish[entry.id]) return render_template('dish_form.html', form=form, id=restaurant_id, dish_id=dish_id, restaurant=restaurant)
def user_profile(id): user = User.query.filter_by(id=id).first() if user is None: abort(404) user_dict = h.rowtodict(user) month_day_year = User.query.filter_by(id=id).first().\ date.strftime("%B %d, %Y") user_opts = [(entry, user_dict[entry]) for entry in app.config['CONTENTS']] return render_template('user_profile.html', month_day_year=month_day_year, user=user, user_opts=user_opts)
def edit_user(id): user = User.query.filter_by(id=id).first() if user is None or id != str(g.user.id): abort(404) month_day_year = User.query.filter_by(id=id).first().\ date.strftime("%B %d, %Y") form = EditUserForm() if request.method == 'POST': if form.validate_on_submit(): if h.post_interval_exists(): return render_template('edit_user.html', form=form, month_day_year=month_day_year, user=user) user = User.query.filter_by(id=id) for entry in form: if entry.id in app.config['CONTENTS']: user.update({entry.id: h.stb(form[entry.id].data)}) elif entry.id != 'csrf_token': user.update({entry.id: form[entry.id].data}) user.update({'last_edited': int(time())}) user.update({'last_activity': int(time())}) user.update({'about': profanity.censor(form['about'].data)}) db.session.commit() flash('Thank you for your update!') return redirect(url_for('user_profile', id=id)) if request.method == 'GET': user_dict = h.rowtodict(user) for entry in form: if entry.id == "username": if user.username: form.username.data = user.username else: form.username.data = user.name elif entry.id == "about": form.about.data = user.about elif entry.id != "csrf_token": form[entry.id].data = str(user_dict[entry.id]) return render_template('edit_user.html', form=form, month_day_year=month_day_year, user=user)
def db_check_value(context, value, column, table, id): if table == "restaurants": entry = rowtodict(Restaurant.query.filter_by(id=id).first()) assert str(entry[column]) != value elif table == "dishes": entry = rowtodict(Dish.query.filter_by(id=id).first()) assert str(entry[column]) != value elif table == "users": entry = rowtodict(User.query.filter_by(id=id).first()) assert str(entry[column]) != value elif table == "comments": entry = rowtodict(Comment.query.filter_by(id=id).first()) assert str(entry[column]) != value elif table == "locations": entry = rowtodict(Location.query.filter_by(id=id).first()) assert str(entry[column]) != value elif table == "issues": entry = rowtodict(Issue.query.filter_by(id=id).first()) assert str(entry[column]) != value