コード例 #1
0
ファイル: routes.py プロジェクト: xiluna/forms-grocery-store
def new_store():
    form = GroceryStoreForm()
    if form.validate_on_submit():
        add_store = GroceryStore(title=form.title.data,
                                 address=form.address.data,
                                 created_by_id=current_user.username)
        db.session.add(add_store)
        db.session.commit()
        flash('New store added')
        return redirect(url_for('main.store_detail', store_id=add_store.id))
    return render_template('new_store.html', form=form)
コード例 #2
0
ファイル: routes.py プロジェクト: xiluna/forms-grocery-store
def store_detail(store_id):
    store = GroceryStore.query.get(store_id)
    form = GroceryStoreForm(obj=store)
    if form.validate_on_submit():
        store.title = form.title.data
        store.address = form.address.data
        db.session.commit()
        flash('Store updated')
        return redirect(url_for('main.store_detail'),
                        store_id=store.id,
                        store=store)
    return render_template('store_detail.html', store=store, form=form)
コード例 #3
0
def new_store():
    '''Route for adding a new_store to the database. '''
    form = GroceryStoreForm()
    if form.validate_on_submit():
        new_store = GroceryStore(title=form.title.data,
                                 address=form.address.data,
                                 created_by=current_user,
                                 created_by_id=current_user.id)
        db.session.add(new_store)
        db.session.commit()
        flash("New Store Was Created!")
        return redirect(url_for('main.store_detail', store_id=new_store.id))
    return render_template('new_store.html', form=form)
コード例 #4
0
def store_detail(store_id):
    '''Route for displaying and modifying a store's information in the database.'''
    store = GroceryStore.query.get(store_id)
    form = GroceryStoreForm(obj=store)

    if form.validate_on_submit():
        store.title = form.title.data
        store.address = form.address.data
        db.session.commit()
        flash("Store Infromation Was Updated")
        return redirect(url_for('main.store_detail', store_id=store_id))

    return render_template('store_detail.html', store=store, form=form)
コード例 #5
0
def store_detail(store_id):
    store = GroceryStore.query.get(store_id)
    form = GroceryStoreForm(obj=store)

    if form.validate_on_submit():
        form.populate_obj(store)
        db.session.add(store)
        db.session.commit()

        flash("Store was successfully updated.")
        return redirect(url_for('main.store_detail', store_id=store.id))

    return render_template('store_detail.html', store=store, form=form)
コード例 #6
0
def new_store():
    form = GroceryStoreForm()

    if form.validate_on_submit():
        print("***** trying to print success *****")
        new_store = GroceryStore(title=form.title.data,
                                 address=form.address.data)
        db.session.add(new_store)
        db.session.commit()

        flash('You have Succesfully created a new store')
        return redirect(url_for('main.store_detail', store_id=new_store.id))
    return render_template('new_store.html', form=form)
コード例 #7
0
ファイル: routes.py プロジェクト: AndreaGraziosi/GroceryApp
def new_store():
    form = GroceryStoreForm()

    if form.validate_on_submit():
        new_GS = GroceryStore(title=form.title.data, address=form.address.data)
        db.session.add(new_GS)
        db.session.commit()

        flash('New Grocery Store was created successfully.')
        # - redirect the user to the store detail page.
        return redirect(url_for('main.store_detail',
                                GroceryStore_id=new_GS.id))
    #Send the form to the template and use it to render the form fields
    return render_template('new_store.html', form=form)
コード例 #8
0
def new_store():
    form = GroceryStoreForm()

    if form.validate_on_submit():
        new_store = GroceryStore(title=form.title.data,
                                 address=form.address.data)

        db.session.add(new_store)
        db.session.commit()

        flash("New store was successfully added.")
        return redirect(url_for('main.store_detail', store_id=new_store.id))

    return render_template('new_store.html', form=form)
コード例 #9
0
def new_store():
    # Creates a GroceryStoreForm
    form = GroceryStoreForm()

    # If form was submitted and was valid:
    if form.validate_on_submit():
        new_store = GroceryStore(title=form.title.data,
                                 address=form.address.data)
        db.session.add(new_store)
        db.session.commit()

        flash('New store was added successfully.')
        return redirect(url_for('main.store_detail', store_id=new_store.id))
    return render_template('new_store.html', form=form)
コード例 #10
0
def store_detail(store_id):
    store = GroceryStore.query.get(store_id)
    form = GroceryStoreForm(obj=store)

    # If form was submitted and was valid:
    if form.validate_on_submit():
        # Populates the attributes of the passed obj with data from the form's fields
        form.populate_obj(store)
        db.session.add(store)
        db.session.commit()

        flash('Store was edited successfully.')
        return redirect(url_for('main.store_detail', store_id=store.id))
    store = GroceryStore.query.get(store_id)
    return render_template('store_detail.html', store=store, form=form)
