Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor add product view #10

Merged
merged 4 commits into from Mar 9, 2015
Merged

Conversation

maerteijn
Copy link
Member

So I can override the validate method in the view like this:

from oscarapi.views.basket import AddProductView as _AddProductView

class AddProductView(_AddProductView):
    def validate(self, basket, product, quantity):
        # check if there is a orderlimit for this product
        allowed, message = basket.add_product_allowed(product, quantity)
        if not allowed:
            return False, message
        return super(
            AddProductView, self).validate(basket, product, quantity)

if p_ser.is_valid():
basket = get_basket(request)
product = p_ser.object['url']
quantity = p_ser.init_data.get('quantity')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not ok, the serializer has been updated, so all properties are available on the cleaned and validated object:

product = p_ser.object['url']
quantity = p_ser.object['quantity'] <-- that one is wrong
options = p_ser.object.get('options', [])

specialunderwear added a commit that referenced this pull request Mar 9, 2015
@specialunderwear specialunderwear merged commit 01d2d77 into checkout Mar 9, 2015
@maerteijn maerteijn deleted the refactor-add-product-view branch March 10, 2015 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants