magic-removal: Fixed #1253 -- Got admin doc for models working.
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2099 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
882c7c1885
commit
b4a454f956
|
@ -8,18 +8,19 @@
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<h1>Models Documentation</h1>
|
<h1>Model documentation</h1>
|
||||||
|
|
||||||
|
{% regroup models by app_label as grouped_models %}
|
||||||
|
|
||||||
<div id="content-main">
|
<div id="content-main">
|
||||||
{% regroup models|dictsort:"module" by module as grouped_models %}
|
|
||||||
{% for group in grouped_models %}
|
{% for group in grouped_models %}
|
||||||
<div class="module">
|
<div class="module">
|
||||||
<h2 id='{{ group.grouper }}'>{{ group.grouper }}</h2>
|
<h2 id="{{ group.grouper }}">{{ group.grouper|capfirst }}</h2>
|
||||||
|
|
||||||
<table class="xfull">
|
<table class="xfull">
|
||||||
{% for model in group.list %}
|
{% for model in group.list %}
|
||||||
<tr>
|
<tr>
|
||||||
<th><a href="{{ model.name }}/">{{ model.class }}</a></th>
|
<th><a href="{{ model.app_label }}.{{ model.object_name.lower }}/">{{ model.object_name }}</a></th>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
@ -32,11 +33,11 @@
|
||||||
{% block sidebar %}
|
{% block sidebar %}
|
||||||
<div id="content-related" class="sidebar">
|
<div id="content-related" class="sidebar">
|
||||||
<div class="module">
|
<div class="module">
|
||||||
<h2>Model Groups Quick List</h2>
|
<h2>Model groups</h2>
|
||||||
<ul>
|
<ul>
|
||||||
{% regroup models|dictsort:"module" by module as grouped_models %}
|
{% regroup models by app_label as grouped_models %}
|
||||||
{% for group in grouped_models %}
|
{% for group in grouped_models %}
|
||||||
<li><a href="#{{ group.grouper }}">{{ group.grouper }}</a></li>
|
<li><a href="#{{ group.grouper }}">{{ group.grouper|capfirst }}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -17,7 +17,7 @@ urlpatterns = patterns('',
|
||||||
('^doc/views/jump/$', 'django.contrib.admin.views.doc.jump_to_view'),
|
('^doc/views/jump/$', 'django.contrib.admin.views.doc.jump_to_view'),
|
||||||
('^doc/views/(?P<view>[^/]+)/$', 'django.contrib.admin.views.doc.view_detail'),
|
('^doc/views/(?P<view>[^/]+)/$', 'django.contrib.admin.views.doc.view_detail'),
|
||||||
('^doc/models/$', 'django.contrib.admin.views.doc.model_index'),
|
('^doc/models/$', 'django.contrib.admin.views.doc.model_index'),
|
||||||
('^doc/models/(?P<model>[^/]+)/$', 'django.contrib.admin.views.doc.model_detail'),
|
('^doc/models/(?P<app_label>[^\.]+)\.(?P<model_name>[^/]+)/$', 'django.contrib.admin.views.doc.model_detail'),
|
||||||
# ('^doc/templates/$', 'django.views.admin.doc.template_index'),
|
# ('^doc/templates/$', 'django.views.admin.doc.template_index'),
|
||||||
('^doc/templates/(?P<template>.*)/$', 'django.contrib.admin.views.doc.template_detail'),
|
('^doc/templates/(?P<template>.*)/$', 'django.contrib.admin.views.doc.template_detail'),
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ from django.conf import settings
|
||||||
from django.contrib.admin.views.decorators import staff_member_required
|
from django.contrib.admin.views.decorators import staff_member_required
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.shortcuts import render_to_response
|
from django.shortcuts import render_to_response
|
||||||
from django.core.exceptions import ViewDoesNotExist
|
from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from django.core import urlresolvers
|
from django.core import urlresolvers
|
||||||
from django.contrib.admin import utils
|
from django.contrib.admin import utils
|
||||||
|
@ -140,26 +140,30 @@ def model_index(request):
|
||||||
m_list = []
|
m_list = []
|
||||||
for app in models.get_installed_model_modules():
|
for app in models.get_installed_model_modules():
|
||||||
for model in app._MODELS:
|
for model in app._MODELS:
|
||||||
opts = model._meta
|
m_list.append(model._meta)
|
||||||
m_list.append({
|
|
||||||
'name': '%s.%s' % (opts.app_label, opts.module_name),
|
|
||||||
'module': opts.app_label,
|
|
||||||
'class': opts.module_name,
|
|
||||||
})
|
|
||||||
return render_to_response('admin_doc/model_index', {'models': m_list}, context_instance=RequestContext(request))
|
return render_to_response('admin_doc/model_index', {'models': m_list}, context_instance=RequestContext(request))
|
||||||
model_index = staff_member_required(model_index)
|
model_index = staff_member_required(model_index)
|
||||||
|
|
||||||
def model_detail(request, model):
|
def model_detail(request, app_label, model_name):
|
||||||
if not utils.docutils_is_available:
|
if not utils.docutils_is_available:
|
||||||
return missing_docutils_page(request)
|
return missing_docutils_page(request)
|
||||||
|
|
||||||
|
# Get the model class.
|
||||||
try:
|
try:
|
||||||
model = models.get_app(model)
|
app_mod = models.get_app(app_label)
|
||||||
except ImportError:
|
except ImproperlyConfigured:
|
||||||
raise Http404
|
raise Http404, "App %r not found" % app_label
|
||||||
opts = model.Klass._meta
|
model = None
|
||||||
|
for m in app_mod._MODELS:
|
||||||
|
if m._meta.object_name.lower() == model_name:
|
||||||
|
model = m
|
||||||
|
break
|
||||||
|
if model is None:
|
||||||
|
raise Http404, "Model %r not found in app %r" % (model_name, app_label)
|
||||||
|
|
||||||
# Gather fields/field descriptions
|
opts = model._meta
|
||||||
|
|
||||||
|
# Gather fields/field descriptions.
|
||||||
fields = []
|
fields = []
|
||||||
for field in opts.fields:
|
for field in opts.fields:
|
||||||
fields.append({
|
fields.append({
|
||||||
|
@ -168,8 +172,10 @@ def model_detail(request, model):
|
||||||
'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():
|
|
||||||
if callable(func) and len(inspect.getargspec(func)[0]) == 0:
|
# Gather model methods.
|
||||||
|
for func_name, func in model.__dict__.items():
|
||||||
|
if (inspect.isfunction(func) or inspect.ismethod(func)) and len(inspect.getargspec(func)[0]) == 0:
|
||||||
try:
|
try:
|
||||||
for exclude in MODEL_METHODS_EXCLUDE:
|
for exclude in MODEL_METHODS_EXCLUDE:
|
||||||
if func_name.startswith(exclude):
|
if func_name.startswith(exclude):
|
||||||
|
@ -184,6 +190,7 @@ def model_detail(request, model):
|
||||||
'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),
|
||||||
'summary': "Fields on %s objects" % opts.verbose_name,
|
'summary': "Fields on %s objects" % opts.verbose_name,
|
||||||
|
|
Loading…
Reference in New Issue