Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Moved parts/admin/doc.py to contrib/admin/utils.py, where it belongs.…

… Also caught docutils ImportError in a more controlled way

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1463 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 2e7e19e0f2571a0514b7201c80fdd3bc4c648dbd 1 parent f237936
Adrian Holovaty authored November 27, 2005
15  django/parts/admin/doc.py → django/contrib/admin/utils.py
... ...
@@ -1,14 +1,17 @@
1  
-"""
2  
-Misc. utility functions/classes for documentation generator
3  
-"""
  1
+"Misc. utility functions/classes for admin documentation generator."
4 2
 
5 3
 import re
6 4
 from email.Parser import HeaderParser
7 5
 from email.Errors import HeaderParseError
8  
-import docutils.core
9  
-import docutils.nodes
10  
-import docutils.parsers.rst.roles
11 6
 from urlparse import urljoin
  7
+try:
  8
+    import docutils.core
  9
+    import docutils.nodes
  10
+    import docutils.parsers.rst.roles
  11
+except ImportError:
  12
+    docutils_is_available = False
  13
+else:
  14
+    docutils_is_available = True
12 15
 
13 16
 def trim_docstring(docstring):
14 17
     """
45  django/contrib/admin/views/doc.py
@@ -6,17 +6,14 @@
6 6
 from django.core.extensions import DjangoContext, render_to_response
7 7
 from django.core.exceptions import Http404, ViewDoesNotExist
8 8
 from django.core import template, urlresolvers
9  
-try:
10  
-    from django.parts.admin import doc
11  
-except ImportError:
12  
-    doc = None
  9
+from django.contrib.admin import utils
13 10
 import inspect, os, re
14 11
 
15 12
 # Exclude methods starting with these strings from documentation
16 13
 MODEL_METHODS_EXCLUDE = ('_', 'add_', 'delete', 'save', 'set_')
17 14
 
18 15
 def doc_index(request):
19  
-    if not doc:
  16
+    if not utils.docutils_is_available:
20 17
         return missing_docutils_page(request)
21 18
     return render_to_response('admin_doc/index', context_instance=DjangoContext(request))
22 19
 doc_index = staff_member_required(doc_index)
@@ -28,7 +25,7 @@ def bookmarklets(request):
28 25
 bookmarklets = staff_member_required(bookmarklets)
29 26
 
30 27
 def template_tag_index(request):
31  
-    if not doc:
  28
+    if not utils.docutils_is_available:
32 29
         return missing_docutils_page(request)
33 30
 
34 31
     load_all_installed_template_libraries()
@@ -36,13 +33,13 @@ def template_tag_index(request):
36 33
     tags = []
37 34
     for module_name, library in template.libraries.items():
38 35
         for tag_name, tag_func in library.tags.items():
39  
-            title, body, metadata = doc.parse_docstring(tag_func.__doc__)
  36
+            title, body, metadata = utils.parse_docstring(tag_func.__doc__)
40 37
             if title:
41  
-                title = doc.parse_rst(title, 'tag', 'tag:' + tag_name)
  38
+                title = utils.parse_rst(title, 'tag', 'tag:' + tag_name)
42 39
             if body:
43  
-                body = doc.parse_rst(body, 'tag', 'tag:' + tag_name)
  40
+                body = utils.parse_rst(body, 'tag', 'tag:' + tag_name)
44 41
             for key in metadata:
45  
-                metadata[key] = doc.parse_rst(metadata[key], 'tag', 'tag:' + tag_name)
  42
+                metadata[key] = utils.parse_rst(metadata[key], 'tag', 'tag:' + tag_name)
46 43
             if library in template.builtins:
47 44
                 tag_library = None
48 45
             else:
@@ -59,7 +56,7 @@ def template_tag_index(request):
59 56
 template_tag_index = staff_member_required(template_tag_index)
60 57
 
61 58
 def template_filter_index(request):
62  
-    if not doc:
  59
+    if not utils.docutils_is_available:
63 60
         return missing_docutils_page(request)
64 61
 
65 62
     load_all_installed_template_libraries()
@@ -67,13 +64,13 @@ def template_filter_index(request):
67 64
     filters = []
68 65
     for module_name, library in template.libraries.items():
69 66
         for filter_name, filter_func in library.filters.items():
70  
-            title, body, metadata = doc.parse_docstring(filter_func.__doc__)
  67
+            title, body, metadata = utils.parse_docstring(filter_func.__doc__)
71 68
             if title:
72  
-                title = doc.parse_rst(title, 'filter', 'filter:' + filter_name)
  69
+                title = utils.parse_rst(title, 'filter', 'filter:' + filter_name)
73 70
             if body:
74  
-                body = doc.parse_rst(body, 'filter', 'filter:' + filter_name)
  71
+                body = utils.parse_rst(body, 'filter', 'filter:' + filter_name)
75 72
             for key in metadata:
76  
-                metadata[key] = doc.parse_rst(metadata[key], 'filter', 'filter:' + filter_name)
  73
+                metadata[key] = utils.parse_rst(metadata[key], 'filter', 'filter:' + filter_name)
77 74
             if library in template.builtins:
78 75
                 tag_library = None
79 76
             else:
@@ -89,7 +86,7 @@ def template_filter_index(request):
89 86
 template_filter_index = staff_member_required(template_filter_index)
90 87
 
91 88
 def view_index(request):
92  
-    if not doc:
  89
+    if not utils.docutils_is_available:
93 90
         return missing_docutils_page(request)
94 91
 
95 92
     views = []
@@ -109,7 +106,7 @@ def view_index(request):
109 106
 view_index = staff_member_required(view_index)
110 107
 
111 108
 def view_detail(request, view):
112  
-    if not doc:
  109
+    if not utils.docutils_is_available:
113 110
         return missing_docutils_page(request)
114 111
 
115 112
     mod, func = urlresolvers.get_mod_func(view)
@@ -117,13 +114,13 @@ def view_detail(request, view):
117 114
         view_func = getattr(__import__(mod, '', '', ['']), func)
118 115
     except (ImportError, AttributeError):
119 116
         raise Http404
120  
-    title, body, metadata = doc.parse_docstring(view_func.__doc__)
  117
+    title, body, metadata = utils.parse_docstring(view_func.__doc__)
121 118
     if title:
122  
-        title = doc.parse_rst(title, 'view', 'view:' + view)
  119
+        title = utils.parse_rst(title, 'view', 'view:' + view)
123 120
     if body:
124  
-        body = doc.parse_rst(body, 'view', 'view:' + view)
  121
+        body = utils.parse_rst(body, 'view', 'view:' + view)
125 122
     for key in metadata:
126  
-        metadata[key] = doc.parse_rst(metadata[key], 'model', 'view:' + view)
  123
+        metadata[key] = utils.parse_rst(metadata[key], 'model', 'view:' + view)
127 124
     return render_to_response('admin_doc/view_detail', {
128 125
         'name': view,
129 126
         'summary': title,
@@ -133,7 +130,7 @@ def view_detail(request, view):
133 130
 view_detail = staff_member_required(view_detail)
134 131
 
135 132
 def model_index(request):
136  
-    if not doc:
  133
+    if not utils.docutils_is_available:
137 134
         return missing_docutils_page(request)
138 135
 
139 136
     models = []
@@ -149,7 +146,7 @@ def model_index(request):
149 146
 model_index = staff_member_required(model_index)
150 147
 
151 148
 def model_detail(request, model):
152  
-    if not doc:
  149
+    if not utils.docutils_is_available:
153 150
         return missing_docutils_page(request)
154 151
 
155 152
     try:
@@ -177,7 +174,7 @@ def model_detail(request, model):
177 174
                 continue
178 175
             verbose = func.__doc__
179 176
             if verbose:
180  
-                verbose = doc.parse_rst(doc.trim_docstring(verbose), 'model', 'model:' + opts.module_name)
  177
+                verbose = utils.parse_rst(utils.trim_docstring(verbose), 'model', 'model:' + opts.module_name)
181 178
             fields.append({
182 179
                 'name': func_name,
183 180
                 'data_type': get_return_data_type(func_name),
0  django/parts/admin/__init__.py
No changes.

0 notes on commit 2e7e19e

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