Skip to content

Commit

Permalink
Merge pull request #261 from issackelly/cbv-full-list
Browse files Browse the repository at this point in the history
Create headings and expand CBV docs so that the "Built-In CBV" docs include a full list.
  • Loading branch information
timgraham committed Aug 17, 2012
2 parents ad11dbf + 060ac8e commit 4eaf73d
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 27 deletions.
35 changes: 22 additions & 13 deletions docs/ref/class-based-views/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ themselves or inherited from. They may not provide all the capabilities
required for projects, in which case there are Mixins and Generic class-based
views.

View
----

.. class:: django.views.generic.base.View

The master class-based base view. All other class-based views inherit from
Expand All @@ -31,13 +34,13 @@ views.
**Example urls.py**::

from django.conf.urls import patterns, url

from myapp.views import MyView

urlpatterns = patterns('',
url(r'^mine/$', MyView.as_view(), name='my-view'),
)

**Methods**

.. method:: dispatch(request, *args, **kwargs)
Expand All @@ -61,13 +64,16 @@ views.

The default implementation returns ``HttpResponseNotAllowed`` with list
of allowed methods in plain text.
.. note::

.. note::

Documentation on class-based views is a work in progress. As yet, only the
methods defined directly on the class are documented here, not methods
defined on superclasses.

TemplateView
------------

.. class:: django.views.generic.base.TemplateView

Renders a given template, passing it a ``{{ params }}`` template variable,
Expand All @@ -84,22 +90,22 @@ views.
1. :meth:`dispatch()`
2. :meth:`http_method_not_allowed()`
3. :meth:`get_context_data()`

**Example views.py**::

from django.views.generic.base import TemplateView

from articles.models import Article

class HomePageView(TemplateView):

template_name = "home.html"

def get_context_data(self, **kwargs):
context = super(HomePageView, self).get_context_data(**kwargs)
context['latest_articles'] = Article.objects.all()[:5]
return context

**Example urls.py**::

from django.conf.urls import patterns, url
Expand All @@ -126,12 +132,15 @@ views.
* ``params``: The dictionary of keyword arguments captured from the URL
pattern that served the view.

.. note::
.. note::

Documentation on class-based views is a work in progress. As yet, only the
methods defined directly on the class are documented here, not methods
defined on superclasses.

RedirectView
------------

.. class:: django.views.generic.base.RedirectView

Redirects to a given URL.
Expand Down Expand Up @@ -159,7 +168,7 @@ views.

from django.shortcuts import get_object_or_404
from django.views.generic.base import RedirectView

from articles.models import Article

class ArticleCounterRedirectView(RedirectView):
Expand All @@ -176,7 +185,7 @@ views.

from django.conf.urls import patterns, url
from django.views.generic.base import RedirectView

from article.views import ArticleCounterRedirectView

