Benoît Bryon avatar Benoît Bryon committed 99ea60d Draft

Simplified project layout. Recommended to move to django-floppyforms.

Comments (0)

Files changed (180)

 syntax: glob
 
-# Local binaries (they are generated).
+# Local binaries.
 bin/
 
-# Local configuration (generated from templates)...
-etc/
+# Local configuration.
+#etc/
 
-# External libraries (generated).
+# Libraries.
 lib/
 
-# External source files (managed with their own VCS).
+# External source files.
 src/
 
-# Data files (backup).
+# Data files.
 var/
 
 # Python files.
 Changes
 =======
 
-0.2.4 (unreleased)
-------------------
+0.3 (unreleased)
+----------------
 
-- Nothing changed yet.
+- Stopped development of django-formrenderingtools.
+  Django-floppyforms is the recommended alternative.
+- Cleaned and simplified project layout.
 
 
 0.2.3 (2012-07-25)
 Update Django project settings
 ******************************
 
-Add ``djc.formrenderingtools`` to the ``INSTALLED_APPS`` list in your Django
+Add ``django_formrenderingtools`` to the ``INSTALLED_APPS`` list in your Django
 project settings:
 
 .. code-block:: python
 
   INSTALLED_APPS = (
       # ...
-      'djc.formrenderingtools',
+      'django_formrenderingtools',
       # ...
   )
 
-recursive-include djc *
+recursive-include django_formrenderingtools *
 recursive-include docs *
 global-exclude *.pyc
 include *.txt
-SHELL = /usr/bin/env bash
+# Makefile for development.
+SHELL = /bin/bash
+ROOT_DIR = $(shell pwd)
+BIN_DIR = $(ROOT_DIR)/bin
+DATA_DIR = $(ROOT_DIR)/var
+WGET = wget
+PYTHON = $(shell which python)
+BUILDOUT_CFG = $(ROOT_DIR)/etc/buildout.cfg
+BUILDOUT_DIR = $(ROOT_DIR)/lib/buildout
+BUILDOUT_VERSION = 1.7.0
+BUILDOUT_BOOTSTRAP_URL = https://raw.github.com/buildout/buildout/$(BUILDOUT_VERSION)/bootstrap/bootstrap.py
+BUILDOUT_BOOTSTRAP = $(BUILDOUT_DIR)/bootstrap.py
+BUILDOUT_BOOTSTRAP_ARGS = -c $(BUILDOUT_CFG) --version=$(BUILDOUT_VERSION) --distribute buildout:directory=$(ROOT_DIR)
+BUILDOUT = $(BIN_DIR)/buildout
+BUILDOUT_ARGS = -N -c $(BUILDOUT_CFG) buildout:directory=$(ROOT_DIR)
+NOSE = $(BIN_DIR)/nosetests
+DJANGO = $(BIN_DIR)/bin/django
 
-# Initialize some variables.
-PROJECT = 'django-formrenderingtools'
-ROOT_DIR = `cd $(@D) && pwd`
-BUILDOUT_BOOTSTRAP_URL = http://svn.zope.org/*checkout*/zc.buildout/tags/1.5.2/bootstrap/bootstrap.py?content-type=text%2Fplain
-BUILDOUT_CONFIGURATION = $(ROOT_DIR)/etc/buildout/buildout.cfg
-# Programs. See http://www.gnu.org/software/make/manual/make.html#Implicit-Variables
-WGET = wget
-VIRTUALENV = virtualenv
-PYTHON = $(ROOT_DIR)/lib/virtualenv/bin/python
-BUILDOUT = $(ROOT_DIR)/bin/buildout -c $(BUILDOUT_CONFIGURATION)
-DJANGO = $(ROOT_DIR)/bin/django
 
 configure:
