Beispiel #1
0
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')
Beispiel #2
0
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)
Beispiel #3
0
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')
Beispiel #4
0
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)
Beispiel #5
0
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)
Beispiel #6
0
def delete_store(store_id):
    store = Store.get_by_id(store_id)
    store.delete()
    return redirect(url_for('admin.list_stores'))
Beispiel #7
0
def list_stores():
    stores = Store.get_all()
    return render_template('admin_stores.html', stores=stores)
Beispiel #8
0
def index():
    stores = Store.get_all()
    return render_template('store.html', stores=stores)
Beispiel #9
0
 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)