Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: django/django
...
head fork: kennethlove/django
Checking mergeability… Don't worry, you can still create the pull request.
  • 5 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jun 08, 2012
@kennethlove kennethlove Updates to the edit views' docstrings.
Signed-off-by: Kenneth Love <kenneth@gigantuan.net>
632b801
@kennethlove kennethlove Updates to the date views
Signed-off-by: Kenneth Love <kenneth@gigantuan.net>
efe4601
@kennethlove kennethlove Updates to the base views
Signed-off-by: Kenneth Love <kenneth@gigantuan.net>
1282938
@kennethlove kennethlove Updates to the detail views
Signed-off-by: Kenneth Love <kenneth@gigantuan.net>
ba0e4c5
@kennethlove kennethlove Updates to the list views
Signed-off-by: Kenneth Love <kenneth@gigantuan.net>
70b9b3a
View
3  django/views/generic/base.py
@@ -90,6 +90,9 @@ def http_method_not_allowed(self, request, *args, **kwargs):
return http.HttpResponseNotAllowed(self._allowed_methods())
def options(self, request, *args, **kwargs):
+ """
+ Handles responding to requests for the OPTIONS HTTP verb.
+ """
response = http.HttpResponse()
response['Allow'] = ', '.join(self._allowed_methods())
response['Content-Length'] = 0
View
14 django/views/generic/dates.py
@@ -14,6 +14,9 @@
from django.views.generic.list import MultipleObjectMixin, MultipleObjectTemplateResponseMixin
class YearMixin(object):
+ """
+ Mixin for views manipulating year-based data.
+ """
year_format = '%Y'
year = None
@@ -67,6 +70,9 @@ def _get_current_year(self, date):
class MonthMixin(object):
+ """
+ Mixin for views manipulating month-based data.
+ """
month_format = '%b'
month = None
@@ -123,6 +129,9 @@ def _get_current_month(self, date):
class DayMixin(object):
+ """
+ Mixin for views manipulating day-based data.
+ """
day_format = '%d'
day = None
@@ -176,6 +185,9 @@ def _get_current_day(self, date):
class WeekMixin(object):
+ """
+ Mixin for views manipulating week-based data.
+ """
week_format = '%U'
week = None
@@ -312,7 +324,7 @@ def _make_single_date_lookup(self, date):
class BaseDateListView(MultipleObjectMixin, DateMixin, View):
"""
- Abstract base class for date-based views display a list of objects.
+ Abstract base class for date-based views displaying a list of objects.
"""
allow_empty = False
View
7 django/views/generic/detail.py
@@ -47,6 +47,7 @@ def get_object(self, queryset=None):
% self.__class__.__name__)
try:
+ # Get the single item from the filtered queryset
obj = queryset.get()
except ObjectDoesNotExist:
raise Http404(_("No %(verbose_name)s found matching the query") %
@@ -87,6 +88,9 @@ def get_context_object_name(self, obj):
return None
def get_context_data(self, **kwargs):
+ """
+ Insert the single object into the context dict.
+ """
context = {}
context_object_name = self.get_context_object_name(self.object)
if context_object_name:
@@ -96,6 +100,9 @@ def get_context_data(self, **kwargs):
class BaseDetailView(SingleObjectMixin, View):
+ """
+ A base view for displaying a single object
+ """
def get(self, request, *args, **kwargs):
self.object = self.get_object()
context = self.get_context_data(object=self.object)
View
38 django/views/generic/edit.py
@@ -46,6 +46,9 @@ def get_form_kwargs(self):
return kwargs
def get_success_url(self):
+ """
+ Returns the supplied success URL.
+ """
if self.success_url:
url = self.success_url
else:
@@ -54,9 +57,16 @@ def get_success_url(self):
return url
def form_valid(self, form):
+ """
+ If the form is valid, redirect to the supplied URL.
+ """
return HttpResponseRedirect(self.get_success_url())
def form_invalid(self, form):
+ """
+ If the form is invalid, re-render the context data with the
+ data-filled form and errors.
+ """
return self.render_to_response(self.get_context_data(form=form))
@@ -67,7 +77,7 @@ class ModelFormMixin(FormMixin, SingleObjectMixin):
def get_form_class(self):
"""
- Returns the form class to use in this view
+ Returns the form class to use in this view.
"""
if self.form_class:
return self.form_class
@@ -94,6 +104,9 @@ def get_form_kwargs(self):
return kwargs
def get_success_url(self):
+ """
+ Returns the supplied URL.
+ """
if self.success_url:
url = self.success_url % self.object.__dict__
else:
@@ -106,10 +119,17 @@ def get_success_url(self):
return url
def form_valid(self, form):
+ """
+ If the form is valid, save is associated model.
+ """
self.object = form.save()
return super(ModelFormMixin, self).form_valid(form)
def get_context_data(self, **kwargs):
+ """
+ If an object has been supplied, inject it into the context with the
+ supplied context_object_name name.
+ """
context = {}
if self.object:
context['object'] = self.object
@@ -125,11 +145,19 @@ class ProcessFormView(View):
A mixin that processes a form on POST.
"""
def get(self, request, *args, **kwargs):
+ """
+ Handles the GET HTTP verb and instantiates a blank version of the form.
+ """
form_class = self.get_form_class()
form = self.get_form(form_class)
return self.render_to_response(self.get_context_data(form=form))
def post(self, request, *args, **kwargs):
+ """
+ Handles the POST HTTP verb, instantiating an instance of the class
+ that is passed the contents of the POST request dict and then checked
+ for validity.
+ """
form_class = self.get_form_class()
form = self.get_form(form_class)
if form.is_valid():
@@ -172,7 +200,7 @@ def post(self, request, *args, **kwargs):
class CreateView(SingleObjectTemplateResponseMixin, BaseCreateView):
"""
- View for creating an new object instance,
+ View for creating a new object instance,
with a response rendered by template.
"""
template_name_suffix = '_form'
@@ -196,7 +224,7 @@ def post(self, request, *args, **kwargs):
class UpdateView(SingleObjectTemplateResponseMixin, BaseUpdateView):
"""
View for updating an object,
- with a response rendered by template..
+ with a response rendered by template.
"""
template_name_suffix = '_form'
@@ -208,6 +236,10 @@ class DeletionMixin(object):
success_url = None
def delete(self, request, *args, **kwargs):
+ """
+ Calls the delete() method on the fetched object and then
+ redirects to the success URL.
+ """
self.object = self.get_object()
self.object.delete()
return HttpResponseRedirect(self.get_success_url())
View
9 django/views/generic/list.py
@@ -8,6 +8,9 @@
class MultipleObjectMixin(ContextMixin):
+ """
+ A mixin for views manipulating multiple objects.
+ """
allow_empty = True
queryset = None
model = None
@@ -111,6 +114,9 @@ def get_context_data(self, **kwargs):
class BaseListView(MultipleObjectMixin, View):
+ """
+ A base view for displaying a list of objects.
+ """
def get(self, request, *args, **kwargs):
self.object_list = self.get_queryset()
allow_empty = self.get_allow_empty()
@@ -132,6 +138,9 @@ def get(self, request, *args, **kwargs):
class MultipleObjectTemplateResponseMixin(TemplateResponseMixin):
+ """
+ Mixin for responding with a template and list of objects.
+ """
template_name_suffix = '_list'
def get_template_names(self):

No commit comments for this range

Something went wrong with that request. Please try again.