-	# For now, we are using static configuration files (not real templates).
-	# These files are stored locally in templates/ folder.
-	# Generate local configuration.
-	mkdir -p $(ROOT_DIR)/etc
-	cp -R $(ROOT_DIR)/etc-templates/* $(ROOT_DIR)/etc/
+	# Configuration is stored in etc/ folder. Not generated yet.
 
-virtualenv:
-	if [ ! -f $(PYTHON) ]; then \
-	    if [[ "`$(VIRTUALENV) --version`" < "`echo '1.8'`" ]]; then \
-	        $(VIRTUALENV) --no-site-packages --distribute $(ROOT_DIR)/lib/virtualenv; \
-	    else \
-	        $(VIRTUALENV) $(ROOT_DIR)/lib/virtualenv; \
-	    fi \
-	fi
+
+develop: buildout
+
 
 buildout:
-	# Download zc.buildout's bootstrap script.
-	if [ ! -f $(ROOT_DIR)/lib/buildout/bootstrap.py ]; then \
-	    mkdir -p $(ROOT_DIR)/lib/buildout; \
-	    $(WGET) $(BUILDOUT_BOOTSTRAP_URL) -O $(ROOT_DIR)/lib/buildout/bootstrap.py; \
-	fi
-	# Generate local directories file for zc.buildout (makes it possible to
-	# set buildout:directory elsewhere than the main configuration file).
-	echo "# Generated by $(ROOT_DIR)/makefile on `date --utc`" > $(ROOT_DIR)/etc/buildout/directories-local.cfg
-	echo "[buildout]" >> $(ROOT_DIR)/etc/buildout/directories-local.cfg
-	echo "directory = $(ROOT_DIR)" >> $(ROOT_DIR)/etc/buildout/directories-local.cfg
-	# Bootstrap zc.buildout.
-	if [ ! -f $(ROOT_DIR)/bin/buildout ]; then \
-	    $(PYTHON) $(ROOT_DIR)/lib/buildout/bootstrap.py --distribute -c $(BUILDOUT_CONFIGURATION); \
-	fi
-	# Run zc.buildout.
-	$(BUILDOUT) -N
+	if [ ! -d $(BUILDOUT_DIR) ]; then mkdir -p $(BUILDOUT_DIR); fi
+	if [ ! -f $(BUILDOUT_BOOTSTRAP) ]; then wget -O $(BUILDOUT_BOOTSTRAP) $(BUILDOUT_BOOTSTRAP_URL); fi
+	if [ ! -x $(BUILDOUT) ]; then $(PYTHON) $(BUILDOUT_BOOTSTRAP) $(BUILDOUT_BOOTSTRAP_ARGS); fi
+	$(BUILDOUT) $(BUILDOUT_ARGS)
 
-update: buildout 
-
-develop: virtualenv update
 
 clean:
-	rm -rf bin/ lib/
+	find $(ROOT_DIR)/ -name "*.pyc" -delete
+	find $(ROOT_DIR)/ -name ".noseids" -delete
+
+
+distclean: clean
+	rm -rf $(ROOT_DIR)/*.egg-info
+	rm -rf $(ROOT_DIR)/demo/*.egg-info
+
+
+maintainer-clean: distclean
+	rm -rf $(ROOT_DIR)/bin/
+	rm -rf $(ROOT_DIR)/lib/
+
+
+test: test-demo test-documentation
+
+
+test-demo:
+	bin/demo test
+	mv $(ROOT_DIR)/.coverage $(ROOT_DIR)/var/test/demo.coverage
+
+
+test-documentation:
+	bin/nosetests -c $(ROOT_DIR)/etc/nose.cfg sphinxcontrib.testbuild.tests
+	mv $(ROOT_DIR)/.coverage $(ROOT_DIR)/var/test/documentation.coverage
+
 
 documentation:
-	make --directory=docs clean html
-	mkdir -p $(ROOT_DIR)/var/docs/html
-	bin/rst2 html README > $(ROOT_DIR)/var/docs/html/README.html
+	make --directory=docs clean html doctest
 
-test:
-	bin/django test --config=$(ROOT_DIR)/etc/nose.cfg
-	rm -f $(ROOT_DIR)/.coverage
+
+demo: develop
+	bin/demo syncdb --noinput
+	bin/demo runserver
+
 
 release:
-	# Freeze versions.
-	cp $(ROOT_DIR)/etc/buildout/versions-kgs.cfg $(ROOT_DIR)/etc-templates/buildout/
-	# Run zest.releaser.
-	bin/fullrelease
+	$(BIN_DIR)/fullrelease
 django-formrenderingtools
 #########################
 
+.. warning::
+
+   This project is inactive.
+   Django-floppyforms is the recommended alternative since it supports form
+   layouts.
+   See: https://pypi.python.org/pypi/django-floppyforms
+
 Customize layout of Django forms in templates, not in Python code.
 
 Rather than using {{ form.as_p }}, set up and reuse templates to render 
+############
+Demo project
+############
+
+The :file:`demo/` folder holds a demo project to illustrate
+django-formrenderingtools usage.
+
+
+***********************
+Browse demo code online
+***********************
+
+See `demo folder in project's repository`_.
+
+
+***************
+Deploy the demo
+***************
+
+System requirements:
+
+* `Python`_ version 2.6 or 2.7, available as ``python`` command.
+  
+  .. note::
+
+     You may use `Virtualenv`_ to make sure the active ``python`` is the right
+     one.
+
+* ``make`` and ``wget`` to use the provided :file:`Makefile`.
+
+Execute:
+
+.. code-block:: sh
+
+  hg clone http://bitbucket.org/benoitbryon/django-formrenderingtools
+  cd django-formrenderingtools/
+  make demo
+
+It installs and runs the demo server on localhost, port 8000. So have a look
+at http://localhost:8000/
+
+.. note::
+
+   If you cannot execute the Makefile, read it and adapt the few commands it
+   contains to your needs.
+
+Browse and use :file:`demo/demoproject/` as a sandbox.
+
+
+**********
+Experiment
+**********
+
+Use the demo project as a sandbox!
+
+
+.. note::
+
+   Demo is part of the development process and part of the documentation. It
+   has been created to both help users discover the application and developers
+   to test features with real-world use cases.
+
+
+.. target-notes::
+
+.. _`demo folder in project's repository`:
+   https://bitbucket.org/benoitbryon/django-formrenderingtools/src/tip/demo
+.. _`Python`: http://python.org
+.. _`Virtualenv`: http://virtualenv.org

demo/README.txt

-######################################
-Django-formrenderingtools demo project
-######################################
-
-This project is a demo for the Django-formrenderingtools package. Use it to
-quickly see, understand and experiment Django-formrenderingtools concepts.
-
-Install
-=======
-
-With Virtualenv and pip
------------------------
-
-* Check requirements. This demo requires the following software to be installed
-  on your system:
-
-  * Python >= 2.6 ("with" statement)
-  * Virtualenv
-  * Mercurial
-
-* Clone Django-formrenderingtools (or download and extract it):
-  ::
-
-    hg clone http://bitbucket.org/benoitbryon/django-formrenderingtools
-
-* Create a virtual environment and activate it:
-  ::
-  
-    virtualenv --no-site-packages --distribute django-formrenderingtools
-    source django-formrenderingtools/bin/activate
-
-* Run the development server:
-  ::
-
-    python django-formrenderingtools/demo/manage.py runserver
-
-* Look at the demo:
-
-  * Open http://localhost:8000/ with your browser
-  * Read the sourcecode at django-formrenderingtools/demo
-
-* Experiment. Use this demo project as a sandbox!
-
-Demo is part of the development process
-=======================================
-
-The demo project is part of the documentation. It has been created to help
-developers discover the application. It explains real-world usage.
-
-The demo project is also part of the tests.
Add a comment to this file

demo/__init__.py

Empty file removed.

Add a comment to this file

demo/demoapp/__init__.py

Empty file removed.

demo/demoapp/forms.py

-from django import forms
-from django.utils.translation import ugettext_lazy as _
-
-
-class FakeContactForm(forms.Form):
-    """A sample contact form which never validates."""
-    subject = forms.CharField(
-        label=_('Subject'),
-        max_length=100,
-    )
-    message = forms.CharField(
-        label=_('Message'),
-        widget=forms.Textarea()
-    )
-    sender_email = forms.EmailField(label=_('Sender email'))
-    sender_nickname = forms.CharField(
-        label=_('Sender nickname'),
-        required=False,
-    )
-    cc_myself = forms.BooleanField(
-        label=_('Copy to the sender'),
-        required=False,
-        help_text='Send a copy of the message to the sender.',
-    )
-    
-    def clean(self):
-        """This sample form never validates!"""
-        raise forms.ValidationError('Sorry, this sample form never validates!')

demo/demoapp/models.py

-from django.db import models
-
-# Create your models here.

demo/demoapp/templates/demoapp/base.html

-{% load i18n %}
-<html>
-  <head>
-    <title>{% trans "Django-formrenderingtools demo" %}</title>
-  </head>
-  <body>
-    {% block content %}{% endblock content %}
-    <div id="menu" style="clear:both;">
-      <h2>{% trans "Table of contents" %}</h2>
-        <h3>{% trans "Basic usage" %}</h3>
-          <h4><a href="{% url demoapp:simple %}">{% trans "Simplest use case" %}</a></h4>
-          <h4><a href="{% url demoapp:errors %}">{% trans "Displaying errors" %}</a></h4>
-        <h3>{% trans "Reproducing builtins output" %}</h3>
-          <h4><a href="{% url demoapp:as_table %}">{% trans "as_table" %}</a></h4>
-          <h4><a href="{% url demoapp:as_ul %}">{% trans "as_ul" %}</a></h4>
-          <h4><a href="{% url demoapp:as_p %}">{% trans "as_p" %}</a></h4>
-        <h3>{% trans "Fields order and form decomposition" %}</h3>
-          <h4><a href="{% url demoapp:fields_order %}">{% trans "Fields order" %}</a></h4>
-          <h4><a href="{% url demoapp:fieldsets %}">{% trans "Fieldsets" %}</a></h4>
-        <h3>{% trans "Template-based customization" %}</h3>
-          <h4><a href="{% url demoapp:two_custom_fields %}">{% trans "Customizing a few fields" %}</a></h4>
-          <h4><a href="{% url demoapp:altering_all_elements %}">{% trans "Customizing all elements in a form" %}</a></h4>
-    </div>
-  </body>
-</html>

demo/demoapp/templates/demoapp/comparison.html

-{% extends "demoapp/base.html" %}
-{% load i18n %}
-
-{% block content %}
-<h1>{{ title }}</h1>
-<p>{{ description|safe }}</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/templates/demoapp/demo.html

-{% extends "demoapp/base.html" %}
-{% load i18n %}
-
-{% block content %}
-<h1>{{ title }}</h1>
-<p>{{ description }}</p>
-
-<div class="source">
-  <h2>Source</h2>
-  <pre>{{ source }}</pre>
-</div>
-
-<div class="output">
-  <h2>Output</h2>
-  {% include template %}
-</div>
-{% endblock content %}

demo/demoapp/templates/demoapp/includes/altering_all_elements_builtin.html

-<form>
-  {{ form.non_field_errors }}
-
-  {% with form.subject as field and "id_subject" as field_id %}
-    <div class="fieldWrapper">
-      {{ field.errors }}
-      {{ field }}
-      <label for="{{ field_id }}">{{ field.label }}</label>
-      <span class="helptext">{{ field.help_text }}</span>
-    </div>
-  {% endwith %}
-
-  {% with form.message as field and "id_message" as field_id %}
-    <div class="fieldWrapper">
-      {{ field.errors }}
-      {{ field }}
-      <label for="{{ field_id }}">{{ field.label }}</label>
-      <span class="helptext">{{ field.help_text }}</span>
-    </div>
-  {% endwith %}
-
-  {% with form.sender_email as field and "id_sender_email" as field_id %}
-    <div class="fieldWrapper">
-      {{ field.errors }}
-      {{ field }}
-      <label for="{{ field_id }}">{{ field.label }}</label>
-      <span class="helptext">{{ field.help_text }}</span>
-    </div>
-  {% endwith %}
-
-  {% with form.sender_nickname as field and "id_sender_nickname" as field_id %}
-    <div class="fieldWrapper">
-      {{ field.errors }}
-      {{ field }}
-      <label for="{{ field_id }}">{{ field.label }}</label>
-      <span class="helptext">{{ field.help_text }}</span>
-    </div>
-  {% endwith %}
-
-  {% with form.cc_myself as field and "id_cc_myself" as field_id %}
-    <div class="fieldWrapper">
-      {{ field.errors }}
-      {{ field }}
-      <label for="{{ field_id }}">{{ field.label }}</label>
-      <span class="helptext">{{ field.help_text }}</span>
-    </div>
-  {% endwith %}
-  
-  <input type="submit">
-</form>

demo/demoapp/templates/demoapp/includes/altering_all_elements_formrenderingtools.html

-{% load form_layouts %}
-
-<form>
-  {% form layout="altering_all_elements" %}
-  <input type="submit">
-</form>

demo/demoapp/templates/demoapp/includes/as_p_builtin.html

-<form>
-  {{ form.as_p }}
-  <input type="submit">
-</form>

demo/demoapp/templates/demoapp/includes/as_p_formrenderingtools.html

-{% load form_layouts %}
-
-<form>
-  {% form layout="as_p" %}
-  <input type="submit">
-</form>

demo/demoapp/templates/demoapp/includes/as_table_builtin.html

-<form>
-  <table>
-    {{ form.as_table }}
-  </table>
-  <input type="submit">
-</form>

demo/demoapp/templates/demoapp/includes/as_table_formrenderingtools.html

-{% load form_layouts %}
-
-<form>
-  <table>
-    {% form layout="as_table" %}
-  </table>
-  <input type="submit">
-</form>

demo/demoapp/templates/demoapp/includes/as_ul_builtin.html

-<form>
-  <ul>
-    {{ form.as_ul }}
-  </ul>
-  <input type="submit">
-</form>

demo/demoapp/templates/demoapp/includes/as_ul_formrenderingtools.html

-{% load form_layouts %}
-
-<form>
-  <ul>
-    {% form layout="as_ul" %}
-  </ul>
-  <input type="submit">
-</form>

demo/demoapp/templates/demoapp/includes/errors_builtin.html

-<form>
-  <table>
-    {{ form }}
-  </table>
-  <input type="submit">
-</form>

demo/demoapp/templates/demoapp/includes/errors_formrenderingtools.html

-{% load form_layouts %}
-
-<form>
-  {% form %}
-  <input type="submit">
-</form>

demo/demoapp/templates/demoapp/includes/fields_order_builtin.html

-<form>
-  {{ form.non_field_errors }}
-
-  {% with form.name as field and "id_name" as field_id %}
-    <div class="fieldWrapper">
-      {{ field.errors }}
-      <label for="{{ field_id }}">{{ field.label }}</label>
-      {{ field }}
-      <span class="helptext">{{ field.help_text }}</span>
-    </div>
-  {% endwith %}
-
-  {% with form.domain as field and "id_domain" as field_id %}
-    <div class="fieldWrapper">
-      {{ field.errors }}
-      <label for="{{ field_id }}">{{ field.label }}</label>
-      {{ field }}
-      <span class="helptext">{{ field.help_text }}</span>
-    </div>
-  {% endwith %}
-
-  <input type="submit">
-</form>

demo/demoapp/templates/demoapp/includes/fields_order_formrenderingtools.html

-{% load form_layouts %}
-
-<form>
-  {% form_errors %}
-  {% field field=form.name %}
-  {% field field=form.domain %}
-  <input type="submit">
-</form>

demo/demoapp/templates/demoapp/includes/fieldsets_builtin.html

-<form>
-  {{ form.non_field_errors }}
-
-  <fieldset>
-    <legend>Message content</legend>
-    
-    {% with form.subject as field and "id_subject" as field_id %}
-      <div class="fieldWrapper">
-        {{ field.errors }}
-        <label for="{{ field_id }}">{{ field.label }}</label>
-        {{ field }}
-        <span class="helptext">{{ field.help_text }}</span>
-      </div>
-    {% endwith %}
-
-    {% with form.message as field and "id_message" as field_id %}
-      <div class="fieldWrapper">
-        {{ field.errors }}
-        <label for="{{ field_id }}">{{ field.label }}</label>
-        {{ field }}
-        <span class="helptext">{{ field.help_text }}</span>
-      </div>
-    {% endwith %}
-  </fieldset>
-
-  <fieldset>
-    <legend>Sender options</legend>
-    
-    {% with form.sender_email as field and "id_sender_email" as field_id %}
-      <div class="fieldWrapper">
-        {{ field.errors }}
-        <label for="{{ field_id }}">{{ field.label }}</label>
-        {{ field }}
-        <span class="helptext">{{ field.help_text }}</span>
-      </div>
-    {% endwith %}
-
-    {% with form.sender_nickname as field and "id_sender_nickname" as field_id %}
-      <div class="fieldWrapper">
-        {{ field.errors }}
-        <label for="{{ field_id }}">{{ field.label }}</label>
-        {{ field }}
-        <span class="helptext">{{ field.help_text }}</span>
-      </div>
-    {% endwith %}
-
-    {% with form.cc_myself as field and "id_cc_myself" as field_id %}
-      <div class="fieldWrapper">
-        {{ field.errors }}
-        <label for="{{ field_id }}">{{ field.label }}</label>
-        {{ field }}
-        <span class="helptext">{{ field.help_text }}</span>
-      </div>
-    {% endwith %}
-  </fieldset>
-  
-  <input type="submit">
-</form>

demo/demoapp/templates/demoapp/includes/fieldsets_formrenderingtools.html

-{% load form_layouts %}
-
-<form>
-  {% form_errors %}
-  
-  <fieldset>
-    <legend>Message content</legend>
-    {% field_list fields="subject,message" %}
-  </fieldset>
-
-  <fieldset>
-    <legend>Sender options</legend>
-    {% field_list fields="sender_email,sender_nickname,cc_myself" %}
-  </fieldset>
-  
-  <input type="submit">
-</form>

demo/demoapp/templates/demoapp/includes/simple_builtin.html

-<form>
-  <table>
-    {{ form }}
-  </table>
-  <input type="submit">
-</form>

demo/demoapp/templates/demoapp/includes/simple_formrenderingtools.html

-{% load form_layouts %}
-
-<form>
-  {% form %}
-  <input type="submit">
-</form>

demo/demoapp/templates/demoapp/includes/two_custom_fields_builtin.html

-<form>
-  {{ form.non_field_errors }}
-
-  {% with form.subject as field and "id_subject" as field_id %}
-    <div class="fieldWrapper">
-      {{ field.errors }}
-      <label for="{{ field_id }}">{{ field.label }}</label>
-      {{ field }}
-      <span class="helptext">{{ field.help_text }}</span>
-    </div>
-  {% endwith %}
-
-  {% with form.message as field and "id_message" as field_id %}
-    <div class="fieldWrapper">
-      {{ field.errors }}
-      <label for="{{ field_id }}">Your message</label>
-      {{ field }}
-      <span class="helptext">{{ field.help_text }}</span>
-    </div>
-  {% endwith %}
-
-  {% with form.sender_email as field and "id_sender_email" as field_id %}
-    <div class="fieldWrapper">
-      {{ field.errors }}
-      <label for="{{ field_id }}">{{ field.label }}</label>
-      {{ field }}
-      <span class="helptext">{{ field.help_text }}</span>
-    </div>
-  {% endwith %}
-
-  {% with form.sender_nickname as field and "id_sender_nickname" as field_id %}
-    <div class="fieldWrapper">
-      {{ field.errors }}
-      {{ field }}
-      <label for="{{ field_id }}">{{ field.label }}</label>
-      <span class="helptext">{{ field.help_text }}</span>
-    </div>
-  {% endwith %}
-
-  {% with form.cc_myself as field and "id_cc_myself" as field_id %}
-    <div class="fieldWrapper">
-      {{ field.errors }}
-      <label for="{{ field_id }}">{{ field.label }}</label>
-      {{ field }}
-      <span class="helptext">{{ field.help_text }}</span>
-    </div>
-  {% endwith %}
-  
-  <input type="submit">
-</form>

demo/demoapp/templates/demoapp/includes/two_custom_fields_formrenderingtools.html

-{% load form_layouts %}
-
-<form>
-  {% form layout="two_custom_fields" %}
-  <input type="submit">
-</form>

demo/demoapp/templates/demoapp/index.html

-{% extends "demoapp/base.html" %}
-{% load i18n %}
-
-{% block content %}
-<h1>{% trans "Django-formrenderingtools demo" %}</h1>
-<p>{% trans "This demonstration compares Django builtins and <a href='http://bitbucket.org/benoitbryon/django-formrenderingtools'>Django-formrenderingtools</a>. Follow the guide..." %}</p>
-{% endblock content %}

demo/demoapp/templates/form_layouts/altering_all_elements/field/default.html

-{% if field.is_hidden %}
-{{ field }}
-{% else %}
-{% load form_layouts %}
-<div class="formItem{% if field.errors %} hasErrors{% endif %}{% if field.field.required %} required{% endif %} {{ field.html_name }}">
-  {% field_errors %}
-  {{ field }}
-  {% label %}
-  {% help_text %}
-</div>
-{% endif %} 

demo/demoapp/templates/form_layouts/two_custom_fields/field/sender_nickname.html

-{% if field.is_hidden %}
-{{ field }}
-{% else %}
-{% load form_layouts %}
-<div class="formItem{% if field.errors %} hasErrors{% endif %}{% if field.field.required %} required{% endif %} {{ field.html_name }}">
-  {% field_errors %}
-  {{ field }}
-  {% label %}
-  {% help_text %}
-</div>
-{% endif %} 

demo/demoapp/templates/form_layouts/two_custom_fields/label/message.html

-<label for="{{ field_id }}" class="{% if field.field.required %} required{% endif %}">Your message</label> 

demo/demoapp/tests.py

-"""
-This file demonstrates writing tests using the unittest module. These will pass
-when you run "manage.py test".
-
-Replace this with more appropriate tests for your application.
-"""
-
-from django.test import TestCase
-
-
-class SimpleTest(TestCase):
-    def test_basic_addition(self):
-        """
-        Tests that 1 + 1 always equals 2.
-        """
-        self.assertEqual(1 + 1, 2)

demo/demoapp/urls.py

-from django.conf.urls.defaults import patterns, include, url
-
-urlpatterns = patterns('',
-    url(r'^$', 'django.views.generic.simple.direct_to_template',
-        {'template': 'demoapp/index.html'}, name='simple_builtin'),
-)
-
-urlpatterns += patterns('demo.demoapp.views',
-    url(r'^simple/$', 'simple', name='simple'),
-    url(r'^errors/$', 'errors', name='errors'),
-    url(r'^as-table/$', 'as_table', name='as_table'),
-    url(r'^as-ul/$', 'as_ul', name='as_ul'),
-    url(r'^as-p/$', 'as_p', name='as_p'),
-    url(r'^fields-order/$', 'fields_order', name='fields_order'),
-    url(r'^fieldsets/$', 'fieldsets', name='fieldsets'),
-    url(r'^two-custom-fields/$', 'two_custom_fields', name='two_custom_fields'),
-    url(r'^altering all elements/$', 'altering_all_elements', name='altering_all_elements'),
-)

demo/demoapp/views.py

-import os.path
-
-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 demo.demoapp.forms import FakeContactForm
-
-
-def get_template_string(template_name):
-    """Utility method that returns the source code of the given template name.
-
-    Template filenames are relative to the demoapp templates folder."""
-    base_path = os.path.dirname(__file__)
-    filename = os.path.join(base_path, 'templates', template_name)
-    with open(filename) as f:
-        return f.read()
-
-
-def demo_page(request, title, description, form, template):
-    """Old-style generic view to display a demo page."""
-    context_data = {
-        'title': title,
-        'description': description,
-        'form': form,
-        'template': template,
-    }
-    context_data['source'] = get_template_string(context_data['template'])
-    template_name = 'demoapp/demo.html'
-    return direct_to_template(request, template_name, context_data)
-
-
-def comparison_page(request, title, description, form, template):
-    """Old-style generic view to display a comparison page."""
-    context_data = {
-        'title': title,
-        'description': description,
-        'form': form,
-        'builtin_template': 'demoapp/includes/%s_builtin.html' % template,
-        'formrenderingtools_template': 'demoapp/includes/%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 errors(request):
-    title = _("Displaying form errors")
-    description = _("Let's see what happens with an invalid form. Notice that nothing changed in both template code.")
-    form = FakeContactForm({'subject': u''})
-    template = 'errors'
-    return comparison_page(request, title, description, form, template)
-
-
-def as_table(request):
-    title = _("Reproducing form.as_table")
-    description = _("Want to reproduce some form.as_table behaviour for backward compatibility? No problem! Notice that 'as_table' is the default for Django builtins, so {% form layout='as_table' %} reproduces both {{ form }} and {{ form.as_table }}.")
-    form = FakeContactForm({'subject': u''})
-    template = 'as_table'
-    return comparison_page(request, title, description, form, template)
-
-
-def as_ul(request):
-    title = _("Reproducing form.as_ul")
-    description = _("Want to reproduce some form.as_ul behaviour for backward compatibility? No problem!")
-    form = FakeContactForm({'subject': u''})
-    template = 'as_ul'
-    return comparison_page(request, title, description, form, template)
-
-
-def as_p(request):
-    title = _("Reproducing form.as_p")
-    description = _("Want to reproduce some form.as_p behaviour for backward compatibility? No problem!")
-    form = FakeContactForm({'subject': u''})
-    template = 'as_p'
-    return comparison_page(request, title, description, form, template)
-
-
-def fields_order(request):
-    title = _("Reordering fields")
-    description = _("""Often, you don't want to reoder fields in Python code because:</p>
-<ul>
-  <li>it resides in Django,</li>
-  <li>or in a third party module (don't want to fork it!),</li>
-  <li>or it is a ModelForm (don't want to alter the model).</li>
-</ul>
-<p>Reordering form fields in a Django template is boring: you have to reproduce all the template code for each field! And don't forget error messages, help texts...</p>
-<p>Notice that the field id in {{ field }} is computed with Python code. You cannot get it in templates to fill in the "for" property of the labels. This could become tricky if you are using form prefixes.</p>
-<p>This example uses a ModelForm on django.contrib.sites.models.Site. We *just* want to display 'display name' before 'domain name'.</p>
-<p>Maybe you are thinking that you had better include a template file instead of repeating code... That is exactly the purpose of Django-formrenderingtools ;)""")
-    from django.contrib.sites.models import Site
-    from django.forms import ModelForm
-    class SiteForm(ModelForm):
-        class Meta:
-            model = Site
-    form = SiteForm({'name': u'example'})
-    template = 'fields_order'
-    return comparison_page(request, title, description, form, template)
-
-
-def fieldsets(request):
-    title = _("Displaying fieldsets")
-    description = _("""Form decomposition with Django builtins: you have to rewrite all fields manually... Need a {% field_list %} template tag?</p>
-<p>In this example, we want to create two fieldsets: one to group message and subject, another one to group fields about sender.""")
-    form = FakeContactForm()
-    template = 'fieldsets'
-    return comparison_page(request, title, description, form, template)
-
-
-def two_custom_fields(request):
-    title = _("Customizing specific fields in a form")
-    description = _("""What if you want to customize only a few fields in a form?</p>
-<p>In this example, we want to do two things:</p>
-<ol>
-  <li>change label of "message" field by "Your message"</li>
-  <li>change order of field and label for "sender nickname" field</li>
-</ol>
-<p>What happened in the Django-formrenderingtools side?</p>
-<ul>
-  <li>we declared a new "form layout". It is the directory name of a set of templates.</li>
-  <li>we created two template files in demo/demoapp/templates/form_layouts/two_custom_fields/</li>
-  <li>one is called label/message.html</li>
-  <li>the other is called field/sender_nickname.html</li>
-  <li>the two templates were copied then adapted from djc/formrenderingtools/templates/form_layouts/default/...</li>
-</ul>""")
-    form = FakeContactForm()
-    template = 'two_custom_fields'
-    return comparison_page(request, title, description, form, template)
-
-
-def altering_all_elements(request):
-    title = _("Altering all elements at once for a specific form")
-    description = _("""What if you want to customize all elements in a form?</p>
-<p>In this example, we want to display field before label for each field.</p>
-<p>What happened in the Django-formrenderingtools side?</p>
-<ul>
-  <li>we declared a new form layout: "altering_all_elements"</li>
-  <li>we created a template file in demo/demoapp/templates/form_layouts/altering_all_elements/</li>
-  <li>it is called field/default.html</li>
-  <li>the templates was copied then adapted from djc/formrenderingtools/templates/form_layouts/default/field/default.html</li>
-</ul>""")
-    form = FakeContactForm()
-    template = 'altering_all_elements'
-    return comparison_page(request, title, description, form, template)
Add a comment to this file

demo/demoproject/__init__.py

Empty file added.

Add a comment to this file

demo/demoproject/demoapp/__init__.py

Empty file added.

demo/demoproject/demoapp/forms.py

+from django import forms
+from django.utils.translation import ugettext_lazy as _
+
+
+class FakeContactForm(forms.Form):
+    """A sample contact form which never validates."""
+    subject = forms.CharField(
+        label=_('Subject'),
+        max_length=100,
+    )
+    message = forms.CharField(
+        label=_('Message'),
+        widget=forms.Textarea()
+    )
+    sender_email = forms.EmailField(label=_('Sender email'))
+    sender_nickname = forms.CharField(
+        label=_('Sender nickname'),
+        required=False,
+    )
+    cc_myself = forms.BooleanField(
+        label=_('Copy to the sender'),
+        required=False,
+        help_text='Send a copy of the message to the sender.',
+    )
+    
+    def clean(self):
+        """This sample form never validates!"""
+        raise forms.ValidationError('Sorry, this sample form never validates!')

demo/demoproject/demoapp/models.py

+from django.db import models
+
+# Create your models here.

demo/demoproject/demoapp/templates/demoapp/base.html

+{% load i18n %}
+<html>
+  <head>
+    <title>{% trans "Django-formrenderingtools demo" %}</title>
+  </head>
+  <body>
+    {% block content %}{% endblock content %}
+    <div id="menu" style="clear:both;">
+      <h2>{% trans "Table of contents" %}</h2>
+        <h3>{% trans "Basic usage" %}</h3>
+          <h4><a href="{% url demoapp:simple %}">{% trans "Simplest use case" %}</a></h4>
+          <h4><a href="{% url demoapp:errors %}">{% trans "Displaying errors" %}</a></h4>
+        <h3>{% trans "Reproducing builtins output" %}</h3>
+          <h4><a href="{% url demoapp:as_table %}">{% trans "as_table" %}</a></h4>
+          <h4><a href="{% url demoapp:as_ul %}">{% trans "as_ul" %}</a></h4>
+          <h4><a href="{% url demoapp:as_p %}">{% trans "as_p" %}</a></h4>
+        <h3>{% trans "Fields order and form decomposition" %}</h3>
+          <h4><a href="{% url demoapp:fields_order %}">{% trans "Fields order" %}</a></h4>
+          <h4><a href="{% url demoapp:fieldsets %}">{% trans "Fieldsets" %}</a></h4>
+        <h3>{% trans "Template-based customization" %}</h3>
+          <h4><a href="{% url demoapp:two_custom_fields %}">{% trans "Customizing a few fields" %}</a></h4>
+          <h4><a href="{% url demoapp:altering_all_elements %}">{% trans "Customizing all elements in a form" %}</a></h4>
+    </div>
+  </body>
+</html>

demo/demoproject/demoapp/templates/demoapp/comparison.html

+{% extends "demoapp/base.html" %}
+{% load i18n %}
+
+{% block content %}
+<h1>{{ title }}</h1>
+<p>{{ description|safe }}</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/demoproject/demoapp/templates/demoapp/demo.html

+{% extends "demoapp/base.html" %}
+{% load i18n %}
+
+{% block content %}
+<h1>{{ title }}</h1>
+<p>{{ description }}</p>
+
+<div class="source">
+  <h2>Source</h2>
+  <pre>{{ source }}</pre>
+</div>
+
+<div class="output">
+  <h2>Output</h2>
+  {% include template %}
+</div>
+{% endblock content %}

demo/demoproject/demoapp/templates/demoapp/includes/altering_all_elements_builtin.html

+<form>
+  {{ form.non_field_errors }}
+
+  {% with form.subject as field and "id_subject" as field_id %}
+    <div class="fieldWrapper">
+      {{ field.errors }}
+      {{ field }}
+      <label for="{{ field_id }}">{{ field.label }}</label>
+      <span class="helptext">{{ field.help_text }}</span>
+    </div>
+  {% endwith %}
+
+  {% with form.message as field and "id_message" as field_id %}
+    <div class="fieldWrapper">
+      {{ field.errors }}
+      {{ field }}
+      <label for="{{ field_id }}">{{ field.label }}</label>
+      <span class="helptext">{{ field.help_text }}</span>
+    </div>
+  {% endwith %}
+
+  {% with form.sender_email as field and "id_sender_email" as field_id %}
+    <div class="fieldWrapper">
+      {{ field.errors }}
+      {{ field }}
+      <label for="{{ field_id }}">{{ field.label }}</label>
+      <span class="helptext">{{ field.help_text }}</span>
+    </div>
+  {% endwith %}
+
+  {% with form.sender_nickname as field and "id_sender_nickname" as field_id %}
+    <div class="fieldWrapper">
+      {{ field.errors }}
+      {{ field }}
+      <label for="{{ field_id }}">{{ field.label }}</label>
+      <span class="helptext">{{ field.help_text }}</span>
+    </div>
+  {% endwith %}
+
+  {% with form.cc_myself as field and "id_cc_myself" as field_id %}
+    <div class="fieldWrapper">
+      {{ field.errors }}
+      {{ field }}
+      <label for="{{ field_id }}">{{ field.label }}</label>
+      <span class="helptext">{{ field.help_text }}</span>
+    </div>
+  {% endwith %}
+  
+  <input type="submit">
+</form>

demo/demoproject/demoapp/templates/demoapp/includes/altering_all_elements_formrenderingtools.html

+{% load form_layouts %}
+
+<form>
+  {% form layout="altering_all_elements" %}
+  <input type="submit">
+</form>

demo/demoproject/demoapp/templates/demoapp/includes/as_p_builtin.html

+<form>
+  {{ form.as_p }}
+  <input type="submit">
+</form>

demo/demoproject/demoapp/templates/demoapp/includes/as_p_formrenderingtools.html

+{% load form_layouts %}
+
+<form>
+  {% form layout="as_p" %}
+  <input type="submit">
+</form>

demo/demoproject/demoapp/templates/demoapp/includes/as_table_builtin.html

+<form>
+  <table>
+    {{ form.as_table }}
+  </table>
+  <input type="submit">
+</form>

demo/demoproject/demoapp/templates/demoapp/includes/as_table_formrenderingtools.html

+{% load form_layouts %}
+
+<form>
+  <table>
+    {% form layout="as_table" %}
+  </table>
+  <input type="submit">
+</form>

demo/demoproject/demoapp/templates/demoapp/includes/as_ul_builtin.html

+<form>
+  <ul>
+    {{ form.as_ul }}
+  </ul>
+  <input type="submit">
+</form>

demo/demoproject/demoapp/templates/demoapp/includes/as_ul_formrenderingtools.html

+{% load form_layouts %}
+
+<form>
+  <ul>
+    {% form layout="as_ul" %}
+  </ul>
+  <input type="submit">
+</form>

demo/demoproject/demoapp/templates/demoapp/includes/errors_builtin.html

+<form>
+  <table>
+    {{ form }}
+  </table>
+  <input type="submit">
+</form>

demo/demoproject/demoapp/templates/demoapp/includes/errors_formrenderingtools.html

+{% load form_layouts %}
+
+<form>
+  {% form %}
+  <input type="submit">
+</form>

demo/demoproject/demoapp/templates/demoapp/includes/fields_order_builtin.html

+<form>
+  {{ form.non_field_errors }}
+
+  {% with form.name as field and "id_name" as field_id %}
+    <div class="fieldWrapper">
+      {{ field.errors }}
+      <label for="{{ field_id }}">{{ field.label }}</label>
+      {{ field }}
+      <span class="helptext">{{ field.help_text }}</span>
+    </div>
+  {% endwith %}
+
+  {% with form.domain as field and "id_domain" as field_id %}
+    <div class="fieldWrapper">
+      {{ field.errors }}
+      <label for="{{ field_id }}">{{ field.label }}</label>
+      {{ field }}
+      <span class="helptext">{{ field.help_text }}</span>
+    </div>
+  {% endwith %}
+
+  <input type="submit">
+</form>

demo/demoproject/demoapp/templates/demoapp/includes/fields_order_formrenderingtools.html

+{% load form_layouts %}
+
+<form>
+  {% form_errors %}
+  {% field field=form.name %}
+  {% field field=form.domain %}
+  <input type="submit">
+</form>

demo/demoproject/demoapp/templates/demoapp/includes/fieldsets_builtin.html

+<form>
+  {{ form.non_field_errors }}
+
+  <fieldset>
+    <legend>Message content</legend>
+    
+    {% with form.subject as field and "id_subject" as field_id %}
+      <div class="fieldWrapper">
+        {{ field.errors }}
+        <label for="{{ field_id }}">{{ field.label }}</label>
+        {{ field }}
+        <span class="helptext">{{ field.help_text }}</span>
+      </div>
+    {% endwith %}
+
+    {% with form.message as field and "id_message" as field_id %}
+      <div class="fieldWrapper">
+        {{ field.errors }}
+        <label for="{{ field_id }}">{{ field.label }}</label>
+        {{ field }}
+        <span class="helptext">{{ field.help_text }}</span>
+      </div>
+    {% endwith %}
+  </fieldset>
+
+  <fieldset>
+    <legend>Sender options</legend>
+    
+    {% with form.sender_email as field and "id_sender_email" as field_id %}
+      <div class="fieldWrapper">
+        {{ field.errors }}
+        <label for="{{ field_id }}">{{ field.label }}</label>
+        {{ field }}
+        <span class="helptext">{{ field.help_text }}</span>
+      </div>
+    {% endwith %}
+
+    {% with form.sender_nickname as field and "id_sender_nickname" as field_id %}
+      <div class="fieldWrapper">
+        {{ field.errors }}
+        <label for="{{ field_id }}">{{ field.label }}</label>
+        {{ field }}
+        <span class="helptext">{{ field.help_text }}</span>
+      </div>
+    {% endwith %}
+
+    {% with form.cc_myself as field and "id_cc_myself" as field_id %}
+      <div class="fieldWrapper">
+        {{ field.errors }}
+        <label for="{{ field_id }}">{{ field.label }}</label>
+        {{ field }}
+        <span class="helptext">{{ field.help_text }}</span>
+      </div>
+    {% endwith %}
+  </fieldset>
+  
+  <input type="submit">
+</form>

demo/demoproject/demoapp/templates/demoapp/includes/fieldsets_formrenderingtools.html

+{% load form_layouts %}
+
+<form>
+  {% form_errors %}
+  
+  <fieldset>
+    <legend>Message content</legend>
+    {% field_list fields="subject,message" %}
+  </fieldset>
+
+  <fieldset>
+    <legend>Sender options</legend>
+    {% field_list fields="sender_email,sender_nickname,cc_myself" %}
+  </fieldset>
+  
+  <input type="submit">
+</form>

demo/demoproject/demoapp/templates/demoapp/includes/simple_builtin.html

+<form>
+  <table>
+    {{ form }}
+  </table>
+  <input type="submit">
+</form>

demo/demoproject/demoapp/templates/demoapp/includes/simple_formrenderingtools.html

+{% load form_layouts %}
+
+<form>
+  {% form %}
+  <input type="submit">
+</form>

demo/demoproject/demoapp/templates/demoapp/includes/two_custom_fields_builtin.html

+<form>
+  {{ form.non_field_errors }}
+
+  {% with form.subject as field and "id_subject" as field_id %}
+    <div class="fieldWrapper">
+      {{ field.errors }}
+      <label for="{{ field_id }}">{{ field.label }}</label>
+      {{ field }}
+      <span class="helptext">{{ field.help_text }}</span>
+    </div>
+  {% endwith %}
+
+  {% with form.message as field and "id_message" as field_id %}
+    <div class="fieldWrapper">
+      {{ field.errors }}
+      <label for="{{ field_id }}">Your message</label>
+      {{ field }}
+      <span class="helptext">{{ field.help_text }}</span>
+    </div>
+  {% endwith %}
+
+  {% with form.sender_email as field and "id_sender_email" as field_id %}
+    <div class="fieldWrapper">
+      {{ field.errors }}
+      <label for="{{ field_id }}">{{ field.label }}</label>
+      {{ field }}
+      <span class="helptext">{{ field.help_text }}</span>
+    </div>
+  {% endwith %}
+
+  {% with form.sender_nickname as field and "id_sender_nickname" as field_id %}
+    <div class="fieldWrapper">
+      {{ field.errors }}
+      {{ field }}
+      <label for="{{ field_id }}">{{ field.label }}</label>
+      <span class="helptext">{{ field.help_text }}</span>
+    </div>
+  {% endwith %}
+
+  {% with form.cc_myself as field and "id_cc_myself" as field_id %}
+    <div class="fieldWrapper">
+      {{ field.errors }}
+      <label for="{{ field_id }}">{{ field.label }}</label>
+      {{ field }}
+      <span class="helptext">{{ field.help_text }}</span>
+    </div>
+  {% endwith %}
+  
+  <input type="submit">
+</form>

demo/demoproject/demoapp/templates/demoapp/includes/two_custom_fields_formrenderingtools.html

+{% load form_layouts %}
+
+<form>
+  {% form layout="two_custom_fields" %}
+  <input type="submit">
+</form>

demo/demoproject/demoapp/templates/demoapp/index.html

+{% extends "demoapp/base.html" %}
+{% load i18n %}
+
+{% block content %}
+<h1>{% trans "Django-formrenderingtools demo" %}</h1>
+<p>{% trans "This demonstration compares Django builtins and <a href='http://bitbucket.org/benoitbryon/django-formrenderingtools'>Django-formrenderingtools</a>. Follow the guide..." %}</p>
+{% endblock content %}

demo/demoproject/demoapp/templates/form_layouts/altering_all_elements/field/default.html

+{% if field.is_hidden %}
+{{ field }}
+{% else %}
+{% load form_layouts %}
+<div class="formItem{% if field.errors %} hasErrors{% endif %}{% if field.field.required %} required{% endif %} {{ field.html_name }}">
+  {% field_errors %}
+  {{ field }}
+  {% label %}
+  {% help_text %}
+</div>
+{% endif %} 

demo/demoproject/demoapp/templates/form_layouts/two_custom_fields/field/sender_nickname.html

+{% if field.is_hidden %}
+{{ field }}
+{% else %}
+{% load form_layouts %}
+<div class="formItem{% if field.errors %} hasErrors{% endif %}{% if field.field.required %} required{% endif %} {{ field.html_name }}">
+  {% field_errors %}
+  {{ field }}
+  {% label %}
+  {% help_text %}
+</div>
+{% endif %} 

demo/demoproject/demoapp/templates/form_layouts/two_custom_fields/label/message.html

+<label for="{{ field_id }}" class="{% if field.field.required %} required{% endif %}">Your message</label> 

demo/demoproject/demoapp/tests.py

+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+
+class SimpleTest(TestCase):
+    def test_basic_addition(self):
+        """
+        Tests that 1 + 1 always equals 2.
+        """
+        self.assertEqual(1 + 1, 2)

demo/demoproject/demoapp/urls.py

+from django.conf.urls.defaults import patterns, url
+
+urlpatterns = patterns('',
+    url(r'^$', 'django.views.generic.direct_to_template',
+        {'template': 'demoapp/index.html'}, name='simple_builtin'),
+)
+
+urlpatterns += patterns('demoproject.demoapp.views',
+    url(r'^simple/$', 'simple', name='simple'),
+    url(r'^errors/$', 'errors', name='errors'),
+    url(r'^as-table/$', 'as_table', name='as_table'),
+    url(r'^as-ul/$', 'as_ul', name='as_ul'),
+    url(r'^as-p/$', 'as_p', name='as_p'),
+    url(r'^fields-order/$', 'fields_order', name='fields_order'),
+    url(r'^fieldsets/$', 'fieldsets', name='fieldsets'),
+    url(r'^two-custom-fields/$', 'two_custom_fields', name='two_custom_fields'),
+    url(r'^altering all elements/$', 'altering_all_elements', name='altering_all_elements'),
+)

demo/demoproject/demoapp/views.py

+import os.path
+
+from django.http import HttpResponse
+from django.template.loader import render_to_string
+from django.utils.translation import ugettext_lazy as _
+
+from demoproject.demoapp.forms import FakeContactForm
+
+
+def direct_to_template(request, name, context):
+    return HttpResponse(render_to_string(name, context))
+
+
+def get_template_string(template_name):
+    """Utility method that returns the source code of the given template name.
+
+    Template filenames are relative to the demoapp templates folder."""
+    base_path = os.path.dirname(__file__)
+    filename = os.path.join(base_path, 'templates', template_name)
+    with open(filename) as f:
+        return f.read()
+
+
+def demo_page(request, title, description, form, template):
+    """Old-style generic view to display a demo page."""
+    context_data = {
+        'title': title,
+        'description': description,
+        'form': form,
+        'template': template,
+    }
+    context_data['source'] = get_template_string(context_data['template'])
+    template_name = 'demoapp/demo.html'
+    return direct_to_template(request, template_name, context_data)
+
+
+def comparison_page(request, title, description, form, template):
+    """Old-style generic view to display a comparison page."""
+    context_data = {
+        'title': title,
+        'description': description,
+        'form': form,
+        'builtin_template': 'demoapp/includes/%s_builtin.html' % template,
+        'formrenderingtools_template': 'demoapp/includes/%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 errors(request):
+    title = _("Displaying form errors")
+    description = _("Let's see what happens with an invalid form. Notice that nothing changed in both template code.")
+    form = FakeContactForm({'subject': u''})
+    template = 'errors'
+    return comparison_page(request, title, description, form, template)
+
+
+def as_table(request):
+    title = _("Reproducing form.as_table")
+    description = _("Want to reproduce some form.as_table behaviour for backward compatibility? No problem! Notice that 'as_table' is the default for Django builtins, so {% form layout='as_table' %} reproduces both {{ form }} and {{ form.as_table }}.")
+    form = FakeContactForm({'subject': u''})
+    template = 'as_table'
+    return comparison_page(request, title, description, form, template)
+
+
+def as_ul(request):
+    title = _("Reproducing form.as_ul")
+    description = _("Want to reproduce some form.as_ul behaviour for backward compatibility? No problem!")
+    form = FakeContactForm({'subject': u''})
+    template = 'as_ul'
+    return comparison_page(request, title, description, form, template)
+
+
+def as_p(request):
+    title = _("Reproducing form.as_p")
+    description = _("Want to reproduce some form.as_p behaviour for backward compatibility? No problem!")
+    form = FakeContactForm({'subject': u''})
+    template = 'as_p'
+    return comparison_page(request, title, description, form, template)
+
+
+def fields_order(request):
+    title = _("Reordering fields")
+    description = _("""Often, you don't want to reoder fields in Python code because:</p>
+<ul>
+  <li>it resides in Django,</li>
+  <li>or in a third party module (don't want to fork it!),</li>
+  <li>or it is a ModelForm (don't want to alter the model).</li>
+</ul>
+<p>Reordering form fields in a Django template is boring: you have to reproduce all the template code for each field! And don't forget error messages, help texts...</p>
+<p>Notice that the field id in {{ field }} is computed with Python code. You cannot get it in templates to fill in the "for" property of the labels. This could become tricky if you are using form prefixes.</p>
+<p>This example uses a ModelForm on django.contrib.sites.models.Site. We *just* want to display 'display name' before 'domain name'.</p>
+<p>Maybe you are thinking that you had better include a template file instead of repeating code... That is exactly the purpose of Django-formrenderingtools ;)""")
+    from django.contrib.sites.models import Site
+    from django.forms import ModelForm
+    class SiteForm(ModelForm):
+        class Meta:
+            model = Site
+    form = SiteForm({'name': u'example'})
+    template = 'fields_order'
+    return comparison_page(request, title, description, form, template)
+
+
+def fieldsets(request):
+    title = _("Displaying fieldsets")
+    description = _("""Form decomposition with Django builtins: you have to rewrite all fields manually... Need a {% field_list %} template tag?</p>
+<p>In this example, we want to create two fieldsets: one to group message and subject, another one to group fields about sender.""")
+    form = FakeContactForm()
+    template = 'fieldsets'
+    return comparison_page(request, title, description, form, template)
+
+
+def two_custom_fields(request):
+    title = _("Customizing specific fields in a form")
+    description = _("""What if you want to customize only a few fields in a form?</p>
+<p>In this example, we want to do two things:</p>
+<ol>
+  <li>change label of "message" field by "Your message"</li>
+  <li>change order of field and label for "sender nickname" field</li>
+</ol>
+<p>What happened in the Django-formrenderingtools side?</p>
+<ul>
+  <li>we declared a new "form layout". It is the directory name of a set of templates.</li>