Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed a few broken model API examples.

git-svn-id: http://code.djangoproject.com/svn/djangoproject.com@4795 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a3259ac9cc2e1fdf731faff0c287bb443e4a55c2 1 parent 248da05
jacob authored
View
13 django_website/apps/docs/builder.py
@@ -32,13 +32,12 @@ def build_model_document(text):
visitor = compiler.walk(tree, ModelSourceVistor())
parts["api_usage"] = visitor.doctest
parts["models"] = visitor.models
- parts["newstyle"] = visitor.newstyle
# Parse out the model source.
- if visitor.newstyle:
+ try:
model_source = text[:text.index("__test__")]
- else:
- model_source = text[:text.index("API_TESTS")]
+ except ValueError:
+ model_source = text
parts["model_source"] = model_source.replace(tree.doc, "").replace('""""""\n', '\n').strip()
return parts
@@ -49,18 +48,14 @@ class ModelSourceVistor:
def __init__(self):
self.doctest = ""
self.models = []
- self.newstyle = True
def visitAssign(self, node):
assname, valtree = node.getChildren()
if assname.name == "__test__":
self.doctest = valtree.getChildren()[1].value
- elif assname.name == "API_TESTS":
- self.newstyle = False
- self.doctest = valtree.value
def visitClass(self, node):
- if node.bases and node.bases[0].attrname == "Model":
+ if node.bases and isinstance(node.bases[0], compiler.ast.Getattr) and node.bases[0].attrname == "Model":
self.models.append(node.name)
class DjangoHTMLWriter(html4css1.Writer):
View
10 django_website/templates/docs/model_detail.html
@@ -23,14 +23,12 @@ <h2 class="deck">
<h2 id="model-source-code">Model source code</h2>
<pre class="literal-block">{{ doc.model_source|escape }}</pre>
+{% if doc.api_usage %}
<h2 id="sample-usage">Sample API usage</h2>
-{% if doc.newstyle %}
<p>This sample code assumes the above model{{ doc.models|pluralize }} {% if doc.models|pluralize %}have{% else %}has{% endif %}
been saved in a file <tt class="docutils literal"><span class="pre">mysite/models.py</span></tt>.
<pre class="literal-block">&gt;&gt;&gt; from mysite.models import {% for model in doc.models %}{{ model }}{% if not forloop.last %}, {% endif %}{% endfor %}
-{{ doc.api_usage|escape }}</pre>
-{% else %}
-<pre class="literal-block">{{ doc.api_usage|escape }}</pre>
+{{ doc.api_usage|escape }}</pre>
{% endif %}
{% endblock %}
@@ -39,6 +37,8 @@ <h2 id="sample-usage">Sample API usage</h2>
<h2>Contents</h2>
<ul>
<li><a href="#model-source-code">Model source code</a></li>
- <li><a href="#sample-usage">Sample API usage</a></li>
+ {% if doc.api_usage %}
+ <li><a href="#sample-usage">Sample API usage</a></li>
+ {% endif %}
</ul>
{% endblock %}

0 comments on commit a3259ac

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