Пример #1
0
def order_item_create(order_id: int) -> typing.Any:
    # type is 'typing.Union[str, Response]', but this errors due to
    #   https://github.com/python/mypy/issues/7187
    "Add item to order from id"
    current_order = Order.query.filter(Order.id == order_id).first()
    if current_order is None:
        abort(404)
    if current_order.stoptime and current_order.stoptime < datetime.now():
        abort(404)
    if current_user.is_anonymous() and not current_order.public:
        flash("Please login to see this order.", "info")
        abort(401)
    form = AnonOrderItemForm() if current_user.is_anonymous() \
        else OrderItemForm()
    form.populate(current_order.location)
    if form.validate_on_submit():
        item = OrderItem()
        form.populate_obj(item)
        item.order_id = order_id
        if not current_user.is_anonymous():
            item.user_id = current_user.id
        else:
            session["anon_name"] = item.name
        db.session.add(item)
        db.session.commit()
        flash("Ordered %s" % (item.product.name), "success")
        return redirect(url_for("order_bp.order_from_id", order_id=order_id))
    return order_from_id(order_id, form=form)
Пример #2
0
def order_item_create(id):
    current_order = Order.query.filter(Order.id == id).first()
    if current_order is None:
        abort(404)
    if current_order.stoptime and current_order.stoptime < datetime.now():
        abort(404)
    if current_user.is_anonymous() and not current_order.public:
        flash('Please login to see this order.', 'info')
        abort(401)
    form = AnonOrderItemForm() if current_user.is_anonymous(
    ) else OrderItemForm()
    form.populate(current_order.location)
    if form.validate_on_submit():
        item = OrderItem()
        form.populate_obj(item)
        item.order_id = id
        if not current_user.is_anonymous():
            item.user_id = current_user.id
        else:
            session['anon_name'] = item.name
        db.session.add(item)
        db.session.commit()
        flash('Ordered %s' % (item.product.name), 'success')
        return redirect(url_for('.order', id=id))
    return order(id, form=form)
Пример #3
0
def order_item_create(id):
    current_order = Order.query.filter(Order.id == id).first()
    if current_order is None:
        abort(404)
    if current_order.stoptime and current_order.stoptime < datetime.now():
        abort(404)
    if current_user.is_anonymous() and not current_order.public:
        flash('Please login to see this order.', 'info')
        abort(401)
    form = AnonOrderItemForm() if current_user.is_anonymous() else OrderItemForm()
    form.populate(current_order.location)
    if form.validate_on_submit():
        item = OrderItem()
        form.populate_obj(item)
        item.order_id = id
        if not current_user.is_anonymous():
            item.user_id = current_user.id
        else:
            session['anon_name'] = item.name
        db.session.add(item)
        db.session.commit()
        flash('Ordered %s' % (item.product.name), 'success')
        return redirect(url_for('.order', id=id))
    return order(id, form=form)