Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 6dc719312df548dd5766b79b1e4c947c54285b93 1 parent 919df8b
Adrian Holovaty authored June 26, 2006

Showing 1 changed file with 14 additions and 2 deletions. Show diff stats Hide diff stats

  1. 16  django/contrib/admin/views/doc.py
16  django/contrib/admin/views/doc.py
@@ -14,6 +14,10 @@
14 14
 # Exclude methods starting with these strings from documentation
15 15
 MODEL_METHODS_EXCLUDE = ('_', 'add_', 'delete', 'save', 'set_')
16 16
 
  17
+class GenericSite(object):
  18
+    domain = 'example.com'
  19
+    name = 'my site'
  20
+
17 21
 def doc_index(request):
18 22
     if not utils.docutils_is_available:
19 23
         return missing_docutils_page(request)
@@ -102,12 +106,16 @@ def view_index(request):
102 106
     for settings_mod in settings_modules:
103 107
         urlconf = __import__(settings_mod.ROOT_URLCONF, '', '', [''])
104 108
         view_functions = extract_views_from_urlpatterns(urlconf.urlpatterns)
  109
+        if Site._meta.installed:
  110
+            site_obj = Site.objects.get(pk=settings_mod.SITE_ID)
  111
+        else:
  112
+            site_obj = GenericSite()
105 113
         for (func, regex) in view_functions:
106 114
             views.append({
107 115
                 'name': func.__name__,
108 116
                 'module': func.__module__,
109 117
                 'site_id': settings_mod.SITE_ID,
110  
-                'site': Site.objects.get(pk=settings_mod.SITE_ID),
  118
+                'site': site_obj,
111 119
                 'url': simplify_regex(regex),
112 120
             })
113 121
     return render_to_response('admin_doc/view_index.html', {'views': views}, context_instance=RequestContext(request))
@@ -228,6 +236,10 @@ def template_detail(request, template):
228 236
     templates = []
229 237
     for site_settings_module in settings.ADMIN_FOR:
230 238
         settings_mod = __import__(site_settings_module, '', '', [''])
  239
+        if Site._meta.installed:
  240
+            site_obj = Site.objects.get(pk=settings_mod.SITE_ID)
  241
+        else:
  242
+            site_obj = GenericSite()
231 243
         for dir in settings_mod.TEMPLATE_DIRS:
232 244
             template_file = os.path.join(dir, "%s.html" % template)
233 245
             templates.append({
@@ -235,7 +247,7 @@ def template_detail(request, template):
235 247
                 'exists': os.path.exists(template_file),
236 248
                 'contents': lambda: os.path.exists(template_file) and open(template_file).read() or '',
237 249
                 'site_id': settings_mod.SITE_ID,
238  
-                'site': Site.objects.get(pk=settings_mod.SITE_ID),
  250
+                'site': site_obj,
239 251
                 'order': list(settings_mod.TEMPLATE_DIRS).index(dir),
240 252
             })
241 253
     return render_to_response('admin_doc/template_detail.html', {

0 notes on commit 6dc7193

Please sign in to comment.
Something went wrong with that request. Please try again.