stephenmcd/cartridge — pull request #82 by lorin (2013-01-09 04:00:46+00:00)
Title: 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 argument.