コード例 #11
0
def store_detail(store_id):
    store = GroceryStore.query.get(store_id)
    form = GroceryStoreForm(obj=store)

    if form.validate_on_submit():
        store.title = (form.title.data)
        store.address = (form.address.data)

    db.session.add(store)
    db.session.commit()

    flash('A new Grocery Store was successfully updated')

    store = GroceryStore.query.get(store_id)
    return render_template('store_detail.html', store=store, form=form)
コード例 #12
0
ファイル: routes.py プロジェクト: AndreaGraziosi/GroceryApp
def store_detail(store_id):
    store = GroceryStore.query.get(store_id)
    form = GroceryStoreForm(obj=store)

    if form.validate_on_submit():
        new_store = GroceryStore(address=form.address.data,
                                 title=form.title.data)
        db.session.add(new_store)
        db.session.commit()

        flash('Store details were updated successfully.')
        return redirect(url_for('main.store_detail', store_id=new_store.id))
    #Send the form to the template and use it to render the form fields
    store = GroceryStore.query.get(store_id)
    return render_template('store_detail.html', store=store, form=form)
コード例 #13
0
def store_detail(store_id):
    store = GroceryStore.query.get(store_id)
    # Created GroceryStoreForm and passed in `obj=store`
    form = GroceryStoreForm(obj=store)

    if form.validate_on_submit(): 
        store.title=form.title.data,
        store.address=form.address.data

    db.session.add(store)
    db.session.commit()

    flash('The new Grocery Store was updated succesfully')        

    store = GroceryStore.query.get(store_id)
    return render_template('store_detail.html', store=store, form=form)
コード例 #14
0
ファイル: routes.py プロジェクト: lotsofluck/GroceryStore
def new_store():
    #Creates a GroceryStoreForm
    form = GroceryStoreForm()

    if form.validate_on_submit():
        new_GroceryStore = GroceryStore(
            title=form.title.data,
            address=form.address.data,
        )
        db.session.add(new_GroceryStore)
        db.session.commit()

        flash('New GroceryStore was created successfully!')
        return redirect(url_for('main.store_detail'))

    return render_template('new_store.html', form=form)
コード例 #15
0
def new_store():
    form = GroceryStoreForm()

    if form.validate_on_submit():
        new_GroceryStore = GroceryStore(title=form.title.data,
                                        address=form.address.data,
                                        created_by=current_user)

        db.session.add(new_GroceryStore)
        db.session.commit()

        flash('A new Grocery Store was successfully created')
        return redirect(
            url_for('main.store_detail', store_id=new_GroceryStore.id))

    return render_template('new_store.html', form=form)
コード例 #16
0
def new_store():
    # TODO: Create a GroceryStoreForm
    form = GroceryStoreForm()

    if form.validate_on_submit():
        store = GroceryStore(
            title=form.title.data,
            address=form.address.data,
            created_by=current_user,
        )
        db.session.add(store)
        db.session.commit()

        flash('New store was created')
        return redirect(url_for('main.store_detail', store_id=store.id))

    return render_template('new_store.html', form=form)
コード例 #17
0
def new_store():
    groceryStoreForm = GroceryStoreForm()

    if groceryStoreForm.validate_on_submit():
        # Create new ORM GroceryStore
        newGroceryStore = GroceryStore(title=groceryStoreForm.title.data,
                                       address=groceryStoreForm.address.data,
                                       created_by=current_user)
        db.session.add(newGroceryStore)
        db.session.commit()
        flash('Success')
        # Send to created GroceryStore page
        return redirect(
            url_for('main.store_detail', store_id=newGroceryStore.id))
    # Returned on 'GET'
    return render_template('new_store.html',
                           groceryStoreForm=groceryStoreForm,
                           current_user=current_user)
コード例 #18
0
def store_detail(store_id):
    store = GroceryStore.query.get(store_id)
    # Create a GroceryStoreForm and pass in `obj=store`
    form = GroceryStoreForm(obj=store)

    # If form was submitted and was valid:
    if form.validate_on_submit():
        new_GroceryStore = GroceryStore(title=form.title.data,
                                        address=form.address.data)
        db.session.add(new_GroceryStore)
        db.session.commit()

        flash('New store was created successfully.')
        return redirect(
            url_for('main.store_detail', GroceryStore_id=new_GroceryStore.id))

    store = GroceryStore.query.get(store_id)
    return render_template('store_detail.html', store=store, form=form)
