Django

Code

Changeset 391

Show
Ignore:
Timestamp:
08/02/05 14:59:51 (3 years ago)
Author:
jacob
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/conf/admin_media/css/global.css

    r387 r391  
    6868code strong     { color:#930; } 
    6969hr { clear:both; color:#eee; background-color:#eee; height:1px; border:none; margin:0; padding:0; font-size:1px; line-height:1px; } 
     70div.system-message { background: #ffc; margin: 10px; padding: 6px 8px; font-size: .8em; } 
     71div.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; } 
    7072 
    7173/*  PAGE STRUCTURE  */ 
  • django/trunk/django/conf/admin_templates/doc/index.html

    r337 r391  
    2222        <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> 
    2323 
    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  
    2724    <h3><a href="bookmarklets/">Bookmarklets</a></h3> 
    2825    <p>Tools for your browser to quickly access admin functionality.</p> 
  • django/trunk/django/conf/admin_templates/doc/view_index.html

    r337 r391  
    1111<h1>View documentation</h1> 
    1212 
    13 <div id="content-main"> 
     13{% regroup views|dictsort:"site_id" by site as views_by_site %} 
    1414 
    15 {% regroup views|dictsort:"site_id" by site as views_by_site %} 
    16 {% for site_views in views_by_site %} 
    17 <div class="module"> 
    18 <h2 id="site{{ site_views.grouper.id }}">Views by URL on {{ site_views.grouper.name }}</h2> 
    19  
    20 {% for view in site_views.list|dictsort:"url" %} 
    21 <h3><a href="{{ view.module }}.{{ view.name }}/"/>{{ view.url|escape }}</a></h3> 
    22 <p class="small quiet">({{ view.module }}.{{ view.name }})</p> 
    23 <p>{{ view.title }}</p> 
    24 <hr> 
    25 {% endfor %} 
    26  
    27 </div> 
    28 {% endfor %} 
    29  
    30 </div> 
    31  
    32 {% endblock %} 
    33  
    34 {% block sidebar %} 
    3515<div id="content-related" class="sidebar"> 
    3616<div class="module"> 
    3717<h2>Jump to site</h2> 
    3818<ul> 
    39     {% regroup views|dictsort:"site_id" by site as views_by_site %} 
    4019    {% for site_views in views_by_site %} 
    4120    <li><a href="#site{{ site_views.grouper.id }}">{{ site_views.grouper.name }}</a></li> 
     
    4423</div> 
    4524</div> 
     25 
     26<div id="content-main"> 
     27 
     28{% for site_views in views_by_site %} 
     29<div class="module"> 
     30<h2 id="site{{ site_views.grouper.id }}">Views by URL on {{ site_views.grouper.name }}</h2> 
     31 
     32{% for view in site_views.list|dictsort:"url" %} 
     33{% ifchanged %} 
     34<h3><a href="{{ view.module }}.{{ view.name }}/"/>{{ view.url|escape }}</a></h3> 
     35<p class="small quiet">View function: {{ view.module }}.{{ view.name }}</p> 
     36<p>{{ view.title }}</p> 
     37<hr> 
     38{% endifchanged %} 
     39{% endfor %} 
     40</div> 
     41{% endfor %} 
     42</div> 
    4643{% endblock %} 
     44 
  • django/trunk/django/core/defaulttags.py

    r390 r391  
    471471    The ``{% if %}`` tag evaluates a variable, and if that variable is "true" 
    472472    (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    :: 
    474476     
    475477        {% if althlete_list %} 
     
    482484    be displayed by the ``{{ athlete_list|count }}`` variable. 
    483485 
    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 
    485487    will be displayed if the test fails. 
    486488 
     
    502504        {% endif %} 
    503505     
    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:: 
    506508     
    507509        {% if athlete_list %} 
  • django/trunk/django/parts/admin/doc.py

    r3 r391  
    99import docutils.nodes 
    1010import 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 
     11from urlparse import urljoin 
    2312 
    2413def trim_docstring(docstring): 
     
    6150    return title, body, metadata 
    6251 
    63 def parse_rst(text, default_reference_context, thing_being_parsed=None): 
     52def parse_rst(text, default_reference_context, thing_being_parsed=None, link_base='../..'): 
    6453    """ 
    6554    Convert the string from reST to an XHTML fragment. 
    6655    """ 
    6756    overrides = { 
    68         'input_encoding' : 'unicode', 
    6957        'doctitle_xform' : True, 
    7058        'inital_header_level' : 3, 
     59        "default_reference_context" : default_reference_context, 
     60        "link_base" : link_base, 
    7161    } 
    7262    if thing_being_parsed: 
     
    7464    parts = docutils.core.publish_parts(text, source_path=thing_being_parsed, 
    7565                destination_path=None, writer_name='html', 
    76                 settings_overrides={'default_reference_context' : default_reference_context}
     66                settings_overrides=overrides
    7767    return parts['fragment'] 
     68 
     69# 
     70# reST roles 
     71# 
     72ROLES = { 
     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} 
    7879 
    7980def create_reference_role(rolename, urlbase): 
    8081    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) 
    8283        return [node], [] 
    8384    docutils.parsers.rst.roles.register_canonical_role(rolename, _role) 
     
    8586def default_reference_role(name, rawtext, text, lineno, inliner, options={}, content=[]): 
    8687    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) 
    8889    return [node], [] 
    8990docutils.parsers.rst.roles.register_canonical_role('cmsreference', default_reference_role) 
  • django/trunk/django/templatetags/log.py

    r3 r391  
    1818    """ 
    1919    Populates a template variable with the admin log for the given criteria. 
    20     Usage: 
     20     
     21    Usage:: 
     22     
    2123        {% get_admin_log [limit] as [varname] for_user [context_var_containing_user_obj] %} 
    22     Examples: 
     24         
     25    Examples:: 
     26         
    2327        {% get_admin_log 10 as admin_log for_user 23 %} 
    2428        {% get_admin_log 10 as admin_log for_user user %} 
    2529        {% 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. 
    2834    """ 
    2935    def __init__(self, tag_name): 
  • django/trunk/django/views/admin/doc.py

    r316 r391  
    33from django.conf import settings 
    44from django.models.core import sites 
    5 from django.views.decorators.cache import cache_page 
    65from django.core.extensions import DjangoContext as Context 
    76from django.core.exceptions import Http404, ViewDoesNotExist 
     
    3332 
    3433def template_tag_index(request): 
     34    import sys 
     35 
    3536    if not doc: 
    3637        return missing_docutils_page(request) 
     
    7071    }) 
    7172    return HttpResponse(t.render(c)) 
    72 template_tag_index = cache_page(template_tag_index, 15*60) 
    7373 
    7474def template_filter_index(request): 
     
    107107    }) 
    108108    return HttpResponse(t.render(c)) 
    109 template_filter_index = cache_page(template_filter_index, 15*60) 
    110109 
    111110def view_index(request): 
     
    119118        view_functions = extract_views_from_urlpatterns(urlconf.urlpatterns) 
    120119        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__) 
    124120            views.append({ 
    125121                'name'   : func.__name__, 
    126122                'module' : func.__module__, 
    127                 'title'  : title, 
    128123                'site_id': settings_mod.SITE_ID, 
    129124                'site'   : sites.get_object(pk=settings_mod.SITE_ID), 
     
    135130    }) 
    136131    return HttpResponse(t.render(c)) 
    137 view_index = cache_page(view_index, 15*60) 
    138132 
    139133def view_detail(request, view): 
     
    152146        body = doc.parse_rst(body, 'view', 'view:' + view) 
    153147    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) 
    155149    t = template_loader.get_template('doc/view_detail') 
    156150    c = Context(request, {