Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Ticket 18628 Cleanup for methods/attributes associated with display views #207

Closed
wants to merge 1 commit into from

1 participant

@pydanny

This pull request adds descriptive text the MRO section of views, as well as validates methods and attributes associated with mixins tied to DetailView and ListView. Finally it adds BaseListView because the BaseListView.get() method's behavior is alterable via the allow_empty attribute.

@pydanny pydanny Added includable methods and attributes files that follow an easy-to-…
…understand pattern. Also implemented includes on methods and attributes on base CBVS and simple CBV mixins. This works, but requires a lot of time and attention to detail.

Removing the includes for parent views and mixins per @andrewgodwin and @alex

Removing the _ files

Added informative description text to MRO. Added BaseListView.get() to documentation in order to aid in understanding of ListView.

Removed unnecessary whitespace
ff48109
@pydanny pydanny closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 15, 2012
  1. @pydanny

    Added includable methods and attributes files that follow an easy-to-…

    pydanny authored
    …understand pattern. Also implemented includes on methods and attributes on base CBVS and simple CBV mixins. This works, but requires a lot of time and attention to detail.
    
    Removing the includes for parent views and mixins per @andrewgodwin and @alex
    
    Removing the _ files
    
    Added informative description text to MRO. Added BaseListView.get() to documentation in order to aid in understanding of ListView.
    
    Removed unnecessary whitespace
