Django

Code

Changeset 8718

Show
Ignore:
Timestamp:
08/29/08 14:29:16 (3 months ago)
Author:
jacob
Message:

Fixed #7466: do a better job figuring out links from the admin docs into the rest of the admin.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/contrib/admindocs/views.py

    r8046 r8718  
    2121    name = 'my site' 
    2222 
     23def get_root_path(): 
     24    from django.contrib import admin 
     25    try: 
     26        return urlresolvers.reverse(admin.site.root, args=['']) 
     27    except urlresolvers.NoReverseMatch: 
     28        return getattr(settings, "ADMIN_SITE_ROOT_URL", "/admin/") 
     29 
    2330def doc_index(request): 
    2431    if not utils.docutils_is_available: 
    2532        return missing_docutils_page(request) 
    26     root_path = re.sub(re.escape('doc/') + '$', '', request.path) 
    2733    return render_to_response('admin_doc/index.html', { 
    28         'root_path': root_path
     34        'root_path': get_root_path()
    2935    }, context_instance=RequestContext(request)) 
    3036doc_index = staff_member_required(doc_index) 
    3137 
    3238def bookmarklets(request): 
    33     # Hack! This couples this view to the URL it lives at. 
    34     admin_root = request.path[:-len('doc/bookmarklets/')] 
    35     root_path = re.sub(re.escape('doc/bookmarklets/') + '$', '', request.path) 
     39    admin_root = get_root_path() 
    3640    return render_to_response('admin_doc/bookmarklets.html', { 
    37         'root_path': root_path
     41        'root_path': admin_root
    3842        'admin_url': mark_safe("%s://%s%s" % (request.is_secure() and 'https' or 'http', request.get_host(), admin_root)), 
    3943    }, context_instance=RequestContext(request)) 
     
    6771                'library': tag_library, 
    6872            }) 
    69     root_path = re.sub(re.escape('doc/tags/') + '$', '', request.path) 
    7073    return render_to_response('admin_doc/template_tag_index.html', { 
    71         'root_path': root_path
     74        'root_path': get_root_path()
    7275        'tags': tags 
    7376    }, context_instance=RequestContext(request)) 
     
    101104                'library': tag_library, 
    102105            }) 
    103     root_path = re.sub(re.escape('doc/filters/') + '$', '', request.path) 
    104106    return render_to_response('admin_doc/template_filter_index.html', { 
    105         'root_path': root_path
     107        'root_path': get_root_path()
    106108        'filters': filters 
    107109    }, context_instance=RequestContext(request)) 
     
    133135                'url': simplify_regex(regex), 
    134136            }) 
    135     root_path = re.sub(re.escape('doc/views/') + '$', '', request.path) 
    136137    return render_to_response('admin_doc/view_index.html', { 
    137         'root_path': root_path
     138        'root_path': get_root_path()
    138139        'views': views 
    139140    }, context_instance=RequestContext(request)) 
     
    156157    for key in metadata: 
    157158        metadata[key] = utils.parse_rst(metadata[key], 'model', _('view:') + view) 
    158     root_path = re.sub(re.escape('doc/views/%s/' % view) + '$', '', request.path) 
    159159    return render_to_response('admin_doc/view_detail.html', { 
    160         'root_path': root_path
     160        'root_path': get_root_path()
    161161        'name': view, 
    162162        'summary': title, 
     
    170170        return missing_docutils_page(request) 
    171171    m_list = [m._meta for m in models.get_models()] 
    172     root_path = re.sub(re.escape('doc/models/') + '$', '', request.path) 
    173172    return render_to_response('admin_doc/model_index.html', { 
    174         'root_path': root_path
     173        'root_path': get_root_path()
    175174        'models': m_list 
    176175    }, context_instance=RequestContext(request)) 
     
    247246            'verbose'   : utils.parse_rst(_("number of %s") % verbose , 'model', _('model:') + opts.module_name), 
    248247        }) 
    249     root_path = re.sub(re.escape('doc/models/%s.%s/' % (app_label, model_name)) + '$', '', request.path) 
    250248    return render_to_response('admin_doc/model_detail.html', { 
    251         'root_path': root_path
     249        'root_path': get_root_path()
    252250        'name': '%s.%s' % (opts.app_label, opts.object_name), 
    253251        'summary': _("Fields on %s objects") % opts.object_name, 
     
    275273                'order': list(settings_mod.TEMPLATE_DIRS).index(dir), 
    276274            }) 
    277     root_path = re.sub(re.escape('doc/templates/%s/' % template) + '$', '', request.path) 
    278275    return render_to_response('admin_doc/template_detail.html', { 
    279         'root_path': root_path
     276        'root_path': get_root_path()
    280277        'name': template, 
    281278        'templates': templates,