Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Made a bunch of fixes to auto-generated admin documentation:

    * Views are no longer "doubled"
    * Links work better (view -> model links and friends were broken)
    * Performance has been improved so now the pages no longer need to be cached.
    


git-svn-id: http://code.djangoproject.com/svn/django/trunk@391 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ce0d0cd9e2cd5ac9850d825f28db39b1e123ac1e 1 parent ffc3edd
Jacob Kaplan-Moss authored August 02, 2005
2  django/conf/admin_media/css/global.css
@@ -67,6 +67,8 @@ code, pre { font-family:"Bitstream Vera Sans Mono", Monaco, "Courier New", Couri
67 67
 pre.literal-block { margin:10px; background:#eee; padding:6px 8px; }
68 68
 code strong	{ color:#930; }
69 69
 hr { clear:both; color:#eee; background-color:#eee; height:1px; border:none; margin:0; padding:0; font-size:1px; line-height:1px; }
  70
+div.system-message { background: #ffc; margin: 10px; padding: 6px 8px; font-size: .8em; }
  71
+div.system-message p.system-message-title { padding:4px 5px 4px 25px; margin:0; color:red;background:#ffc url(../img/admin/icon_error.gif) 5px .3em no-repeat; }
70 72
 
71 73
 /*  PAGE STRUCTURE  */
72 74
 
3  django/conf/admin_templates/doc/index.html
@@ -21,9 +21,6 @@
21 21
 	<h3><a href="views/">Views</a></h3>
22 22
 	<p>Each page on the public site is generated by a view. The view defines which template is used to generate the page and which objects are available to that template.</p>
23 23
 
24  
-	<h3><a href="views/">Views</a></h3>
25  
-	<p>Each page on the public site is generated by a view. The view defines which template is used to generate the page and which objects are available to that template.</p>
26  
-
27 24
     <h3><a href="bookmarklets/">Bookmarklets</a></h3>
28 25
     <p>Tools for your browser to quickly access admin functionality.</p>
29 26
 </div>
34  django/conf/admin_templates/doc/view_index.html
@@ -10,37 +10,35 @@
10 10
 
11 11
 <h1>View documentation</h1>
12 12
 
  13
+{% regroup views|dictsort:"site_id" by site as views_by_site %}
  14
+
  15
+<div id="content-related" class="sidebar">
  16
+<div class="module">
  17
+<h2>Jump to site</h2>
  18
+<ul>
  19
+    {% for site_views in views_by_site %}
  20
+    <li><a href="#site{{ site_views.grouper.id }}">{{ site_views.grouper.name }}</a></li>
  21
+    {% endfor %}
  22
+</ul>
  23
+</div>
  24
+</div>
  25
+
13 26
 <div id="content-main">
14 27
 
15  
-{% regroup views|dictsort:"site_id" by site as views_by_site %}
16 28
 {% for site_views in views_by_site %}
17 29
 <div class="module">
18 30
 <h2 id="site{{ site_views.grouper.id }}">Views by URL on {{ site_views.grouper.name }}</h2>
19 31
 
20 32
 {% for view in site_views.list|dictsort:"url" %}
  33
+{% ifchanged %}
21 34
 <h3><a href="{{ view.module }}.{{ view.name }}/"/>{{ view.url|escape }}</a></h3>
22  
-<p class="small quiet">({{ view.module }}.{{ view.name }})</p>
  35
+<p class="small quiet">View function: {{ view.module }}.{{ view.name }}</p>
23 36
 <p>{{ view.title }}</p>
24 37
 <hr>
  38
+{% endifchanged %}
25 39
 {% endfor %}
26  
-
27 40
 </div>
28 41
 {% endfor %}
29  
-
30 42
 </div>
31  
-
32 43
 {% endblock %}
33 44
 
34  
-{% block sidebar %}
35  
-<div id="content-related" class="sidebar">
36  
-<div class="module">
37  
-<h2>Jump to site</h2>
38  
-<ul>
39  
-    {% regroup views|dictsort:"site_id" by site as views_by_site %}
40  
-    {% for site_views in views_by_site %}
41  
-    <li><a href="#site{{ site_views.grouper.id }}">{{ site_views.grouper.name }}</a></li>
42  
-    {% endfor %}
43  
-</ul>
44  
-</div>
45  
-</div>
46  
-{% endblock %}
10  django/core/defaulttags.py
@@ -470,7 +470,9 @@ def do_if(parser, token):
470 470
     """
471 471
     The ``{% if %}`` tag evaluates a variable, and if that variable is "true"
472 472
     (i.e. exists, is not empty, and is not a false boolean value) the contents
473  
-    of the block are output::
  473
+    of the block are output:
  474
+    
  475
+    ::
474 476
     
475 477
         {% if althlete_list %}
476 478
             Number of athletes: {{ althete_list|count }}
@@ -481,7 +483,7 @@ def do_if(parser, token):
481 483
     In the above, if ``athlete_list`` is not empty, the number of athletes will
482 484
     be displayed by the ``{{ athlete_list|count }}`` variable.
483 485
 
484  
-    As you can see, the ``if`` tag can take an option ``{% else %} clause that
  486
+    As you can see, the ``if`` tag can take an option ``{% else %}`` clause that
485 487
     will be displayed if the test fails.
486 488
 
487 489
     ``if`` tags may use ``or`` or ``not`` to test a number of variables or to
@@ -501,8 +503,8 @@ def do_if(parser, token):
501 503
             stupid; it's not my fault).
502 504
         {% endif %}
503 505
     
504  
-    For simplicity, ``if`` tags do not allow ``and`` clauses; use nested ``if``s
505  
-    instead::
  506
+    For simplicity, ``if`` tags do not allow ``and`` clauses; use nested ``if``
  507
+    tags instead::
506 508
     
507 509
         {% if athlete_list %}
508 510
             {% if coach_list %}
35  django/parts/admin/doc.py
@@ -8,18 +8,7 @@
8 8
 import docutils.core
9 9
 import docutils.nodes
10 10
 import docutils.parsers.rst.roles
11  
-
12  
-#
13  
-# reST roles
14  
-#
15  
-ROLES = {
16  
-    # role name,    base role url (in the admin)
17  
-    'model'    : '/doc/models/%s/',
18  
-    'view'     : '/doc/views/%s/',
19  
-    'template' : '/doc/templates/%s/',
20  
-    'filter'   : '/doc/filters/#%s',
21  
-    'tag'      : '/doc/tags/#%s',
22  
-}
  11
+from urlparse import urljoin
23 12
 
24 13
 def trim_docstring(docstring):
25 14
     """
@@ -60,31 +49,43 @@ def parse_docstring(docstring):
60 49
                 body = "\n\n".join(parts[1:])
61 50
     return title, body, metadata
62 51
 
63  
-def parse_rst(text, default_reference_context, thing_being_parsed=None):
  52
+def parse_rst(text, default_reference_context, thing_being_parsed=None, link_base='../..'):
64 53
     """
65 54
     Convert the string from reST to an XHTML fragment.
66 55
     """
67 56
     overrides = {
68  
-        'input_encoding' : 'unicode',
69 57
         'doctitle_xform' : True,
70 58
         'inital_header_level' : 3,
  59
+        "default_reference_context" : default_reference_context,
  60
+        "link_base" : link_base,
71 61
     }
72 62
     if thing_being_parsed:
73 63
         thing_being_parsed = "<%s>" % thing_being_parsed
74 64
     parts = docutils.core.publish_parts(text, source_path=thing_being_parsed,
75 65
                 destination_path=None, writer_name='html',
76  
-                settings_overrides={'default_reference_context' : default_reference_context})
  66
+                settings_overrides=overrides)
77 67
     return parts['fragment']
78 68
 
  69
+#
  70
+# reST roles
  71
+#
  72
+ROLES = {
  73
+    'model'    : '%s/models/%s/',
  74
+    'view'     : '%s/views/%s/',
  75
+    'template' : '%s/templates/%s/',
  76
+    'filter'   : '%s/filters/#%s',
  77
+    'tag'      : '%s/tags/#%s',
  78
+}
  79
+
79 80
 def create_reference_role(rolename, urlbase):
80 81
     def _role(name, rawtext, text, lineno, inliner, options={}, content=[]):
81  
-        node = docutils.nodes.reference(rawtext, text, refuri=(urlbase % text), **options)
  82
+        node = docutils.nodes.reference(rawtext, text, refuri=(urlbase % (inliner.document.settings.link_base, text)), **options)
82 83
         return [node], []
83 84
     docutils.parsers.rst.roles.register_canonical_role(rolename, _role)
84 85
 
85 86
 def default_reference_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
86 87
     context = inliner.document.settings.default_reference_context
87  
-    node = docutils.nodes.reference(rawtext, text, refuri=(ROLES[context] % text), **options)
  88
+    node = docutils.nodes.reference(rawtext, text, refuri=(ROLES[context] % (inliner.document.settings.link_base, text)), **options)
88 89
     return [node], []
89 90
 docutils.parsers.rst.roles.register_canonical_role('cmsreference', default_reference_role)
90 91
 docutils.parsers.rst.roles.DEFAULT_INTERPRETED_ROLE = 'cmsreference'
14  django/templatetags/log.py
@@ -17,14 +17,20 @@ def render(self, context):
17 17
 class DoGetAdminLog:
18 18
     """
19 19
     Populates a template variable with the admin log for the given criteria.
20  
-    Usage:
  20
+    
  21
+    Usage::
  22
+    
21 23
         {% get_admin_log [limit] as [varname] for_user [context_var_containing_user_obj] %}
22  
-    Examples:
  24
+        
  25
+    Examples::
  26
+        
23 27
         {% get_admin_log 10 as admin_log for_user 23 %}
24 28
         {% get_admin_log 10 as admin_log for_user user %}
25 29
         {% get_admin_log 10 as admin_log %}
26  
-    Note that [context_var_containing_user_obj] can be a hard-coded integer (user ID) or the
27  
-    name of a template context variable containing the user object whose ID you want.
  30
+    
  31
+    Note that ``context_var_containing_user_obj`` can be a hard-coded integer
  32
+    (user ID) or the name of a template context variable containing the user
  33
+    object whose ID you want.
28 34
     """
29 35
     def __init__(self, tag_name):
30 36
         self.tag_name = tag_name
12  django/views/admin/doc.py
@@ -2,7 +2,6 @@
2 2
 from django import templatetags
3 3
 from django.conf import settings
4 4
 from django.models.core import sites
5  
-from django.views.decorators.cache import cache_page
6 5
 from django.core.extensions import DjangoContext as Context
7 6
 from django.core.exceptions import Http404, ViewDoesNotExist
8 7
 from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect
@@ -32,6 +31,8 @@ def bookmarklets(request):
32 31
     return HttpResponse(t.render(c))
33 32
 
34 33
 def template_tag_index(request):
  34
+    import sys
  35
+
35 36
     if not doc:
36 37
         return missing_docutils_page(request)
37 38
 
@@ -69,7 +70,6 @@ def template_tag_index(request):
69 70
         'tags' : tags,
70 71
     })
71 72
     return HttpResponse(t.render(c))
72  
-template_tag_index = cache_page(template_tag_index, 15*60)
73 73
 
74 74
 def template_filter_index(request):
75 75
     if not doc:
@@ -106,7 +106,6 @@ def template_filter_index(request):
106 106
         'filters' : filters,
107 107
     })
108 108
     return HttpResponse(t.render(c))
109  
-template_filter_index = cache_page(template_filter_index, 15*60)
110 109
 
111 110
 def view_index(request):
112 111
     if not doc:
@@ -118,13 +117,9 @@ def view_index(request):
118 117
         urlconf = __import__(settings_mod.ROOT_URLCONF, '', '', [''])
119 118
         view_functions = extract_views_from_urlpatterns(urlconf.urlpatterns)
120 119
         for (func, regex) in view_functions:
121  
-            title, body, metadata = doc.parse_docstring(func.__doc__)
122  
-            if title:
123  
-                title = doc.parse_rst(title, 'view', 'view:' + func.__name__)
124 120
             views.append({
125 121
                 'name'   : func.__name__,
126 122
                 'module' : func.__module__,
127  
-                'title'  : title,
128 123
                 'site_id': settings_mod.SITE_ID,
129 124
                 'site'   : sites.get_object(pk=settings_mod.SITE_ID),
130 125
                 'url'    : simplify_regex(regex),
@@ -134,7 +129,6 @@ def view_index(request):
134 129
         'views' : views,
135 130
     })
136 131
     return HttpResponse(t.render(c))
137  
-view_index = cache_page(view_index, 15*60)
138 132
 
139 133
 def view_detail(request, view):
140 134
     if not doc:
@@ -151,7 +145,7 @@ def view_detail(request, view):
151 145
     if body:
152 146
         body = doc.parse_rst(body, 'view', 'view:' + view)
153 147
     for key in metadata:
154  
-        metadata[key] = doc.parse_rst(metadata[key], 'view', 'view:' + view)
  148
+        metadata[key] = doc.parse_rst(metadata[key], 'model', 'view:' + view)
155 149
     t = template_loader.get_template('doc/view_detail')
156 150
     c = Context(request, {
157 151
         'name'      : view,

0 notes on commit ce0d0cd

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