This page is out of date. Refresh to see the latest.
View
56 docs/ref/class-based-views/base.txt
@@ -37,9 +37,20 @@ views.
urlpatterns = patterns('',
url(r'^mine/$', MyView.as_view(), name='my-view'),
)
-
+
+ **Attributes**
+
+ .. attribute:: http_method_names = ['get', 'post', 'put', 'delete', 'head', 'options', 'trace']
+
+ The default list of HTTP method names that this view will accept.
+
+
**Methods**
+ .. method:: as_view(cls, **initkwargs)
+
+ Main entry point for a request-response process.
+
.. method:: dispatch(request, *args, **kwargs)
The ``view`` part of the view -- the method that accepts a ``request``
@@ -59,14 +70,14 @@ views.
If the view was called with a HTTP method it doesn't support, this
method is called instead.
- The default implementation returns ``HttpResponseNotAllowed`` with list
+ The default implementation returns ``HttpResponseNotAllowed`` with a list
of allowed methods in plain text.
-
- .. 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.
+ .. method:: options(request, *args, **kwargs)
+
+ Handles responding to requests for the OPTIONS HTTP verb.
+
+
.. class:: django.views.generic.base.TemplateView
@@ -74,6 +85,8 @@ views.
which is a dictionary of the parameters captured in the URL.
**Ancestors (MRO)**
+
+ This view inherits methods and attributes from the following views:
* :class:`django.views.generic.base.TemplateView`
* :class:`django.views.generic.base.TemplateResponseMixin`
@@ -110,27 +123,12 @@ views.
url(r'^$', HomePageView.as_view(), name='home'),
)
- **Methods and Attributes**
-
- .. attribute:: template_name
-
- The full name of a template to use.
-
- .. method:: get_context_data(**kwargs)
-
- Return a context data dictionary consisting of the contents of
- ``kwargs`` stored in the context variable ``params``.
**Context**
* ``params``: The dictionary of keyword arguments captured from the URL
pattern that served the view.
- .. 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.
.. class:: django.views.generic.base.RedirectView
@@ -146,6 +144,8 @@ views.
(410).
**Ancestors (MRO)**
+
+ This view inherits methods and attributes from the following view:
* :class:`django.views.generic.base.View`
@@ -185,7 +185,7 @@ views.
url(r'^go-to-django/$', RedirectView.as_view(url='http://djangoproject.com'), name='go-to-django'),
)
- **Methods and Attributes**
+ **Attributes**
.. attribute:: url
@@ -206,6 +206,8 @@ views.
then the query string is discarded. By default, ``query_string`` is
``False``.
+ **Methods**
+
.. method:: get_redirect_url(**kwargs)
Constructs the target URL for redirection.
@@ -215,10 +217,4 @@ views.
as the appending of query string if requested by
:attr:`~RedirectView.query_string`. Subclasses may implement any
behavior they wish, as long as the method returns a redirect-ready URL
- string.
-
- .. 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.
+ string.
View
55 docs/ref/class-based-views/generic-display.txt
@@ -11,6 +11,8 @@ many projects they are typically the most commonly used views.
the view is operating upon.
**Ancestors (MRO)**
+
+ This view inherits methods and attributes from the following views:
* :class:`django.views.generic.detail.SingleObjectTemplateResponseMixin`
* :class:`django.views.generic.base.TemplateResponseMixin`
@@ -55,7 +57,7 @@ many projects they are typically the most commonly used views.
urlpatterns = patterns('',
url(r'^(?P<slug>[-_\w]+)/$', ArticleDetailView.as_view(), 'article-detail'),
- )
+ )
.. class:: django.views.generic.list.ListView
@@ -65,7 +67,9 @@ many projects they are typically the most commonly used views.
objects (usually, but not necessarily a queryset) that the view is
operating upon.
- **Mixins**
+ **Ancestors (MRO)**
+
+ This view inherits methods and attributes from the following views:
* :class:`django.views.generic.list.ListView`
* :class:`django.views.generic.list.MultipleObjectTemplateResponseMixin`
@@ -84,3 +88,50 @@ many projects they are typically the most commonly used views.
6. :meth:`get_context_data()`
7. :meth:`get()`
8. :meth:`render_to_response()`
+
+
+ **Example views.py**::
+
+ from django.views.generic.list import ListView
+ from django.utils import timezone
+
+ from articles.models import Article
+
+ class ArticleListView(ListView):
+
+ model = Article
+
+ def get_context_data(self, **kwargs):
+ context = super(ArticleDetailView, self).get_context_data(**kwargs)
+ context['now'] = timezone.now()
+ return context
+
+ **Example urls.py**::
+
+ from django.conf.urls import patterns, url
+
+ from article.views import ArticleListView
+
+ urlpatterns = patterns('',
+ url(r'^$', ArticleListView.as_view(), 'article-list'),
+ )
+
+.. class:: django.views.generic.list.BaseListView
+
+ A base view for displaying a list of objects. It is not intended to be used
+ directly, but rather as a parent class of the :class:`django.views.generic.list.ListView` or other views representing lists of objects.
+
+ **Ancestors (MRO)**
+
+ This view inherits methods and attributes from the following views:
+
+ * :class:`django.views.generic.list.MultipleObjectMixin`
+ * :class:`django.views.generic.base.View`
+
+ **Methods**
+
+ .. method:: get(request, *args, **kwargs)
+
+ Adds :attr:`object_list` to the context. If the :attr:`allow_empty`
+ is True then display an empty list. If the :attr:`allow_empty` is
+ False then raise a 404 error.
View
3  docs/ref/class-based-views/mixins-multiple-object.txt
@@ -83,7 +83,8 @@ Multiple object mixins
.. method:: get_queryset()
- Returns the queryset that represents the data this view will display.
+ Get the list of items for this view. This must be an iterable, and may
+ be a queryset (in which qs-specific behavior will be enabled).
.. method:: paginate_queryset(queryset, page_size)
View
38 docs/ref/class-based-views/mixins-simple.txt
@@ -6,16 +6,17 @@ Simple mixins
.. versionadded:: 1.5
- **classpath**
-
- ``django.views.generic.base.ContextMixin``
-
**Methods**
- .. method:: get_context_data(**kwargs)
+ .. method:: get_context_data( **kwargs):
+
+ Returns a dictionary representing the template context. The keyword
+ arguments provided will make up the returned context. Example usage::
- Returns a dictionary representing the template context. The
- keyword arguments provided will make up the returned context.
+ def get_context_data(self, **kwargs):
+ context = super(RandomNumberView, self).get_context_data(**kwargs)
+ context['number'] = random.randrange(1,100)
+ return context
.. class:: django.views.generic.base.TemplateResponseMixin
@@ -24,7 +25,13 @@ Simple mixins
suitable context. The template to use is configurable and can be
further customized by subclasses.
- **Methods and Attributes**
+ **Attributes**
+
+ .. attribute:: template_name = None
+
+ The full name of a template to use as defined by a string. Not defining a
+ template_name will raise a ``django.core.exceptions.ImproperlyConfigured``
+ exception.
.. attribute:: response_class
@@ -39,12 +46,14 @@ Simple mixins
instantiation, create a ``TemplateResponse`` subclass and assign it to
``response_class``.
+ **Methods**
+
.. method:: render_to_response(context, **response_kwargs)
Returns a ``self.response_class`` instance.
- If any keyword arguments are provided, they will be
- passed to the constructor of the response class.
+ If any keyword arguments are provided, they will be passed to the
+ constructor of the response class.
Calls :meth:`~TemplateResponseMixin.get_template_names()` to obtain the
list of template names that will be searched looking for an existent
@@ -52,9 +61,10 @@ Simple mixins
.. method:: get_template_names()
- Returns a list of template names to search for when rendering the
- template.
+ Returns a list of template names to search for when rendering the template.
- If :attr:`TemplateResponseMixin.template_name` is specified, the
- default implementation will return a list containing
+ If :attr:`TemplateResponseMixin.template_name` is specified, the default
+ implementation will return a list containing
:attr:`TemplateResponseMixin.template_name` (if it is specified).
+
+
Something went wrong with that request. Please try again.