From 81545940c68de0d1235a2fb50e61b8619f17a3e3 Mon Sep 17 00:00:00 2001 From: Baptiste Darthenay Date: Tue, 11 Jun 2013 22:32:39 +0200 Subject: [PATCH] Fixed #20565 -- Added template examples for GCBV. Thanks to David Reitter for the report, and to Marc Tamlyn and Baptiste Mispelon for the review. --- .../class-based-views/generic-date-based.txt | 24 ++++----- .../ref/class-based-views/generic-display.txt | 29 +++++++++-- .../ref/class-based-views/generic-editing.txt | 49 ++++++++++++++++--- 3 files changed, 81 insertions(+), 21 deletions(-) diff --git a/docs/ref/class-based-views/generic-date-based.txt b/docs/ref/class-based-views/generic-date-based.txt index 1ebee254b1..205d556463 100644 --- a/docs/ref/class-based-views/generic-date-based.txt +++ b/docs/ref/class-based-views/generic-date-based.txt @@ -63,7 +63,7 @@ ArchiveIndexView month or day using the attribute ``date_list_period``. This also applies to all subclass views. - **Example views.py**:: + **Example myapp/views.py**:: from django.conf.urls import patterns, url from django.views.generic.dates import ArchiveIndexView @@ -160,7 +160,7 @@ YearArchiveView * Uses a default ``template_name_suffix`` of ``_archive_year``. - **Example views.py**:: + **Example myapp/views.py**:: from django.views.generic.dates import YearArchiveView @@ -172,7 +172,7 @@ YearArchiveView make_object_list = True allow_future = True - **Example urls.py**:: + **Example myapp/urls.py**:: from django.conf.urls import patterns, url @@ -255,7 +255,7 @@ MonthArchiveView * Uses a default ``template_name_suffix`` of ``_archive_month``. - **Example views.py**:: + **Example myapp/views.py**:: from django.views.generic.dates import MonthArchiveView @@ -267,7 +267,7 @@ MonthArchiveView make_object_list = True allow_future = True - **Example urls.py**:: + **Example myapp/urls.py**:: from django.conf.urls import patterns, url @@ -348,7 +348,7 @@ WeekArchiveView * Uses a default ``template_name_suffix`` of ``_archive_week``. - **Example views.py**:: + **Example myapp/views.py**:: from django.views.generic.dates import WeekArchiveView @@ -361,7 +361,7 @@ WeekArchiveView week_format = "%W" allow_future = True - **Example urls.py**:: + **Example myapp/urls.py**:: from django.conf.urls import patterns, url @@ -463,7 +463,7 @@ DayArchiveView * Uses a default ``template_name_suffix`` of ``_archive_day``. - **Example views.py**:: + **Example myapp/views.py**:: from django.views.generic.dates import DayArchiveView @@ -475,7 +475,7 @@ DayArchiveView make_object_list = True allow_future = True - **Example urls.py**:: + **Example myapp/urls.py**:: from django.conf.urls import patterns, url @@ -537,7 +537,7 @@ TodayArchiveView * Uses a default ``template_name_suffix`` of ``_archive_today``. - **Example views.py**:: + **Example myapp/views.py**:: from django.views.generic.dates import TodayArchiveView @@ -549,7 +549,7 @@ TodayArchiveView make_object_list = True allow_future = True - **Example urls.py**:: + **Example myapp/urls.py**:: from django.conf.urls import patterns, url @@ -599,7 +599,7 @@ DateDetailView * Uses a default ``template_name_suffix`` of ``_detail``. - **Example urls.py**:: + **Example myapp/urls.py**:: from django.conf.urls import patterns, url from django.views.generic.dates import DateDetailView diff --git a/docs/ref/class-based-views/generic-display.txt b/docs/ref/class-based-views/generic-display.txt index c133134d65..7fc95ac5d2 100644 --- a/docs/ref/class-based-views/generic-display.txt +++ b/docs/ref/class-based-views/generic-display.txt @@ -36,7 +36,7 @@ DetailView 9. ``get()`` 10. :meth:`~django.views.generic.base.TemplateResponseMixin.render_to_response()` - **Example views.py**:: + **Example myapp/views.py**:: from django.views.generic.detail import DetailView from django.utils import timezone @@ -52,7 +52,7 @@ DetailView context['now'] = timezone.now() return context - **Example urls.py**:: + **Example myapp/urls.py**:: from django.conf.urls import patterns, url @@ -62,6 +62,16 @@ DetailView url(r'^(?P[-_\w]+)/$', ArticleDetailView.as_view(), name='article-detail'), ) + **Example myapp/article_detail.html**: + + .. code-block:: html+django + +

