def delete_place(category_id, place_id): """Delete place page. User must have created place to delete.""" cat = db.get_cat(category_id) place = db.get_place(place_id) user_id = login_session['user_id'] if place.user_id != user_id: return redirect(url_for('main_page')) if creator.id != login_session['user_id']: flash("You cannot delete this Type.\ This Type belongs to % s" % creator.name) return redirect(url_for('show_place')) if request.method == 'POST': delete_confirmation = request.form['delete'] if delete_confirmation == 'yes': db.delete_place(place) flash('place entry deleted.') return redirect(url_for('show_category', category_id=cat.id)) else: return render_template( 'delete_place.html', category=cat, place=place )
def show_place(category_id, place_id): """Specific place page. Shows desc.""" categories = db.get_all_categories() cat = db.get_cat(category_id) place = db.get_place(place_id) return render_template('place.html', categories=categories, category=cat, place=place)
def edit_place(category_id, place_id): """Edit place page. User must have created the place to edit.""" categories = db.get_all_categories() cat = db.get_cat(category_id) place = db.get_place(place_id) user_id = login_session['user_id'] if place.user_id != user_id: return redirect(url_for('main_page')) if creator.id != login_session['user_id']: flash("You cannot edit this Type.\ This Type belongs to % s" % creator.name) return redirect(url_for('show_place')) if request.method == 'POST': name = request.form['name'] description = request.form['description'] category = request.form['category'] field_vals = {} if name and description: flash('place edited!') db.edit_place(place, name, description, db.get_cat_id(category)) time.sleep(1) return redirect(url_for( 'show_place', category_id=category_id, place_id=place_id ) ) else: field_vals['default_cat'] = category flash('Invalid input! Must enter values.') field_vals['input_name'] = name field_vals['input_description'] = description return render_template('new_place.html', categories=categories, **field_vals) else: return render_template( 'edit_place.html', category_id=category_id, place_id=place_id, categories=categories, input_name=place.name, input_description=place.description, default_cat=cat.name )
def place_json(category_id, place_id): place = db.get_place(place_id) return jsonify(Place=place.serialize)