Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added docstrings to shortcuts module and functions.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5744 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit d95e91b380a72cc2011ee48c7875517984e723c2 1 parent bac6a2f
Gary Wilson Jr. authored July 22, 2007

Showing 1 changed file with 26 additions and 3 deletions. Show diff stats Hide diff stats

  1. 29  django/shortcuts/__init__.py
29  django/shortcuts/__init__.py
... ...
@@ -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
+"""
4 6
 
5 7
 from django.template import loader
6 8
 from django.http import HttpResponse, Http404
7 9
 from django.db.models.manager import Manager
8 10
 
9 11
 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
+    """
10 16
     return HttpResponse(loader.render_to_string(*args, **kwargs))
11 17
 load_and_render = render_to_response # For backwards compatibility.
12 18
 
13 19
 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
+    """
14 30
     if isinstance(klass, Manager):
15 31
         manager = klass
16 32
         klass = manager.model
@@ -22,6 +38,13 @@ def get_object_or_404(klass, *args, **kwargs):
22 38
         raise Http404('No %s matches the given query.' % klass._meta.object_name)
23 39
 
24 40
 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
+    """
25 48
     if isinstance(klass, Manager):
26 49
         manager = klass
27 50
     else:

0 notes on commit d95e91b

Please sign in to comment.
Something went wrong with that request. Please try again.