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:
parent
2fb95f1de6
commit
f237936a87
|
@ -19,7 +19,6 @@
|
||||||
{% for filter in library.list|dictsort:"name" %}
|
{% for filter in library.list|dictsort:"name" %}
|
||||||
<h3 id="{{ filter.name }}">{{ filter.name }}</h3>
|
<h3 id="{{ filter.name }}">{{ filter.name }}</h3>
|
||||||
<p>{{ filter.title }}</p>
|
<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>
|
<p>{{ filter.body }}</p>
|
||||||
{% if not forloop.last %}<hr />{% endif %}
|
{% if not forloop.last %}<hr />{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -6,7 +6,6 @@ from django.models.core import sites
|
||||||
from django.core.extensions import DjangoContext, render_to_response
|
from django.core.extensions import DjangoContext, render_to_response
|
||||||
from django.core.exceptions import Http404, ViewDoesNotExist
|
from django.core.exceptions import Http404, ViewDoesNotExist
|
||||||
from django.core import template, urlresolvers
|
from django.core import template, urlresolvers
|
||||||
from django.core.template import defaulttags, defaultfilters, loader
|
|
||||||
try:
|
try:
|
||||||
from django.parts.admin import doc
|
from django.parts.admin import doc
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -29,40 +28,33 @@ def bookmarklets(request):
|
||||||
bookmarklets = staff_member_required(bookmarklets)
|
bookmarklets = staff_member_required(bookmarklets)
|
||||||
|
|
||||||
def template_tag_index(request):
|
def template_tag_index(request):
|
||||||
import sys
|
|
||||||
|
|
||||||
if not doc:
|
if not doc:
|
||||||
return missing_docutils_page(request)
|
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()
|
load_all_installed_template_libraries()
|
||||||
|
|
||||||
# Gather docs
|
|
||||||
tags = []
|
tags = []
|
||||||
for tagname in template.registered_tags:
|
for module_name, library in template.libraries.items():
|
||||||
title, body, metadata = doc.parse_docstring(template.registered_tags[tagname].__doc__)
|
for tag_name, tag_func in library.tags.items():
|
||||||
|
title, body, metadata = doc.parse_docstring(tag_func.__doc__)
|
||||||
if title:
|
if title:
|
||||||
title = doc.parse_rst(title, 'tag', 'tag:' + tagname)
|
title = doc.parse_rst(title, 'tag', 'tag:' + tag_name)
|
||||||
if body:
|
if body:
|
||||||
body = doc.parse_rst(body, 'tag', 'tag:' + tagname)
|
body = doc.parse_rst(body, 'tag', 'tag:' + tag_name)
|
||||||
for key in metadata:
|
for key in metadata:
|
||||||
metadata[key] = doc.parse_rst(metadata[key], 'tag', 'tag:' + tagname)
|
metadata[key] = doc.parse_rst(metadata[key], 'tag', 'tag:' + tag_name)
|
||||||
library = template.registered_tags[tagname].__module__.split('.')[-1]
|
if library in template.builtins:
|
||||||
if library == 'template_loader' or library == 'defaulttags':
|
tag_library = None
|
||||||
library = None
|
else:
|
||||||
|
tag_library = module_name.split('.')[-1]
|
||||||
tags.append({
|
tags.append({
|
||||||
'name' : tagname,
|
'name': tag_name,
|
||||||
'title': title,
|
'title': title,
|
||||||
'body': body,
|
'body': body,
|
||||||
'meta': metadata,
|
'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))
|
return render_to_response('admin_doc/template_tag_index', {'tags': tags}, context_instance=DjangoContext(request))
|
||||||
template_tag_index = staff_member_required(template_tag_index)
|
template_tag_index = staff_member_required(template_tag_index)
|
||||||
|
|
||||||
|
@ -70,32 +62,29 @@ def template_filter_index(request):
|
||||||
if not doc:
|
if not doc:
|
||||||
return missing_docutils_page(request)
|
return missing_docutils_page(request)
|
||||||
|
|
||||||
saved_tagset = template.registered_tags.copy(), template.registered_filters.copy()
|
|
||||||
load_all_installed_template_libraries()
|
load_all_installed_template_libraries()
|
||||||
|
|
||||||
filters = []
|
filters = []
|
||||||
for filtername in template.registered_filters:
|
for module_name, library in template.libraries.items():
|
||||||
title, body, metadata = doc.parse_docstring(template.registered_filters[filtername][0].__doc__)
|
for filter_name, filter_func in library.filters.items():
|
||||||
|
title, body, metadata = doc.parse_docstring(filter_func.__doc__)
|
||||||
if title:
|
if title:
|
||||||
title = doc.parse_rst(title, 'filter', 'filter:' + filtername)
|
title = doc.parse_rst(title, 'filter', 'filter:' + filter_name)
|
||||||
if body:
|
if body:
|
||||||
body = doc.parse_rst(body, 'filter', 'filter:' + filtername)
|
body = doc.parse_rst(body, 'filter', 'filter:' + filter_name)
|
||||||
for key in metadata:
|
for key in metadata:
|
||||||
metadata[key] = doc.parse_rst(metadata[key], 'filter', 'filter:' + filtername)
|
metadata[key] = doc.parse_rst(metadata[key], 'filter', 'filter:' + filter_name)
|
||||||
metadata['AcceptsArgument'] = template.registered_filters[filtername][1]
|
if library in template.builtins:
|
||||||
library = template.registered_filters[filtername][0].__module__.split('.')[-1]
|
tag_library = None
|
||||||
if library == 'template_loader' or library == 'defaultfilters':
|
else:
|
||||||
library = None
|
tag_library = module_name.split('.')[-1]
|
||||||
filters.append({
|
filters.append({
|
||||||
'name' : filtername,
|
'name': filter_name,
|
||||||
'title': title,
|
'title': title,
|
||||||
'body': body,
|
'body': body,
|
||||||
'meta': metadata,
|
'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))
|
return render_to_response('admin_doc/template_filter_index', {'filters': filters}, context_instance=DjangoContext(request))
|
||||||
template_filter_index = staff_member_required(template_filter_index)
|
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')
|
return render_to_response('admin_doc/missing_docutils')
|
||||||
|
|
||||||
def load_all_installed_template_libraries():
|
def load_all_installed_template_libraries():
|
||||||
# Clear out and reload default tags
|
# Load/register all template tag libraries from installed apps.
|
||||||
template.registered_tags.clear()
|
|
||||||
reload(defaulttags)
|
|
||||||
reload(loader) # loader defines the block/extends tags
|
|
||||||
|
|
||||||
# Load any template tag libraries from installed apps
|
|
||||||
for e in templatetags.__path__:
|
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()]
|
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:
|
try:
|
||||||
mod = defaulttags.LoadNode.load_taglib(lib)
|
lib = template.get_library("django.templatetags.%s" % library_name.split('.')[-1])
|
||||||
reload(mod)
|
except template.InvalidTemplateLibrary:
|
||||||
except ImportError:
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_return_data_type(func_name):
|
def get_return_data_type(func_name):
|
||||||
|
|
Loading…
Reference in New Issue