Fixed #928 -- Fixed admin documentation breakage after [1443]. Thanks for reporting, nesh

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1462 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2005-11-27 17:14:11 +00:00
parent 2fb95f1de6
commit f237936a87
2 changed files with 64 additions and 82 deletions

View File

@ -19,7 +19,6 @@
{% for filter in library.list|dictsort:"name" %}
<h3 id="{{ filter.name }}">{{ filter.name }}</h3>
<p>{{ filter.title }}</p>
<p><strong>Usage:</strong> <code>{% templatetag openvariable %} variable|{{ filter.name }}{% if filter.meta.AcceptsArgument %}:"arg"{% endif %} {% templatetag closevariable %}</code></p>
<p>{{ filter.body }}</p>
{% if not forloop.last %}<hr />{% endif %}
{% endfor %}

View File

@ -6,7 +6,6 @@ from django.models.core import sites
from django.core.extensions import DjangoContext, render_to_response
from django.core.exceptions import Http404, ViewDoesNotExist
from django.core import template, urlresolvers
from django.core.template import defaulttags, defaultfilters, loader
try:
from django.parts.admin import doc
except ImportError:
@ -29,40 +28,33 @@ def bookmarklets(request):
bookmarklets = staff_member_required(bookmarklets)
def template_tag_index(request):
import sys
if not doc:
return missing_docutils_page(request)
# We have to jump through some hoops with registered_tags to make sure
# they don't get messed up by loading outside tagsets
saved_tagset = template.registered_tags.copy(), template.registered_filters.copy()
load_all_installed_template_libraries()
# Gather docs
tags = []
for tagname in template.registered_tags:
title, body, metadata = doc.parse_docstring(template.registered_tags[tagname].__doc__)
for module_name, library in template.libraries.items():
for tag_name, tag_func in library.tags.items():
title, body, metadata = doc.parse_docstring(tag_func.__doc__)
if title:
title = doc.parse_rst(title, 'tag', 'tag:' + tagname)
title = doc.parse_rst(title, 'tag', 'tag:' + tag_name)
if body:
body = doc.parse_rst(body, 'tag', 'tag:' + tagname)
body = doc.parse_rst(body, 'tag', 'tag:' + tag_name)
for key in metadata:
metadata[key] = doc.parse_rst(metadata[key], 'tag', 'tag:' + tagname)
library = template.registered_tags[tagname].__module__.split('.')[-1]
if library == 'template_loader' or library == 'defaulttags':
library = None
metadata[key] = doc.parse_rst(metadata[key], 'tag', 'tag:' + tag_name)
if library in template.builtins:
tag_library = None
else:
tag_library = module_name.split('.')[-1]
tags.append({
'name' : tagname,
'name': tag_name,
'title': title,
'body': body,
'meta': metadata,
'library' : library,
'library': tag_library,
})
# Fix registered_tags
template.registered_tags, template.registered_filters = saved_tagset
return render_to_response('admin_doc/template_tag_index', {'tags': tags}, context_instance=DjangoContext(request))
template_tag_index = staff_member_required(template_tag_index)
@ -70,32 +62,29 @@ def template_filter_index(request):
if not doc:
return missing_docutils_page(request)
saved_tagset = template.registered_tags.copy(), template.registered_filters.copy()
load_all_installed_template_libraries()
filters = []
for filtername in template.registered_filters:
title, body, metadata = doc.parse_docstring(template.registered_filters[filtername][0].__doc__)
for module_name, library in template.libraries.items():
for filter_name, filter_func in library.filters.items():
title, body, metadata = doc.parse_docstring(filter_func.__doc__)
if title:
title = doc.parse_rst(title, 'filter', 'filter:' + filtername)
title = doc.parse_rst(title, 'filter', 'filter:' + filter_name)
if body:
body = doc.parse_rst(body, 'filter', 'filter:' + filtername)
body = doc.parse_rst(body, 'filter', 'filter:' + filter_name)
for key in metadata:
metadata[key] = doc.parse_rst(metadata[key], 'filter', 'filter:' + filtername)
metadata['AcceptsArgument'] = template.registered_filters[filtername][1]
library = template.registered_filters[filtername][0].__module__.split('.')[-1]
if library == 'template_loader' or library == 'defaultfilters':
library = None
metadata[key] = doc.parse_rst(metadata[key], 'filter', 'filter:' + filter_name)
if library in template.builtins:
tag_library = None
else:
tag_library = module_name.split('.')[-1]
filters.append({
'name' : filtername,
'name': filter_name,
'title': title,
'body': body,
'meta': metadata,
'library' : library,
'library': tag_library,
})
template.registered_tags, template.registered_filters = saved_tagset
return render_to_response('admin_doc/template_filter_index', {'filters': filters}, context_instance=DjangoContext(request))
template_filter_index = staff_member_required(template_filter_index)
@ -230,19 +219,13 @@ def missing_docutils_page(request):
return render_to_response('admin_doc/missing_docutils')
def load_all_installed_template_libraries():
# Clear out and reload default tags
template.registered_tags.clear()
reload(defaulttags)
reload(loader) # loader defines the block/extends tags
# Load any template tag libraries from installed apps
# Load/register all template tag libraries from installed apps.
for e in templatetags.__path__:
libraries = [os.path.splitext(p)[0] for p in os.listdir(e) if p.endswith('.py') and p[0].isalpha()]
for lib in libraries:
for library_name in libraries:
try:
mod = defaulttags.LoadNode.load_taglib(lib)
reload(mod)
except ImportError:
lib = template.get_library("django.templatetags.%s" % library_name.split('.')[-1])
except template.InvalidTemplateLibrary:
pass
def get_return_data_type(func_name):