Commits

Russell Keith-Magee  committed 8b16094

One more set of bikeshed changes (hopefully nearing the end) revealed when writing the migration guide.

  • Participants
  • Parent commits 7a219aa
  • Branches class-based-views

Comments (0)

Files changed (8)

File django/views/generic/__init__.py

 from django.views.generic.base import View, TemplateView, RedirectView
-from django.views.generic.dates import (ArchiveView, YearView, MonthView,
-                                     WeekView, DayView, TodayView,
+from django.views.generic.dates import (ArchiveIndexView, YearArchiveView, MonthArchiveView,
+                                     WeekArchiveView, DayArchiveView, TodayArchiveView,
                                      DateDetailView)
 from django.views.generic.detail import DetailView
 from django.views.generic.edit import CreateView, UpdateView, DeleteView

File django/views/generic/dates.py

         return context
 
 
-class BaseArchiveView(BaseDateListView):
+class BaseArchiveIndexView(BaseDateListView):
     """
     Base class for archives of date-based items.
 
         return (date_list, object_list, {})
 
 
-class ArchiveView(MultipleObjectTemplateResponseMixin, BaseArchiveView):
+class ArchiveIndexView(MultipleObjectTemplateResponseMixin, BaseArchiveIndexView):
     """
     Top-level archive of date-based items.
     """
     template_name_suffix = '_archive'
 
 
-class BaseYearView(YearMixin, BaseDateListView):
+class BaseYearArchiveView(YearMixin, BaseDateListView):
     """
     List of objects published in a given year.
     """
         return self.make_object_list
 
 
-class YearView(MultipleObjectTemplateResponseMixin, BaseYearView):
+class YearArchiveView(MultipleObjectTemplateResponseMixin, BaseYearArchiveView):
     """
     List of objects published in a given year.
     """
     template_name_suffix = '_archive_year'
 
 
-class BaseMonthView(YearMixin, MonthMixin, BaseDateListView):
+class BaseMonthArchiveView(YearMixin, MonthMixin, BaseDateListView):
     """
     List of objects published in a given year.
     """
 
 
 
-class MonthView(MultipleObjectTemplateResponseMixin, BaseMonthView):
+class MonthArchiveView(MultipleObjectTemplateResponseMixin, BaseMonthArchiveView):
     """
     List of objects published in a given year.
     """
     template_name_suffix = '_archive_month'
 
 
-class BaseWeekView(YearMixin, WeekMixin, BaseDateListView):
+class BaseWeekArchiveView(YearMixin, WeekMixin, BaseDateListView):
     """
     List of objects published in a given week.
     """
         return (None, qs, {'week': date})
 
 
-class WeekView(MultipleObjectTemplateResponseMixin, BaseWeekView):
+class WeekArchiveView(MultipleObjectTemplateResponseMixin, BaseWeekArchiveView):
     """
     List of objects published in a given week.
     """
     template_name_suffix = '_archive_week'
 
 
-class BaseDayView(YearMixin, MonthMixin, DayMixin, BaseDateListView):
+class BaseDayArchiveView(YearMixin, MonthMixin, DayMixin, BaseDateListView):
     """
     List of objects published on a given day.
     """
     def _get_dated_items(self, date):
         """
         Do the actual heavy lifting of getting the dated items; this accepts a
-        date object so that TodayView can be trivial.
+        date object so that TodayArchiveView can be trivial.
         """
         date_field = self.get_date_field()
 
 
 
 
-class DayView(MultipleObjectTemplateResponseMixin, BaseDayView):
+class DayArchiveView(MultipleObjectTemplateResponseMixin, BaseDayArchiveView):
     """
     List of objects published on a given day.
     """
     template_name_suffix = "_archive_day"
 
 
-class BaseTodayView(BaseDayView):
+class BaseTodayArchiveView(BaseDayArchiveView):
     """
     List of objects published today.
     """
         return self._get_dated_items(datetime.date.today())
 
 
-class TodayView(MultipleObjectTemplateResponseMixin, BaseTodayView):
+class TodayArchiveView(MultipleObjectTemplateResponseMixin, BaseTodayArchiveView):
     """
     List of objects published today.
     """
     that'll be invalid for the given view.
 
     This is a bit complicated since it handles both next and previous months
-    and days (for MonthView and DayView); hence the coupling to generic_view.
+    and days (for MonthArchiveView and DayArchiveView); hence the coupling to generic_view.
 
     However in essance the logic comes down to:
 

File docs/ref/class-based-views.txt

 
 .. currentmodule:: django.views.generic.dates
 
-ArchiveView
-~~~~~~~~~~~
-.. class:: BaseArchiveView()
-.. class:: ArchiveView()
+ArchiveIndexView
+~~~~~~~~~~~~~~~~
+.. class:: BaseArchiveIndexView()
+.. class:: ArchiveIndexView()
 
 A top-level index page showing the "latest" objects, by date. Objects
 with a date in the *future* are not included unless you set
 ``allow_future`` to ``True``.
 
-:class:`django.views.generic.dates.BaseArchiveView` implements the
-same behavior as :class:`django.views.generic.dates.ArchiveView`, but
-doesn't include the
+:class:`django.views.generic.dates.BaseArchiveIndexView` implements
+the same behavior as
+:class:`django.views.generic.dates.ArchiveIndexView`, but doesn't
+include the
 :class:`~django.views.generic.base.MultipleObjectTemplateResponseMixin`.
 
 **Mixins**
 
     * Uses a default ``template_name_suffix`` of ``_archive``.
 
-YearView
-~~~~~~~~
-.. class:: BaseYearView()
-.. class:: YearView()
+YearArchiveView
+~~~~~~~~~~~~~~~
+.. class:: BaseYearArchiveView()
+.. class:: YearArchiveView()
 
 A yearly archive page showing all available months in a given year.
 Objects with a date in the *future* are not displayed unless you set
 ``allow_future`` to ``True``.
 
-:class:`django.views.generic.dates.BaseYearView` implements the same behavior as
-:class:`django.views.generic.dates.YearView`, but doesn't include the
+:class:`django.views.generic.dates.BaseYearArchiveView` implements the
+same behavior as :class:`django.views.generic.dates.YearArchiveView`,
+but doesn't include the
 :class:`~django.views.generic.base.MultipleObjectTemplateResponseMixin`.
 
 **Mixins**
 
 **Attributes**
 
-.. attribute:: YearView.make_object_list
+.. attribute:: YearArchiveView.make_object_list
 
     A boolean specifying whether to retrieve the full list of objects
     for this year and pass those to the template. If ``True``, the
 
 **Methods**
 
-.. method:: YearView.get_make_object_list()
+.. method:: YearArchiveView.get_make_object_list()
 
     Determine if an object list will be returned as part of the context.
     If ``False``, the ``None`` queryset will be used as the object list.
 
     * Uses a default ``template_name_suffix`` of ``_archive_year``.
 
-MonthView
-~~~~~~~~~
-.. class:: BaseMonthView()
-.. class:: MonthView()
+MonthArchiveView
+~~~~~~~~~~~~~~~~
+.. class:: BaseMonthArchiveView()
+.. class:: MonthArchiveView()
 
 A monthly archive page showing all objects in a given month. Objects with a
 date in the *future* are not displayed unless you set ``allow_future`` to
 ``True``.
 
-:class:`django.views.generic.dates.BaseMonthView` implements the same behavior as
-:class:`django.views.generic.dates.MonthView`, but doesn't include the
+:class:`django.views.generic.dates.BaseMonthArchiveView` implements
+the same behavior as
+:class:`django.views.generic.dates.MonthArchiveView`, but doesn't
+include the
 :class:`~django.views.generic.base.MultipleObjectTemplateResponseMixin`.
 
 **Mixins**
 
     * Uses a default ``template_name_suffix`` of ``_archive_month``.
 
-WeekView
-~~~~~~~~
-.. class:: BaseWeekView()
-.. class:: WeekView()
+WeekArchiveView
+~~~~~~~~~~~~~~~
+.. class:: BaseWeekArchiveView()
+.. class:: WeekArchiveView()
 
 A weekly archive page showing all objects in a given week. Objects with a date
 in the *future* are not displayed unless you set ``allow_future`` to ``True``.
 
-:class:`django.views.generic.dates.BaseWeekView` implements the same behavior as
-:class:`django.views.generic.dates.WeekView`, but doesn't include the
+:class:`django.views.generic.dates.BaseWeekArchiveView` implements the
+same behavior as :class:`django.views.generic.dates.WeekArchiveView`,
+but doesn't include the
 :class:`~django.views.generic.base.MultipleObjectTemplateResponseMixin`.
 
 **Mixins**
 
     * Uses a default ``template_name_suffix`` of ``_archive_week``.
 
-DayView
-~~~~~~~
-.. class:: BaseDayView()
-.. class:: DayView()
+DayArchiveView
+~~~~~~~~~~~~~~
+.. class:: BaseDayArchiveView()
+.. class:: DayArchiveView()
 
 A day archive page showing all objects in a given day. Days in the future throw
 a 404 error, regardless of whether any objects exist for future days, unless
 you set ``allow_future`` to ``True``.
 
-:class:`django.views.generic.dates.BaseDayView` implements the same behavior as
-:class:`django.views.generic.dates.DayView`, but doesn't include the
+:class:`django.views.generic.dates.BaseDayArchiveView` implements the
+same behavior as :class:`django.views.generic.dates.DayArchiveView`,
+but doesn't include the
 :class:`~django.views.generic.base.MultipleObjectTemplateResponseMixin`.
 
 **Mixins**
 
     * Uses a default ``template_name_suffix`` of ``_archive_day``.
 
-TodayView
-~~~~~~~~~
-.. class:: BaseTodayView()
-.. class:: TodayView()
+TodayArchiveView
+~~~~~~~~~~~~~~~~
+.. class:: BaseTodayArchiveView()
+.. class:: TodayArchiveView()
 
 A day archive page showing all objects for *today*. This is exactly the same as
 ``archive_day``, except the ``year``/``month``/``day`` arguments are not used,
 
-:class:`django.views.generic.dates.BaseTodayView` implements the same behavior as
-:class:`django.views.generic.dates.TodayView`, but doesn't include the
+:class:`django.views.generic.dates.BaseTodayArchiveView` implements the same behavior as
+:class:`django.views.generic.dates.TodayArchiveView`, but doesn't include the
 :class:`~django.views.generic.base.MultipleObjectTemplateResponseMixin`.
 
 **Mixins**
 
-    * :class:`~django.views.generic.date.DayView`
+    * :class:`~django.views.generic.date.DayArchiveView`
 
 DateDetailView
 ~~~~~~~~~~~~~~

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

 How to migrate
 ==============
 
+Replace generic views with generic classes
+------------------------------------------
 
-
-Specific differences
-====================
-
-Here are some specific differences between function-based and
-class-based generic views that are worth watching out for.
+    ====================================================  ====================================================
+    Old function-based generic view                       New class-based generic view
+    ====================================================  ====================================================
+    ``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.create_update.update_object``  :class:`django.views.generic.edit.UpdateView`
+    ``django.views.generic.create_update.delete_object``  :class:`django.views.generic.edit.DeleteView`
+    ``django.views.generic.date_based.archive_index``     :class:`django.views.generic.dates.ArchiveIndexView`
+    ``django.views.generic.date_based.archive_year``      :class:`django.views.generic.dates.YearArchiveView`
+    ``django.views.generic.date_based.archive_month``     :class:`django.views.generic.dates.MonthArchiveView`
+    ``django.views.generic.date_based.archive_week``      :class:`django.views.generic.dates.WeekArchiveView`
+    ``django.views.generic.date_based.archive_day``       :class:`django.views.generic.dates.DayArchiveView`
+    ``django.views.generic.date_based.archive_today``     :class:`django.views.generic.dates.TodayArchiveView`
+    ``django.views.generic.date_based.object_detail``     :class:`django.views.generic.dates.DateDetailView`
+    ====================================================  ====================================================
 
 ``object_id`` argument to detail views
 --------------------------------------

File tests/regressiontests/generic_views/dates.py

 
 from regressiontests.generic_views.models import Book
 
-class ArchiveViewTests(TestCase):
+class ArchiveIndexViewTests(TestCase):
     fixtures = ['generic-views-test-data.json']
     urls = 'regressiontests.generic_views.urls'
 
         self.assertEqual(list(res.context['latest']), list(Book.objects.all()[10:20]))
 
 
-class YearViewTests(TestCase):
+class YearArchiveViewTests(TestCase):
     fixtures = ['generic-views-test-data.json']
     urls = 'regressiontests.generic_views.urls'
 
         res = self.client.get('/dates/books/no_year/')
         self.assertEqual(res.status_code, 404)
 
-class MonthViewTests(TestCase):
+class MonthArchiveViewTests(TestCase):
     fixtures = ['generic-views-test-data.json']
     urls = 'regressiontests.generic_views.urls'
 
         res = self.client.get('/dates/books/2007/no_month/')
         self.assertEqual(res.status_code, 404)
 
-class WeekViewTests(TestCase):
+class WeekArchiveViewTests(TestCase):
     fixtures = ['generic-views-test-data.json']
     urls = 'regressiontests.generic_views.urls'
 
         res = self.client.get('/dates/books/2007/week/no_week/')
         self.assertEqual(res.status_code, 404)
 
-class DayViewTests(TestCase):
+class DayArchiveViewTests(TestCase):
     fixtures = ['generic-views-test-data.json']
     urls = 'regressiontests.generic_views.urls'
 

File tests/regressiontests/generic_views/tests.py

 from regressiontests.generic_views.base import ViewTest, TemplateViewTest, RedirectViewTest
-from regressiontests.generic_views.dates import ArchiveViewTests, YearViewTests, MonthViewTests, WeekViewTests, DayViewTests, DateDetailViewTests
+from regressiontests.generic_views.dates import ArchiveIndexViewTests, YearArchiveViewTests, MonthArchiveViewTests, WeekArchiveViewTests, DayArchiveViewTests, DateDetailViewTests
 from regressiontests.generic_views.detail import DetailViewTest
 from regressiontests.generic_views.edit import CreateViewTests, UpdateViewTests, DeleteViewTests
 from regressiontests.generic_views.list import ListViewTests

File tests/regressiontests/generic_views/urls.py

     (r'^edit/author/(?P<pk>\d+)/delete/special/$',
         views.SpecializedAuthorDelete.as_view()),
 
-    # ArchiveView
+    # ArchiveIndexView
     (r'^dates/books/$',
         views.BookArchive.as_view()),
     (r'^dates/books/context_object_name/$',
     (r'^list/authors/invalid/$',
         views.AuthorList.as_view(queryset=None)),
 
-    # YearView
+    # YearArchiveView
     # Mixing keyword and possitional captures below is intentional; the views
     # ought to be able to accept either.
     (r'^dates/books/(?P<year>\d{4})/$',
     (r'^dates/books/no_year/$',
         views.BookYearArchive.as_view()),
 
-    # MonthView
+    # MonthArchiveView
     (r'^dates/books/(?P<year>\d{4})/(?P<month>[a-z]{3})/$',
         views.BookMonthArchive.as_view()),
     (r'^dates/books/(?P<year>\d{4})/(?P<month>\d{1,2})/$',
     (r'^dates/books/(?P<year>\d{4})/no_month/$',
         views.BookMonthArchive.as_view()),
 
-    # WeekView
+    # WeekArchiveView
     (r'^dates/books/(?P<year>\d{4})/week/(?P<week>\d{1,2})/$',
         views.BookWeekArchive.as_view()),
     (r'^dates/books/(?P<year>\d{4})/week/(?P<week>\d{1,2})/allow_empty/$',
     (r'^dates/books/(?P<year>\d{4})/week/no_week/$',
         views.BookWeekArchive.as_view()),
 
-    # DayView
+    # DayArchiveView
     (r'^dates/books/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\d{1,2})/$',
         views.BookDayArchive.as_view()),
     (r'^dates/books/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$',
     (r'^dates/books/(?P<year>\d{4})/(?P<month>[a-z]{3})/no_day/$',
         views.BookDayArchive.as_view()),
 
-    # TodayView
+    # TodayArchiveView
     (r'dates/books/today/$',
         views.BookTodayArchive.as_view()),
     (r'dates/books/today/allow_empty/$',

File tests/regressiontests/generic_views/views.py

     queryset = Book.objects.all()
     date_field = 'pubdate'
 
-class BookArchive(BookConfig, generic.ArchiveView):
+class BookArchive(BookConfig, generic.ArchiveIndexView):
     pass
 
-class BookYearArchive(BookConfig, generic.YearView):
+class BookYearArchive(BookConfig, generic.YearArchiveView):
     pass
 
-class BookMonthArchive(BookConfig, generic.MonthView):
+class BookMonthArchive(BookConfig, generic.MonthArchiveView):
     pass
 
-class BookWeekArchive(BookConfig, generic.WeekView):
+class BookWeekArchive(BookConfig, generic.WeekArchiveView):
     pass
 
-class BookDayArchive(BookConfig, generic.DayView):
+class BookDayArchive(BookConfig, generic.DayArchiveView):
     pass
 
-class BookTodayArchive(BookConfig, generic.TodayView):
+class BookTodayArchive(BookConfig, generic.TodayArchiveView):
     pass
 
 class BookDetail(BookConfig, generic.DateDetailView):