Fixed #2157 -- Admin doc views now work if django.contrib.sites isn't installed

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3213 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-06-26 23:01:46 +00:00
parent 919df8b8c7
commit 6dc719312d
1 changed files with 14 additions and 2 deletions

View File

@ -14,6 +14,10 @@ import inspect, os, re
# Exclude methods starting with these strings from documentation # Exclude methods starting with these strings from documentation
MODEL_METHODS_EXCLUDE = ('_', 'add_', 'delete', 'save', 'set_') MODEL_METHODS_EXCLUDE = ('_', 'add_', 'delete', 'save', 'set_')
class GenericSite(object):
domain = 'example.com'
name = 'my site'
def doc_index(request): def doc_index(request):
if not utils.docutils_is_available: if not utils.docutils_is_available:
return missing_docutils_page(request) return missing_docutils_page(request)
@ -102,12 +106,16 @@ def view_index(request):
for settings_mod in settings_modules: for settings_mod in settings_modules:
urlconf = __import__(settings_mod.ROOT_URLCONF, '', '', ['']) urlconf = __import__(settings_mod.ROOT_URLCONF, '', '', [''])
view_functions = extract_views_from_urlpatterns(urlconf.urlpatterns) view_functions = extract_views_from_urlpatterns(urlconf.urlpatterns)
if Site._meta.installed:
site_obj = Site.objects.get(pk=settings_mod.SITE_ID)
else:
site_obj = GenericSite()
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': Site.objects.get(pk=settings_mod.SITE_ID), 'site': site_obj,
'url': simplify_regex(regex), 'url': simplify_regex(regex),
}) })
return render_to_response('admin_doc/view_index.html', {'views': views}, context_instance=RequestContext(request)) return render_to_response('admin_doc/view_index.html', {'views': views}, context_instance=RequestContext(request))
@ -228,6 +236,10 @@ def template_detail(request, template):
templates = [] templates = []
for site_settings_module in settings.ADMIN_FOR: for site_settings_module in settings.ADMIN_FOR:
settings_mod = __import__(site_settings_module, '', '', ['']) settings_mod = __import__(site_settings_module, '', '', [''])
if Site._meta.installed:
site_obj = Site.objects.get(pk=settings_mod.SITE_ID)
else:
site_obj = GenericSite()
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({
@ -235,7 +247,7 @@ def template_detail(request, template):
'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': Site.objects.get(pk=settings_mod.SITE_ID), 'site': site_obj,
'order': list(settings_mod.TEMPLATE_DIRS).index(dir), 'order': list(settings_mod.TEMPLATE_DIRS).index(dir),
}) })
return render_to_response('admin_doc/template_detail.html', { return render_to_response('admin_doc/template_detail.html', {