From a0139dc4e2aa7e1b5695a3499c6fcc80a6334dba Mon Sep 17 00:00:00 2001 From: adrian Date: Sun, 27 Nov 2005 17:20:43 +0000 Subject: [PATCH] Moved parts/admin/doc.py to contrib/admin/utils.py, where it belongs. Also caught docutils ImportError in a more controlled way git-svn-id: http://code.djangoproject.com/svn/django/trunk@1463 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- .../{parts/admin/doc.py => contrib/admin/utils.py} | 15 +++++--- django/contrib/admin/views/doc.py | 45 ++++++++++------------ django/parts/admin/__init__.py | 0 3 files changed, 30 insertions(+), 30 deletions(-) rename django/{parts/admin/doc.py => contrib/admin/utils.py} (92%) delete mode 100644 django/parts/admin/__init__.py diff --git a/django/parts/admin/doc.py b/django/contrib/admin/utils.py similarity index 92% rename from django/parts/admin/doc.py rename to django/contrib/admin/utils.py index f102278d..513067a2 100644 --- a/django/parts/admin/doc.py +++ b/django/contrib/admin/utils.py @@ -1,14 +1,17 @@ -""" -Misc. utility functions/classes for documentation generator -""" +"Misc. utility functions/classes for admin documentation generator." import re from email.Parser import HeaderParser from email.Errors import HeaderParseError -import docutils.core -import docutils.nodes -import docutils.parsers.rst.roles from urlparse import urljoin +try: + import docutils.core + import docutils.nodes + import docutils.parsers.rst.roles +except ImportError: + docutils_is_available = False +else: + docutils_is_available = True def trim_docstring(docstring): """ diff --git a/django/contrib/admin/views/doc.py b/django/contrib/admin/views/doc.py index eb464e1e..6e1d97a4 100644 --- a/django/contrib/admin/views/doc.py +++ b/django/contrib/admin/views/doc.py @@ -6,17 +6,14 @@ 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 -try: - from django.parts.admin import doc -except ImportError: - doc = None +from django.contrib.admin import utils import inspect, os, re # Exclude methods starting with these strings from documentation MODEL_METHODS_EXCLUDE = ('_', 'add_', 'delete', 'save', 'set_') def doc_index(request): - if not doc: + if not utils.docutils_is_available: return missing_docutils_page(request) return render_to_response('admin_doc/index', context_instance=DjangoContext(request)) doc_index = staff_member_required(doc_index) @@ -28,7 +25,7 @@ def bookmarklets(request): bookmarklets = staff_member_required(bookmarklets) def template_tag_index(request): - if not doc: + if not utils.docutils_is_available: return missing_docutils_page(request) load_all_installed_template_libraries() @@ -36,13 +33,13 @@ def template_tag_index(request): tags = [] 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__) + title, body, metadata = utils.parse_docstring(tag_func.__doc__) if title: - title = doc.parse_rst(title, 'tag', 'tag:' + tag_name) + title = utils.parse_rst(title, 'tag', 'tag:' + tag_name) if body: - body = doc.parse_rst(body, 'tag', 'tag:' + tag_name) + body = utils.parse_rst(body, 'tag', 'tag:' + tag_name) for key in metadata: - metadata[key] = doc.parse_rst(metadata[key], 'tag', 'tag:' + tag_name) + metadata[key] = utils.parse_rst(metadata[key], 'tag', 'tag:' + tag_name) if library in template.builtins: tag_library = None else: @@ -59,7 +56,7 @@ def template_tag_index(request): template_tag_index = staff_member_required(template_tag_index) def template_filter_index(request): - if not doc: + if not utils.docutils_is_available: return missing_docutils_page(request) load_all_installed_template_libraries() @@ -67,13 +64,13 @@ def template_filter_index(request): filters = [] 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__) + title, body, metadata = utils.parse_docstring(filter_func.__doc__) if title: - title = doc.parse_rst(title, 'filter', 'filter:' + filter_name) + title = utils.parse_rst(title, 'filter', 'filter:' + filter_name) if body: - body = doc.parse_rst(body, 'filter', 'filter:' + filter_name) + body = utils.parse_rst(body, 'filter', 'filter:' + filter_name) for key in metadata: - metadata[key] = doc.parse_rst(metadata[key], 'filter', 'filter:' + filter_name) + metadata[key] = utils.parse_rst(metadata[key], 'filter', 'filter:' + filter_name) if library in template.builtins: tag_library = None else: @@ -89,7 +86,7 @@ def template_filter_index(request): template_filter_index = staff_member_required(template_filter_index) def view_index(request): - if not doc: + if not utils.docutils_is_available: return missing_docutils_page(request) views = [] @@ -109,7 +106,7 @@ def view_index(request): view_index = staff_member_required(view_index) def view_detail(request, view): - if not doc: + if not utils.docutils_is_available: return missing_docutils_page(request) mod, func = urlresolvers.get_mod_func(view) @@ -117,13 +114,13 @@ def view_detail(request, view): view_func = getattr(__import__(mod, '', '', ['']), func) except (ImportError, AttributeError): raise Http404 - title, body, metadata = doc.parse_docstring(view_func.__doc__) + title, body, metadata = utils.parse_docstring(view_func.__doc__) if title: - title = doc.parse_rst(title, 'view', 'view:' + view) + title = utils.parse_rst(title, 'view', 'view:' + view) if body: - body = doc.parse_rst(body, 'view', 'view:' + view) + body = utils.parse_rst(body, 'view', 'view:' + view) for key in metadata: - metadata[key] = doc.parse_rst(metadata[key], 'model', 'view:' + view) + metadata[key] = utils.parse_rst(metadata[key], 'model', 'view:' + view) return render_to_response('admin_doc/view_detail', { 'name': view, 'summary': title, @@ -133,7 +130,7 @@ def view_detail(request, view): view_detail = staff_member_required(view_detail) def model_index(request): - if not doc: + if not utils.docutils_is_available: return missing_docutils_page(request) models = [] @@ -149,7 +146,7 @@ def model_index(request): model_index = staff_member_required(model_index) def model_detail(request, model): - if not doc: + if not utils.docutils_is_available: return missing_docutils_page(request) try: @@ -177,7 +174,7 @@ def model_detail(request, model): continue verbose = func.__doc__ if verbose: - verbose = doc.parse_rst(doc.trim_docstring(verbose), 'model', 'model:' + opts.module_name) + verbose = utils.parse_rst(utils.trim_docstring(verbose), 'model', 'model:' + opts.module_name) fields.append({ 'name': func_name, 'data_type': get_return_data_type(func_name), diff --git a/django/parts/admin/__init__.py b/django/parts/admin/__init__.py deleted file mode 100644 index e69de29b..00000000 -- 2.11.4.GIT