tangentlabs/django-oscar — pull request #639 by andrefsp (2013-04-12 16:03:20+00:00)
Title: Request object injected on AddToBasketForm

Added user purchase permission handling for users.

Response to issue:
https://github.com/tangentlabs/django-oscar/issues/445

AddToBasketForm now has a is_purchase_permitted method to allow a control block on form user permission. Here can be defined functionality to allow or disallow a form to be processed.

class AddToBasketForm(forms.Form):
# (....)
def is_purchase_permitted(self, user, product, desired_qty):
return product.is_purchase_permitted(user=user, quantity=desired_qty)

Also, some re-factoring was done on the basket tags.

From now on {% basket_form %} accepts the request object and a product instead of passing individually the basket and user.

The form is now created by:

{% basket_form request product as basket_form %}