urlpatterns = patterns('',
Expand Down Expand Up @@ -217,7 +226,7 @@ views.
behavior they wish, as long as the method returns a redirect-ready URL
string.

.. note::
.. note::

Documentation on class-based views is a work in progress. As yet, only the
methods defined directly on the class are documented here, not methods
Expand Down
24 changes: 23 additions & 1 deletion docs/ref/class-based-views/generic-date-based.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Generic date views
Date-based generic views (in the module :mod:`django.views.generic.dates`)
are views for displaying drilldown pages for date-based data.

ArchiveIndexView
----------------

.. class:: django.views.generic.dates.ArchiveIndexView

A top-level index page showing the "latest" objects, by date. Objects with
Expand All @@ -21,12 +24,15 @@ are views for displaying drilldown pages for date-based data.
* :class:`django.views.generic.list.MultipleObjectMixin`
* :class:`django.views.generic.dates.DateMixin`
* :class:`django.views.generic.base.View`

**Notes**

* Uses a default ``context_object_name`` of ``latest``.
* Uses a default ``template_name_suffix`` of ``_archive``.

YearArchiveView
---------------

.. class:: django.views.generic.dates.YearArchiveView

A yearly archive page showing all available months in a given year. Objects
Expand Down Expand Up @@ -86,6 +92,9 @@ are views for displaying drilldown pages for date-based data.

* Uses a default ``template_name_suffix`` of ``_archive_year``.

MonthArchiveView
----------------

.. class:: django.views.generic.dates.MonthArchiveView

A monthly archive page showing all objects in a given month. Objects with a
Expand Down Expand Up @@ -134,6 +143,9 @@ are views for displaying drilldown pages for date-based data.

* Uses a default ``template_name_suffix`` of ``_archive_month``.

WeekArchiveView
---------------

.. class:: django.views.generic.dates.WeekArchiveView

A weekly archive page showing all objects in a given week. Objects with a
Expand Down Expand Up @@ -175,6 +187,9 @@ are views for displaying drilldown pages for date-based data.

* Uses a default ``template_name_suffix`` of ``_archive_week``.

DayArchiveView
--------------

.. class:: django.views.generic.dates.DayArchiveView

A day archive page showing all objects in a given day. Days in the future
Expand Down Expand Up @@ -225,6 +240,9 @@ are views for displaying drilldown pages for date-based data.

* Uses a default ``template_name_suffix`` of ``_archive_day``.

TodayArchiveView
----------------

.. class:: django.views.generic.dates.TodayArchiveView

A day archive page showing all objects for *today*. This is exactly the
Expand All @@ -246,6 +264,10 @@ are views for displaying drilldown pages for date-based data.
* :class:`django.views.generic.dates.DateMixin`
* :class:`django.views.generic.base.View`


DateDetailView
--------------

.. class:: django.views.generic.dates.DateDetailView

A page representing an individual object. If the object has a date value in
Expand Down
10 changes: 8 additions & 2 deletions docs/ref/class-based-views/generic-display.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Generic display views
The two following generic class-based views are designed to display data. On
many projects they are typically the most commonly used views.

DetailView
----------

.. class:: django.views.generic.detail.DetailView

While this view is executing, ``self.object`` will contain the object that
Expand Down Expand Up @@ -39,7 +42,7 @@ many projects they are typically the most commonly used views.
from articles.models import Article

class ArticleDetailView(DetailView):

model = Article

def get_context_data(self, **kwargs):
Expand All @@ -55,7 +58,10 @@ many projects they are typically the most commonly used views.

urlpatterns = patterns('',
url(r'^(?P<slug>[-_\w]+)/$', ArticleDetailView.as_view(), name='article-detail'),
)
)

ListView
--------

.. class:: django.views.generic.list.ListView

Expand Down
27 changes: 19 additions & 8 deletions docs/ref/class-based-views/generic-editing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Generic editing views
=====================

The following views are described on this page and provide a foundation for
The following views are described on this page and provide a foundation for
editing content:

* :class:`django.views.generic.edit.FormView`
Expand All @@ -13,7 +13,7 @@ editing content:
.. note::

Some of the examples on this page assume that a model titled 'Author'
has been defined. For these cases we assume the following has been defined
has been defined. For these cases we assume the following has been defined
in `myapp/models.py`::

from django import models
Expand All @@ -25,6 +25,9 @@ editing content:
def get_absolute_url(self):
return reverse('author-detail', kwargs={'pk': self.pk})

FormView
--------

.. class:: django.views.generic.edit.FormView

A view that displays a form. On error, redisplays the form with validation
Expand Down Expand Up @@ -69,6 +72,8 @@ editing content:
form.send_email()
return super(ContactView, self).form_valid(form)

CreateView
----------

.. class:: django.views.generic.edit.CreateView

Expand All @@ -94,7 +99,7 @@ editing content:
.. attribute:: template_name_suffix

