from oscar.templatetags.basket_tags import QNT_SINGLE, basket_form, register


@register.simple_tag(name="basket_form")
def basket_form_in_place(request, product, quantity_type=QNT_SINGLE):
    form = basket_form(request, product, quantity_type)
    if not form:  # guard against crap
        return form

    # pylint: disable=protected-access
    errors = request.session.pop("add_to_basket_form_errors", False)
    if errors:
        form._errors = errors

    return form
