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 product view to use class-based views #82

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Refactor product view to use class-based views #82

wants to merge 3 commits into from

Commits on Jan 9, 2013

  1. Add tests for product view

    This commit adds some tests of the Product view code.
    Lorin Hochstein committed Jan 9, 2013
    Configuration menu
    Copy the full SHA
    4387d3f View commit details
    Browse the repository at this point in the history
  2. Remove some unnecessary code from tests

    Lorin Hochstein committed Jan 9, 2013
    Configuration menu
    Copy the full SHA
    f8b502a View commit details
    Browse the repository at this point in the history
  3. Refactor product view to use class-based views

    This is a proposed refactoring of the product view code to use
    class-based views. There are no (intentional) changes to the behavior
    in this commit.
    
    The motivation behind this proposed change is to make it easier for
    users to extend Cartridge through subclassing. For example, if a
    Cartridge user wanted to be able to use a subclass of the Product
    class in their template, all they would need to do is:
     1. subclass the proposed ProductDetailView class
     2. Override the get_object method in the subclass
     3. Add a line in urls.py in their project to use the subclass
    
     The main change is replacing the cartridge.shop.views.product function
     with the cartridge.shop.views.ProductDetailView class.
    
    The only other required change was the
    cartridge.shop.forms.AddProductForm.__init__ method. This change was
    needed because the Django class-based views don't support passing a
    positional argument to the __init__ method of forms. However, the
    Django class-based view code automatically passes request.POST as an
    argument called 'data' (see
    django.views.generic.edit.FormMixin.get_form_kwargs), so I made a
    change to use `data` as a keyword argument as a replacement for
    the positional arguemnt.
    Lorin Hochstein committed Jan 9, 2013
    Configuration menu
    Copy the full SHA
    fa089a8 View commit details
    Browse the repository at this point in the history