{{ object.headline }}

+

{{ object.content }}

+

Reporter: {{ object.reporter }}

+

Published: {{ object.pub_date|date }}

+

Date: {{ object.now|date }}

+ ListView -------- @@ -111,7 +121,7 @@ ListView context['now'] = timezone.now() return context - **Example urls.py**:: + **Example myapp/urls.py**:: from django.conf.urls import patterns, url @@ -121,6 +131,19 @@ ListView url(r'^$', ArticleListView.as_view(), name='article-list'), ) + **Example myapp/article_list.html**: + + .. code-block:: html+django + +

Articles

+ + .. class:: django.views.generic.list.BaseListView A base view for displaying a list of objects. It is not intended to be used diff --git a/docs/ref/class-based-views/generic-editing.txt b/docs/ref/class-based-views/generic-editing.txt index c1fb2dcca9..51dfe7c71b 100644 --- a/docs/ref/class-based-views/generic-editing.txt +++ b/docs/ref/class-based-views/generic-editing.txt @@ -42,7 +42,7 @@ FormView * :class:`django.views.generic.edit.ProcessFormView` * :class:`django.views.generic.base.View` - **Example forms.py**:: + **Example myapp/forms.py**:: from django import forms @@ -54,7 +54,7 @@ FormView # send email using the self.cleaned_data dictionary pass - **Example views.py**:: + **Example myapp/views.py**:: from myapp.forms import ContactForm from django.views.generic.edit import FormView @@ -70,6 +70,16 @@ FormView form.send_email() return super(ContactView, self).form_valid(form) + **Example myapp/contact.html**: + + .. code-block:: html+django + +
{% csrf_token %} + {{ form.as_p }} + +
+ + CreateView ---------- @@ -101,7 +111,7 @@ CreateView creating objects for the example ``Author`` model would cause the default ``template_name`` to be ``'myapp/author_create_form.html'``. - **Example views.py**:: + **Example myapp/views.py**:: from django.views.generic.edit import CreateView from myapp.models import Author @@ -110,6 +120,15 @@ CreateView model = Author fields = ['name'] + **Example myapp/author_form.html**: + + .. code-block:: html+django + +
{% csrf_token %} + {{ form.as_p }} + +
+ UpdateView ---------- @@ -143,7 +162,7 @@ UpdateView updating objects for the example ``Author`` model would cause the default ``template_name`` to be ``'myapp/author_update_form.html'``. - **Example views.py**:: + **Example myapp/views.py**:: from django.views.generic.edit import UpdateView from myapp.models import Author @@ -151,6 +170,16 @@ UpdateView class AuthorUpdate(UpdateView): model = Author fields = ['name'] + template_name_suffix = '_update_form' + + **Example myapp/author_update_form.html**: + + .. code-block:: html+django + +
{% csrf_token %} + {{ form.as_p }} + +
DeleteView ---------- @@ -184,8 +213,7 @@ DeleteView deleting objects for the example ``Author`` model would cause the default ``template_name`` to be ``'myapp/author_check_delete.html'``. - - **Example views.py**:: + **Example myapp/views.py**:: from django.views.generic.edit import DeleteView from django.core.urlresolvers import reverse_lazy @@ -194,3 +222,12 @@ DeleteView class AuthorDelete(DeleteView): model = Author success_url = reverse_lazy('author-list') + + **Example myapp/author_confirm_delete.html**: + + .. code-block:: html+django + +
{% csrf_token %} +

Are you sure you want to delete "{{ object }}"?

+ +