The CreateView page displayed to a GET request uses a
``template_name_suffix`` of ``'_form.html'``. For
``template_name_suffix`` of ``'_form.html'``. For
example, changing this attribute to ``'_create_form.html'`` for a view
creating objects for the the example `Author` model would cause the the
default `template_name` to be ``'myapp/author_create_form.html'``.
Expand All @@ -107,6 +112,9 @@ editing content:
class AuthorCreate(CreateView):
model = Author

UpdateView
----------

.. class:: django.views.generic.edit.UpdateView

A view that displays a form for editing an existing object, redisplaying
Expand All @@ -133,10 +141,10 @@ editing content:
.. attribute:: template_name_suffix

The UpdateView page displayed to a GET request uses a
``template_name_suffix`` of ``'_form.html'``. For
``template_name_suffix`` of ``'_form.html'``. For
example, changing this attribute to ``'_update_form.html'`` for a view
updating objects for the the example `Author` model would cause the the
default `template_name` to be ``'myapp/author_update_form.html'``.
default `template_name` to be ``'myapp/author_update_form.html'``.

**Example views.py**::

Expand All @@ -146,6 +154,9 @@ editing content:
class AuthorUpdate(UpdateView):
model = Author

DeleteView
----------

.. class:: django.views.generic.edit.DeleteView

A view that displays a confirmation page and deletes an existing object.
Expand All @@ -171,10 +182,10 @@ editing content:
.. attribute:: template_name_suffix

The DeleteView page displayed to a GET request uses a
``template_name_suffix`` of ``'_confirm_delete.html'``. For
``template_name_suffix`` of ``'_confirm_delete.html'``. For
example, changing this attribute to ``'_check_delete.html'`` for a view
deleting objects for the the example `Author` model would cause the the
default `template_name` to be ``'myapp/author_check_delete.html'``.
default `template_name` to be ``'myapp/author_check_delete.html'``.


**Example views.py**::
Expand All @@ -185,4 +196,4 @@ editing content:

class AuthorDelete(DeleteView):
model = Author
success_url = reverse_lazy('author-list')
success_url = reverse_lazy('author-list')
2 changes: 1 addition & 1 deletion docs/ref/class-based-views/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Class-based views API reference. For introductory material, see
:doc:`/topics/class-based-views/index`.

.. toctree::
:maxdepth: 1
:maxdepth: 3

base
generic-display
Expand Down
18 changes: 18 additions & 0 deletions docs/ref/class-based-views/mixins-date-based.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Date-based mixins
=================


YearMixin
---------

.. class:: django.views.generic.dates.YearMixin

A mixin that can be used to retrieve and provide parsing information for a
Expand Down Expand Up @@ -36,6 +39,9 @@ Date-based mixins

Raises a 404 if no valid year specification can be found.

MonthMixin
----------

.. class:: django.views.generic.dates.MonthMixin

A mixin that can be used to retrieve and provide parsing information for a
Expand Down Expand Up @@ -82,6 +88,9 @@ Date-based mixins
date provided. If ``allow_empty = False``, returns the previous month
that contained data.

DayMixin
--------

.. class:: django.views.generic.dates.DayMixin

A mixin that can be used to retrieve and provide parsing information for a
Expand Down Expand Up @@ -127,6 +136,9 @@ Date-based mixins
Returns a date object containing the previous day. If
``allow_empty = False``, returns the previous day that contained data.

WeekMixin
---------

.. class:: django.views.generic.dates.WeekMixin

A mixin that can be used to retrieve and provide parsing information for a
Expand Down Expand Up @@ -161,6 +173,9 @@ Date-based mixins
Raises a 404 if no valid week specification can be found.


DateMixin
---------

.. class:: django.views.generic.dates.DateMixin

A mixin class providing common behavior for all date-based views.
Expand Down Expand Up @@ -204,6 +219,9 @@ Date-based mixins
is greater than the current date/time. Returns
:attr:`DateMixin.allow_future` by default.

BaseDateListView
----------------

.. class:: django.views.generic.dates.BaseDateListView

A base class that provides common behavior for all date-based views. There
Expand Down
Loading

0 comments on commit 4eaf73d

Please sign in to comment.