def create_store(): if request.method == 'POST': name = request.form['name'] store = Store.get_by_name(name) if store is None: store = Store(name=name) store.save() return redirect(url_for('admin.list_stores')) else: flash('Store already exists', 'danger') return redirect(url_for('admin.create_store')) return render_template('admin_new_store.html')
def edit_store(store_id): store = Store.get_by_id(store_id) if request.method == 'POST': store.name = request.form['name'] store.save() return redirect(url_for('admin.list_stores')) return render_template('admin_edit_store.html', store=store)
def create_dealer(): if request.method == 'POST': name = request.form['name'] store_name = request.form['store_name'] store = Store.get_by_name(store_name) if store is None: flash('Store does not exist', 'danger') return redirect(url_for('admin.create_dealer')) else: dealer = Dealer(name=name) store.dealers.append(dealer) dealer.save() return redirect(url_for('admin.list_dealers')) return render_template('admin_new_dealer.html')
def store(store_id): stores = Store.get_all() shop = Store.get_by_id(store_id) dealers = Dealer.get_by_store(shop.id) if request.method == 'POST': customer_name = request.form['customer_name'] customer_email = request.form['customer_email'] dealer = request.form['dealer'] rating = request.form['rating'] comments = request.form['comments'] if not customer_email or customer_name or dealer: flash('Please enter required fields', 'danger') return redirect(url_for('store.store', store_id=store_id)) feedback = Feedback(customer_name=customer_name, customer_email=customer_email, dealer=dealer, rating=rating, comments=comments) feedback.save() return render_template('success.html', feedback=feedback) return render_template('store_opinion.html', shop=shop, dealers=dealers, stores=stores)
def list_dealers(): stores = Store.get_all() dealers = Dealer.get_all() for dealer in dealers: store = dealer.store return render_template('admin_dealers.html', store=store, dealers=dealers)
def delete_store(store_id): store = Store.get_by_id(store_id) store.delete() return redirect(url_for('admin.list_stores'))
def list_stores(): stores = Store.get_all() return render_template('admin_stores.html', stores=stores)
def index(): stores = Store.get_all() return render_template('store.html', stores=stores)
def mutate(self, info, name, user_id): store = Store(name=name, user_id=user_id) if store: db_session.add(store) db_session.commit() return CreateStore(store=store)