Skip to content

Commit d95e91b

Browse files
committed
Added docstrings to shortcuts module and functions.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5744 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent bac6a2f commit d95e91b

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

django/shortcuts/__init__.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
1-
# This module collects helper functions and classes that "span" multiple levels
2-
# of MVC. In other words, these functions/classes introduce controlled coupling
3-
# for convenience's sake.
1+
"""
2+
This module collects helper functions and classes that "span" multiple levels
3+
of MVC. In other words, these functions/classes introduce controlled coupling
4+
for convenience's sake.
5+
"""
46

57
from django.template import loader
68
from django.http import HttpResponse, Http404
79
from django.db.models.manager import Manager
810

911
def render_to_response(*args, **kwargs):
12+
"""
13+
Return a HttpResponse whose content is filled with the result of calling
14+
django.template.loader.render_to_string() with the passed arguments.
15+
"""
1016
return HttpResponse(loader.render_to_string(*args, **kwargs))
1117
load_and_render = render_to_response # For backwards compatibility.
1218

1319
def get_object_or_404(klass, *args, **kwargs):
20+
"""
21+
Use get() to return an object, or raise a Http404 exception if the object
22+
does not exist.
23+
24+
klass may be a Model, Manager, or QuerySet object. All other passed
25+
arguments and keyword arguments are used in the get() query.
26+
27+
Note: Like with get(), an AssertionError will be raised if more than one
28+
object is found.
29+
"""
1430
if isinstance(klass, Manager):
1531
manager = klass
1632
klass = manager.model
@@ -22,6 +38,13 @@ def get_object_or_404(klass, *args, **kwargs):
2238
raise Http404('No %s matches the given query.' % klass._meta.object_name)
2339

2440
def get_list_or_404(klass, *args, **kwargs):
41+
"""
42+
Use filter() to return a list of objects, or raise a Http404 exception if
43+
the list is empty.
44+
45+
klass may be a Model, Manager, or QuerySet object. All other passed
46+
arguments and keyword arguments are used in the filter() query.
47+
"""
2548
if isinstance(klass, Manager):
2649
manager = klass
2750
else:

0 commit comments

Comments
 (0)