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:
|
||||||
|
@ -24,44 +23,37 @@ doc_index = staff_member_required(doc_index)
|
||||||
|
|
||||||
def bookmarklets(request):
|
def bookmarklets(request):
|
||||||
return render_to_response('admin_doc/bookmarklets', {
|
return render_to_response('admin_doc/bookmarklets', {
|
||||||
'admin_url' : "%s://%s" % (os.environ.get('HTTPS') == 'on' and 'https' or 'http', request.META['HTTP_HOST']),
|
'admin_url': "%s://%s" % (os.environ.get('HTTPS') == 'on' and 'https' or 'http', request.META['HTTP_HOST']),
|
||||||
}, context_instance=DjangoContext(request))
|
}, context_instance=DjangoContext(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():
|
||||||
if title:
|
title, body, metadata = doc.parse_docstring(tag_func.__doc__)
|
||||||
title = doc.parse_rst(title, 'tag', 'tag:' + tagname)
|
if title:
|
||||||
if body:
|
title = doc.parse_rst(title, 'tag', 'tag:' + tag_name)
|
||||||
body = doc.parse_rst(body, 'tag', 'tag:' + tagname)
|
if body:
|
||||||
for key in metadata:
|
body = doc.parse_rst(body, 'tag', 'tag:' + tag_name)
|
||||||
metadata[key] = doc.parse_rst(metadata[key], 'tag', 'tag:' + tagname)
|
for key in metadata:
|
||||||
library = template.registered_tags[tagname].__module__.split('.')[-1]
|
metadata[key] = doc.parse_rst(metadata[key], 'tag', 'tag:' + tag_name)
|
||||||
if library == 'template_loader' or library == 'defaulttags':
|
if library in template.builtins:
|
||||||
library = None
|
tag_library = None
|
||||||
tags.append({
|
else:
|
||||||
'name' : tagname,
|
tag_library = module_name.split('.')[-1]
|
||||||
'title' : title,
|
tags.append({
|
||||||
'body' : body,
|
'name': tag_name,
|
||||||
'meta' : metadata,
|
'title': title,
|
||||||
'library' : library,
|
'body': body,
|
||||||
})
|
'meta': metadata,
|
||||||
|
'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():
|
||||||
if title:
|
title, body, metadata = doc.parse_docstring(filter_func.__doc__)
|
||||||
title = doc.parse_rst(title, 'filter', 'filter:' + filtername)
|
if title:
|
||||||
if body:
|
title = doc.parse_rst(title, 'filter', 'filter:' + filter_name)
|
||||||
body = doc.parse_rst(body, 'filter', 'filter:' + filtername)
|
if body:
|
||||||
for key in metadata:
|
body = doc.parse_rst(body, 'filter', 'filter:' + filter_name)
|
||||||
metadata[key] = doc.parse_rst(metadata[key], 'filter', 'filter:' + filtername)
|
for key in metadata:
|
||||||
metadata['AcceptsArgument'] = template.registered_filters[filtername][1]
|
metadata[key] = doc.parse_rst(metadata[key], 'filter', 'filter:' + filter_name)
|
||||||
library = template.registered_filters[filtername][0].__module__.split('.')[-1]
|
if library in template.builtins:
|
||||||
if library == 'template_loader' or library == 'defaultfilters':
|
tag_library = None
|
||||||
library = None
|
else:
|
||||||
filters.append({
|
tag_library = module_name.split('.')[-1]
|
||||||
'name' : filtername,
|
filters.append({
|
||||||
'title' : title,
|
'name': filter_name,
|
||||||
'body' : body,
|
'title': title,
|
||||||
'meta' : metadata,
|
'body': body,
|
||||||
'library' : library,
|
'meta': metadata,
|
||||||
})
|
'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)
|
||||||
|
|
||||||
|
@ -110,11 +99,11 @@ def view_index(request):
|
||||||
view_functions = extract_views_from_urlpatterns(urlconf.urlpatterns)
|
view_functions = extract_views_from_urlpatterns(urlconf.urlpatterns)
|
||||||
for (func, regex) in view_functions:
|
for (func, regex) in view_functions:
|
||||||
views.append({
|
views.append({
|
||||||
'name' : func.__name__,
|
'name': func.__name__,
|
||||||
'module' : func.__module__,
|
'module': func.__module__,
|
||||||
'site_id': settings_mod.SITE_ID,
|
'site_id': settings_mod.SITE_ID,
|
||||||
'site' : sites.get_object(pk=settings_mod.SITE_ID),
|
'site': sites.get_object(pk=settings_mod.SITE_ID),
|
||||||
'url' : simplify_regex(regex),
|
'url': simplify_regex(regex),
|
||||||
})
|
})
|
||||||
return render_to_response('admin_doc/view_index', {'views': views}, context_instance=DjangoContext(request))
|
return render_to_response('admin_doc/view_index', {'views': views}, context_instance=DjangoContext(request))
|
||||||
view_index = staff_member_required(view_index)
|
view_index = staff_member_required(view_index)
|
||||||
|
@ -152,9 +141,9 @@ def model_index(request):
|
||||||
for model in app._MODELS:
|
for model in app._MODELS:
|
||||||
opts = model._meta
|
opts = model._meta
|
||||||
models.append({
|
models.append({
|
||||||
'name' : '%s.%s' % (opts.app_label, opts.module_name),
|
'name': '%s.%s' % (opts.app_label, opts.module_name),
|
||||||
'module' : opts.app_label,
|
'module': opts.app_label,
|
||||||
'class' : opts.module_name,
|
'class': opts.module_name,
|
||||||
})
|
})
|
||||||
return render_to_response('admin_doc/model_index', {'models': models}, context_instance=DjangoContext(request))
|
return render_to_response('admin_doc/model_index', {'models': models}, context_instance=DjangoContext(request))
|
||||||
model_index = staff_member_required(model_index)
|
model_index = staff_member_required(model_index)
|
||||||
|
@ -173,10 +162,10 @@ def model_detail(request, model):
|
||||||
fields = []
|
fields = []
|
||||||
for field in opts.fields:
|
for field in opts.fields:
|
||||||
fields.append({
|
fields.append({
|
||||||
'name' : field.name,
|
'name': field.name,
|
||||||
'data_type': get_readable_field_data_type(field),
|
'data_type': get_readable_field_data_type(field),
|
||||||
'verbose' : field.verbose_name,
|
'verbose': field.verbose_name,
|
||||||
'help' : field.help_text,
|
'help': field.help_text,
|
||||||
})
|
})
|
||||||
for func_name, func in model.Klass.__dict__.items():
|
for func_name, func in model.Klass.__dict__.items():
|
||||||
if callable(func) and len(inspect.getargspec(func)[0]) == 0:
|
if callable(func) and len(inspect.getargspec(func)[0]) == 0:
|
||||||
|
@ -190,9 +179,9 @@ def model_detail(request, model):
|
||||||
if verbose:
|
if verbose:
|
||||||
verbose = doc.parse_rst(doc.trim_docstring(verbose), 'model', 'model:' + opts.module_name)
|
verbose = doc.parse_rst(doc.trim_docstring(verbose), 'model', 'model:' + opts.module_name)
|
||||||
fields.append({
|
fields.append({
|
||||||
'name' : func_name,
|
'name': func_name,
|
||||||
'data_type' : get_return_data_type(func_name),
|
'data_type': get_return_data_type(func_name),
|
||||||
'verbose' : verbose,
|
'verbose': verbose,
|
||||||
})
|
})
|
||||||
return render_to_response('admin_doc/model_detail', {
|
return render_to_response('admin_doc/model_detail', {
|
||||||
'name': '%s.%s' % (opts.app_label, opts.module_name),
|
'name': '%s.%s' % (opts.app_label, opts.module_name),
|
||||||
|
@ -208,12 +197,12 @@ def template_detail(request, template):
|
||||||
for dir in settings_mod.TEMPLATE_DIRS:
|
for dir in settings_mod.TEMPLATE_DIRS:
|
||||||
template_file = os.path.join(dir, "%s.html" % template)
|
template_file = os.path.join(dir, "%s.html" % template)
|
||||||
templates.append({
|
templates.append({
|
||||||
'file' : template_file,
|
'file': template_file,
|
||||||
'exists' : os.path.exists(template_file),
|
'exists': os.path.exists(template_file),
|
||||||
'contents' : lambda: os.path.exists(template_file) and open(template_file).read() or '',
|
'contents': lambda: os.path.exists(template_file) and open(template_file).read() or '',
|
||||||
'site_id' : settings_mod.SITE_ID,
|
'site_id': settings_mod.SITE_ID,
|
||||||
'site' : sites.get_object(pk=settings_mod.SITE_ID),
|
'site': sites.get_object(pk=settings_mod.SITE_ID),
|
||||||
'order' : list(settings_mod.TEMPLATE_DIRS).index(dir),
|
'order': list(settings_mod.TEMPLATE_DIRS).index(dir),
|
||||||
})
|
})
|
||||||
return render_to_response('admin_doc/template_detail', {
|
return render_to_response('admin_doc/template_detail', {
|
||||||
'name': template,
|
'name': template,
|
||||||
|
@ -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