Пример #1
0
def editMaker(id=0):
    maker = Maker.query.filter_by(id=id).first()
    if maker == None:
        flash(gettext('Maker not found.'))
        return redirect(url_for('makers'))
    form = AddMakerForm(obj=maker)
    form.category.choices = [(a.id, a.name_CS) for a in Category.query.all()]
    if form.validate_on_submit():

        #delete maker
        if 'delete' in request.form:
            db.session.delete(maker)
            db.session.commit()
            return redirect(url_for("makers"))

        #update maker
        maker.name = form.name.data
        maker.category_id = form.category.data
        maker.email = form.email.data
        maker.standard_delivery_days = form.standard_delivery_days.data
        db.session.add(maker)
        db.session.commit()
        flash(gettext("Maker successfully changed."))
        return redirect(url_for("makers"))

    selected = maker.category_id
    return render_template('settings/editMaker.html',
                           title=gettext("Edit Maker"),
                           maker=maker,
                           selected=selected,
                           form=form)
Пример #2
0
def addMaker():
    form = AddMakerForm()
    form.category.choices = [(a.id, a.name_CS) for a in Category.query.all()]
    if form.validate_on_submit():
        maker = Maker()
        maker.name = form.name.data
        maker.category_id = form.category.data
        maker.email = form.email.data
        db.session.add(maker)
        db.session.commit()
        flash(gettext("New maker successfully added."))
        return redirect(url_for("makers"))
    return render_template('settings/addMaker.html',
                           title=gettext("Add New Maker"),
                           form=form)