Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix #5405 - Added missing tests for admindocs #760

Closed
wants to merge 4 commits into from

4 participants

Gokmen Gorgen Wang GaoXiang Tim Graham Tomáš Ehrlich
Gokmen Gorgen

@elvard wrote a code for fixing #5405 and i added missing tests to apply the pull request: #484

https://code.djangoproject.com/ticket/5405

Wang GaoXiang

+1, I think this feature should be included, now my model docstrings looks bad on admin doc page.

Thx.

Tim Graham timgraham commented on the diff
django/contrib/admindocs/tests/__init__.py
((18 lines not shown))
+ Display an individual :model:`myapp.MyModel`.
+
+ **Context**
+
+ ``RequestContext``
+
+ ``mymodel``
+ An instance of :model:`myapp.MyModel`.
+
+ **Template:**
+
+ :template:`myapp/my_template.html` (DESCRIPTION)
+
+ """
+
+ @classmethod
Tim Graham Owner

use unittest.skipIf decorator on the class

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Tim Graham timgraham commented on the diff
django/contrib/admindocs/views.py
@@ -267,8 +275,10 @@ def model_detail(request, app_label, model_name):
return render_to_response('admin_doc/model_detail.html', {
'root_path': urlresolvers.reverse('admin:index'),
'name': '%s.%s' % (opts.app_label, opts.object_name),
- 'summary': _("Fields on %s objects") % opts.object_name,
- 'description': model.__doc__,
+ 'heading': _("Fields on %s objects") % opts.object_name,
Tim Graham Owner

for backwards compatibility, It would be good not to rename context variables

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Tim Graham
Owner

This no longer merges cleanly. Please open a new pull request if you can update it, thanks!

Tim Graham timgraham closed this
Žan Anderle zanderle referenced this pull request from a commit in zanderle/django
Žan Anderle zanderle Fixed #5405 -- Added support for reStructured text in admindocs for m…
…odel docstrings

Refered to PR #760 for help
@elvard wrote code to support it, but it needed to be modified, in order to merge
@gkmngrgn added tests that also needed to be modified
Squashed commits:
[39a9318] Made changes asked in review by MarkusH

- Renamed TestDocstrings to more apt name TestUtils
- Wrote tests for methods in utils
- Removed unused meta data for ModelDetailView
- Made small changes in docstrings in utils to comply to PEP 257
ecf7658
Žan Anderle zanderle referenced this pull request from a commit in zanderle/django
Žan Anderle zanderle Fixed #5405 -- Added support for reStructured text in admindocs for m…
…odel docstrings

Refered to PR #760 for help
@elvard wrote code to support it, but it needed to be modified, in order to merge
@gkmngrgn added tests that also needed to be modified
Squashed commits:
[39a9318] Made changes asked in review by MarkusH

- Renamed TestDocstrings to more apt name TestUtils
- Wrote tests for methods in utils
- Removed unused meta data for ModelDetailView
- Made small changes in docstrings in utils to comply to PEP 257
bebe55c
Žan Anderle zanderle referenced this pull request from a commit in zanderle/django
Žan Anderle zanderle Fixed #5405 -- Added support for reStructured text in admindocs for m…
…odel docstrings

Refered to PR #760 for help
@elvard wrote code to support it, but it needed to be modified, in order to merge
@gkmngrgn added tests that also needed to be modified
Squashed commits:
[39a9318] Made changes asked in review by MarkusH

- Renamed TestDocstrings to more apt name TestUtils
- Wrote tests for methods in utils
- Removed unused meta data for ModelDetailView
- Made small changes in docstrings in utils to comply to PEP 257
25c64c5
Žan Anderle zanderle referenced this pull request from a commit in zanderle/django
Žan Anderle zanderle Fixed #5405 -- Added support for reStructured text in admindocs for m…
…odel docstrings

Referred to PR #760 for help
@elvard wrote code to support it, but it needed to be modified, in order to merge
@gkmngrgn added tests that also needed to be modified

Squashed commits:
[39a9318] Made changes asked in review by MarkusH

- Renamed TestDocstrings to more apt name TestUtils
- Wrote tests for methods in utils
- Removed unused meta data for ModelDetailView
0ea3989
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 23, 2013
  1. Tomáš Ehrlich Gokmen Gorgen

    Fixes #5405

    tricoder42 authored gkmngrgn committed
  2. Tomáš Ehrlich Gokmen Gorgen

    Removed striptags filter from parsed docstring

    tricoder42 authored gkmngrgn committed
  3. Gokmen Gorgen

    Refs #5405 -- pep8ize.

    gkmngrgn authored
  4. Gokmen Gorgen
This page is out of date. Refresh to see the latest.
10 django/contrib/admindocs/templates/admin_doc/model_detail.html
View
@@ -22,12 +22,12 @@
{% block content %}
<div id="content-main">
-<h1>{{ summary }}</h1>
-
-{% if description %}
- <p>{% filter linebreaksbr %}{% trans description %}{% endfilter %}</p>
-{% endif %}
+<h1>{{ name }}</h1>
+<h2>{% trans "Description" %}</h2>
+{% if summary %}<strong>{% trans summary %}</strong>{% endif %}
+{% if description %}<p>{% trans description %}</p>{% endif %}
+<h2>{{ heading }}</h2>
<div class="module">
<table class="model">
<thead>
2  django/contrib/admindocs/templates/admin_doc/view_detail.html
View
@@ -15,7 +15,7 @@
<h1>{{ name }}</h1>
-<h2 class="subhead">{{ summary|striptags }}</h2>
+<h2 class="subhead">{{ summary }}</h2>
{{ body }}
81 django/contrib/admindocs/tests/__init__.py
View
@@ -1,6 +1,6 @@
from __future__ import absolute_import, unicode_literals
-from django.contrib.admindocs import views
+from django.contrib.admindocs import utils, views
from django.db.models import fields as builtin_fields
from django.utils import unittest
from django.utils.translation import ugettext as _
@@ -14,8 +14,7 @@ def setUp(self):
def test_field_name(self):
self.assertRaises(AttributeError,
- views.get_readable_field_data_type, "NotAField"
- )
+ views.get_readable_field_data_type, "NotAField")
def test_builtin_fields(self):
self.assertEqual(
@@ -29,8 +28,82 @@ def test_custom_fields(self):
'A custom field type'
)
self.assertEqual(
- views.get_readable_field_data_type(fields.DescriptionLackingField()),
+ views.get_readable_field_data_type(
+ fields.DescriptionLackingField()),
_('Field of type: %(field_type)s') % {
'field_type': 'DescriptionLackingField'
}
)
+
+
+class TestDocstrings(unittest.TestCase):
+ """
+ This __doc__ output is required for testing. I copied this example from
+ `admindocs` documentation. (TITLE)
+
+ Display an individual :model:`myapp.MyModel`.
+
+ **Context**
+
+ ``RequestContext``
+
+ ``mymodel``
+ An instance of :model:`myapp.MyModel`.
+
+ **Template:**
+
+ :template:`myapp/my_template.html` (DESCRIPTION)
+
+ """
+
+ @classmethod
Tim Graham Owner

use unittest.skipIf decorator on the class

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ def setUpClass(cls):
+ try:
+ import docutils
+ except ImportError:
+ raise unittest.SkipTest('docutils not installed')
+
+ super(TestDocstrings, cls).setUpClass()
+
+ def setUp(self):
+ self.title, self.description, self.metadata = utils.parse_docstring(
+ self.__doc__)
+ self.title_rendered = utils.parse_rst(
+ self.title, 'model', 'model:admindocs')
+ self.description_rendered = utils.parse_rst(
+ self.description, 'model', 'model:admindocs')
+ self.metadata_rendered = self.metadata
+ for key in self.metadata_rendered:
+ self.metadata_rendered[key] = utils.parse_rst(
+ self.metadata_rendered[key], 'model', 'model:admindocs')
+
+ def test_title_output(self):
+ self.assertIn('TITLE', self.title)
+ self.assertIn('TITLE', self.title_rendered)
+
+ title_rendered = (
+ '<p>This __doc__ output is required for testing. I copied this '
+ 'example from\n<a class="reference external" '
+ 'href="/admin/doc/models/admindocs/">admindocs</a> documentation. '
+ '(TITLE)</p>\n')
+ self.assertEqual(self.title_rendered, title_rendered)
+
+ def test_description_output(self):
+ self.assertIn('DESCRIPTION', self.description)
+ self.assertIn('DESCRIPTION', self.description_rendered)
+
+ description_rendered = (
+ '<p>Display an individual <a class="reference external" '
+ 'href="/admin/doc/models/myapp.mymodel/">myapp.MyModel</a>.</p>\n'
+ '<p><strong>Context</strong></p>\n<p><tt class="docutils literal">'
+ 'RequestContext</tt></p>\n<dl class="docutils">\n<dt><tt class="'
+ 'docutils literal">mymodel</tt></dt>\n<dd>An instance of <a class="'
+ 'reference external" href="/admin/doc/models/myapp.mymodel/">'
+ 'myapp.MyModel</a>.</dd>\n</dl>\n<p><strong>Template:</strong></p>'
+ '\n<p><a class="reference external" href="/admin/doc/templates/'
+ 'myapp/my_template.html/">myapp/my_template.html</a> (DESCRIPTION)'
+ '</p>\n')
+ self.assertEqual(self.description_rendered, description_rendered)
+
+ def test_metadata_output(self):
+ self.assertDictEqual(self.metadata, {})
14 django/contrib/admindocs/views.py
View
@@ -197,6 +197,14 @@ def model_detail(request, app_label, model_name):
opts = model._meta
+ title, description, metadata = utils.parse_docstring(model.__doc__)
+ if title:
+ title = utils.parse_rst(title, 'model', _('model:') + model_name)
+ if description:
+ description = utils.parse_rst(description, 'model', _('model:') + model_name)
+ for key in metadata:
+ metadata[key] = utils.parse_rst(metadata[key], 'model', _('model:') + model_name)
+
# Gather fields/field descriptions.
fields = []
for field in opts.fields:
@@ -267,8 +275,10 @@ def model_detail(request, app_label, model_name):
return render_to_response('admin_doc/model_detail.html', {
'root_path': urlresolvers.reverse('admin:index'),
'name': '%s.%s' % (opts.app_label, opts.object_name),
- 'summary': _("Fields on %s objects") % opts.object_name,
- 'description': model.__doc__,
+ 'heading': _("Fields on %s objects") % opts.object_name,
Tim Graham Owner

for backwards compatibility, It would be good not to rename context variables

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ 'summary': title,
+ 'description': description,
+ 'meta': metadata,
'fields': fields,
}, context_instance=RequestContext(request))
Something went wrong with that request. Please try again.