Benoît Bryon avatar Benoît Bryon committed 4bbd176

Added comparison example for simple use case in demo.

Comments (0)

Files changed (4)

demo/demoapp/templates/demoapp/base.html

   </head>
   <body>
     {% block content %}{% endblock content %}
-    <div id="menu">
+    <div id="menu" style="clear:both;">
       <h2>{% trans "Table of contents" %}</h2>
-        <h3><a href="{% url demoapp:simple_builtin %}">{% trans "Simplest use case with Django builtins" %}</a></h3>
-        <h3><a href="{% url demoapp:simple_formrenderingtools %}">{% trans "Simplest use case with Django-formrenderingtools" %}</a></h3>
+        <h3><a href="{% url demoapp:simple %}">{% trans "Simplest use case" %}</a></h3>
     </div>
   </body>
 </html>

demo/demoapp/templates/demoapp/comparison.html

+{% extends "demoapp/base.html" %}
+{% load i18n %}
+
+{% block content %}
+<h1>{{ title }}</h1>
+<p>{{ description }}</p>
+
+<div class="builtin" style="width:50%;margin:0;padding:0;float:left;">
+  <h2>{% trans "Django's builtins" %}</h2>
+  <div class="source">
+    <h3>Source</h3>
+    <pre>{{ builtin_source }}</pre>
+  </div>
+
+  <div class="output">
+    <h3>Output</h3>
+    {% include builtin_template %}
+  </div>
+</div>
+
+<div class="formrenderingtools" style="width:50%;margin:0;padding:0;float:right;">
+  <h2>{% trans "Django-formrenderingtools" %}</h2>
+  <div class="source">
+    <h3>Source</h3>
+    <pre>{{ formrenderingtools_source }}</pre>
+  </div>
+
+  <div class="output">
+    <h3>Output</h3>
+    {% include formrenderingtools_template %}
+  </div>
+</div>
+{% endblock content %}

demo/demoapp/urls.py

 )
 
 urlpatterns += patterns('demoapp.views',
+    url(r'^simple/$', 'simple', name='simple'),
     url(r'^simple/builtin/$', 'simple_builtin', name='simple_builtin'),
     url(r'^simple/formrenderingtools/$', 'simple_formrenderingtools', name='simple_formrenderingtools'),
 )

demo/demoapp/views.py

 import os.path
 
-from django.views.generic.simple import direct_to_template
+from django.core.urlresolvers import reverse
 from django.template.loader import find_template
 from django.utils.translation import ugettext_lazy as _
+from django.views.generic.simple import direct_to_template
 
 from demoapp.forms import FakeContactForm
 
     return direct_to_template(request, template_name, context_data)
 
 
+def comparison_page(request, title, description, form, template):
+    """Generic view to display a comparison page."""
+    context_data = {
+        'title': title,
+        'description': description,
+        'form': form,
+        'builtin_template': 'demoapp/%s_builtin.html' % template,
+        'formrenderingtools_template': 'demoapp/%s_formrenderingtools.html' % template,
+    }
+    context_data['builtin_source'] = get_template_string(context_data['builtin_template'])
+    context_data['formrenderingtools_source'] = get_template_string(context_data['formrenderingtools_template'])
+    template_name = 'demoapp/comparison.html'
+    return direct_to_template(request, template_name, context_data)
+
+
+def simple(request):
+    title = _("Simplest way to display a form")
+    description = _("The following example illustrates the minimal way to display a form.")
+    form = FakeContactForm()
+    template = 'simple'
+    return comparison_page(request, title, description, form, template)
+
+
 def simple_builtin(request):
     title = _("Simple form with Django's builtin {{ form }}")
     description = _("The following example illustrates the minimal way to display a form with Django's builtins.")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.