Beispiel #1
0
def edit(order_id):
    order = get_order(order_id)
    order.client = order.client.id
    form = OrderForm(obj=order)
    if form.validate_on_submit():
        update_order(order_id, form.data)
        return redirect(url_for('orders.list'))

    clients = get_all_clients()
    form.client.choices = [(item.id, '{} {}'.format(item.name, item.surname))
                           for item in clients]
    client_choices = jsonpickle.dumps(clients)

    products = get_all_products()
    product_choices = {}
    for product in products:
        product_choices[product.id] = {
            'id': product.id,
            'price': product.string_price,
        }
    product_choices = jsonpickle.dumps(product_choices)

    return render_template('orders/create.html',
                           form=form,
                           client_choices=client_choices,
                           product_choices=product_choices)
Beispiel #2
0
def create():
    form = OrderForm()
    if form.validate_on_submit():
        save_order(form.data)
        return redirect(url_for("orders.list"))

    clients = get_all_clients()
    form.client.choices = [(item.id, "{} {}".format(item.name, item.surname)) for item in clients]
    client_choices = jsonpickle.dumps(clients)

    products = get_all_products()
    product_choices = {}
    for product in products:
        product_choices[product.id] = {"id": product.id, "price": product.string_price}
    product_choices = jsonpickle.dumps(product_choices)

    return render_template(
        "orders/create.html", form=form, client_choices=client_choices, product_choices=product_choices
    )
Beispiel #3
0
 def __init__(self, *args, **kwargs):
     super(OrderForm, self).__init__(*args, **kwargs)
     self.client.choices = [
         (item.id, item.name) for item in get_all_clients()
     ]
     self.status.choices = get_statuses_choices()