コード例 #19
0
def new_store():
    # TODO: Create a GroceryStoreForm
    form = GroceryStoreForm()

    # TODO: If form was submitted and was valid:
    # - create a new GroceryStore object and save it to the database,
    # - flash a success message, and
    # - redirect the user to the store detail page.
    if form.validate_on_submit():
        new_store = GroceryStore(title=form.title.data,
                                 address=form.address.data,
                                 created_by=current_user)
        db.session.add(new_store)
        db.session.commit()

        flash('Store was created successfully.')
        return redirect(url_for('auth.store_detail', store_id=new_store.id))
    # TODO: Send the form to the template and use it to render the form fields
    return render_template('new_store.html', form=form)
コード例 #20
0
def store_detail(store_id):
    store = GroceryStore.query.get(store_id)
    groceryStoreForm = GroceryStoreForm(obj=store)

    if groceryStoreForm.validate_on_submit():
        # Update ORM GroceryStore
        store.title = groceryStoreForm.title.data
        store.address = groceryStoreForm.address.data
        db.session.commit()
        flash('Success')
        # Send to updated GroceryItem page (same resource)
        return redirect(url_for('main.store_detail', store_id=store_id))

    store = GroceryStore.query.get(store_id)
    # Returned on 'GET'
    return render_template('store_detail.html',
                           store=store,
                           groceryStoreForm=groceryStoreForm,
                           current_user=current_user)
コード例 #21
0
ファイル: routes.py プロジェクト: lotsofluck/GroceryStore
def store_detail(store_id):
    store = GroceryStore.query.get(store_id)
    #Creates a GroceryStoreForm
    store = GroceryStore.query.get(store_id)
    form = GroceryStoreForm(obj=store)

    if form.validate_on_submit():
        new_GroceryStore = GroceryStore(
            title=form.title.data,
            address=form.address.data,
        )
        db.session.add(new_GroceryStore)
        db.sesssion.commit()

        flash('New GroceryStore was created')
        return redirect(
            url_for('main.store_detail', store_id=new_GroceryStore.id))

    store = GroceryStore.query.get(store_id)
    return render_template('store_detail.html', store=store, form=form)
コード例 #22
0
def new_store():
    form = GroceryStoreForm()
    # If form was submitted and was valid:
    if form.validate_on_submit(): 
        # - creates a new GroceryStore object and save it to the database,
        new_GroceryStore = GroceryStore(
            title=form.title.data,
            address=form.address.data,
            created_by=current_user
        ) 

        db.session.add(new_GroceryStore)
        db.session.commit()

        # - flashes a success message
        flash('You have created a Grocery Store successfully')
        # - redirects the user to the store detail page.
        return redirect(url_for('main.store_detail', store_id=new_GroceryStore.id))
     # Sends the form to the template and use it to render the form fields
    return render_template('new_store.html', form=form)
コード例 #23
0
def store_detail(store_id):
    store = GroceryStore.query.get(store_id)
    # TODO: Create a GroceryStoreForm and pass in `obj=store`
    form = GroceryStoreForm(obj=store)
    # TODO: If form was submitted and was valid:
    # - update the GroceryStore object and save it to the database,
    # - flash a success message, and
    # - redirect the user to the store detail page.
    if form.validate_on_submit():
        store.title = form.title.data
        store.address = form.address.data

        db.session.commit()
        flash('Store updated')
        return redirect(
            url_for('main.store_detail', store_id=store.id, store=store))

    # TODO: Send the form to the template and use it to render the form fields

    return render_template('store_detail.html', store=store, form=form)
コード例 #24
0
def store_detail(store_id):
    store = GroceryStore.query.get(store_id)
    # Creates a GroceryStoreForm and pass in `obj=store`
    form = GroceryStoreForm(obj=store)

    # If form was submitted and was valid:
    # - update the GroceryStore object and save it to the database,
    # - flash a success message, and
    # - redirect the user to the store detail page.

    if form.validate_on_submit():
        new_store = GroceryStore(title=form.data.title,
                                 address=form.address.data)
        db.session.add(new_store)
        db.committ()

        flash("New store was added")
        return redirect(
            url_for('main.store_detail', store_id=store.id, store=store))

    return render_template('store_detail.html', store=store)
コード例 #25
0
def store_detail(store_id):
    """Display grocery store details with update form below."""
    store = GroceryStore.query.get(store_id)
    # TCreate a GroceryStoreForm and pass in `obj=store`
    form = GroceryStoreForm(obj=store)

    # If form was submitted and was valid:
    # - update the GroceryStore object and save it to the database,
    # - flash a success message, and
    # - redirect the user to the store detail page.
    if form.validate_on_submit():
        store.title = form.title.data
        store.address = form.address.data

        db.session.add(store)
        db.session.commit()

        flash('The grocery store was updated successfully.')
        return redirect(url_for('main.store_detail', store_id=store.id))

    # Send the form to the template and use it to render the form fields
    store = GroceryStore.query.get(store_id)
    return render_template('store_detail.html', store=store, form=form)