Commits

Russell Keith-Magee committed 2a0a871

Tweaks to the migration guide.

  • Participants
  • Parent commits 8b16094
  • Branches class-based-views

Comments (0)

Files changed (2)

File docs/releases/1.3.txt

 extended.
 
 See :doc:`the documentation on Generic Views</topics/generic-views>`
-for more details.
+for more details. There is also a document to help you :doc:`convert
+your function-based generic views to class-based
+views</topics/generic-views-migration>`.
 
 Logging
 ~~~~~~~

File docs/topics/generic-views-migration.txt

 Replace generic views with generic classes
 ------------------------------------------
 
+Existing usage of function-based generic views should be replaced with
+their class-based analogs::
+
     ====================================================  ====================================================
     Old function-based generic view                       New class-based generic view
     ====================================================  ====================================================
+    ``django.views.generic.simple.direct_to_template``    :class:`django.views.generic.base.TemplateView`
+    ``django.views.generic.simple.redirect_to``           :class:`django.views.generic.base.RedirectView`
     ``django.views.generic.list_detail.object_list``      :class:`django.views.generic.list.ListView`
     ``django.views.generic.list_detail.object_detail``    :class:`django.views.generic.detail.DetailView`
     ``django.views.generic.create_update.create_object``  :class:`django.views.generic.edit.CreateView`
     ``django.views.generic.date_based.object_detail``     :class:`django.views.generic.dates.DateDetailView`
     ====================================================  ====================================================
 
+To do this, replace the reference to the generic view function with
+a ``as_view()`` instantiation of the class-based view. For example,
+the old-style ``direct_to_template`` pattern::
+
+    ('^about/$', direct_to_template, {'template': 'about.html'})
+
+can be replaced with an instance of
+:class:`~django.views.generic.base.TemplateView`::
+
+    ('^about/$', TemplateView.as_view(template_name='about.html'))
+
+``template`` argument to ``direct_to_template`` views
+-----------------------------------------------------
+
+The ``template`` argument to the ``direct_to_template`` view has been renamed
+``template_name``. This has ben done to maintain consistency with other views.
+
 ``object_id`` argument to detail views
 --------------------------------------
 
 as way to insert extra items into the context at time of rendering.
 
 Class-based views don't provide an ``extra_context`` argument.
-Instead, you subclass the view, and override the
-:meth:`get_context_data()` method. For example::
+Instead, you subclass the view, overriding :meth:`get_context_data()`.
+For example::
 
     class MyListView(ListView):
         def get_context_data(self, **kwargs):
                 'bar': 37
             })
             return context
+
+``mimetype``
+------------
+
+Some function-based generic views provided a ``mimetype`` argument
+as way to control the mimetype of the response.
+
+Class-based views don't provide a ``mimetype`` argument. Instead, you
+subclass the view, overriding
+:meth:`TemplateResponseMixin.get_response()` and pass in arguments for
+the HttpResponse constructor. For example::
+
+    class MyListView(ListView):
+        def get_response(self, content, **kwargs):
+            return super(MyListView, self).get_response(content,
+                            content_type='application/json', **kwargs)
+
+``context_processors``
+----------------------
+
+Some function-based generic views provided a ``context_processors``
+argument that could be used to force the use of specialized context
+processors when rendering template content.
+
+Class-based views don't provide a ``context_processors`` argument.
+Instead, you subclass the view, overriding
+:meth:`TemplateResponseMixin.get_context_instance()`. For example::
+
+    class MyListView(ListView):
+        def get_context_instance(self, context):
+            return RequestContext(self.request,
+                                  context,
+                                  processors=[custom_processor])