diff options
author | Madhusudan.C.S | 2011-01-16 17:02:02 +0530 |
---|---|---|
committer | Madhusudan.C.S | 2011-01-16 17:02:02 +0530 |
commit | 6faea1e0a91632fefe391c705d18c600e652c7f6 (patch) | |
tree | c50f94cb1f1eac7d41070fb511fae1480f09f4da | |
parent | 1bee9a1b41dfcde655ef318994ba969c02b35daa (diff) | |
download | pytask-6faea1e0a91632fefe391c705d18c600e652c7f6.tar.gz pytask-6faea1e0a91632fefe391c705d18c600e652c7f6.tar.bz2 pytask-6faea1e0a91632fefe391c705d18c600e652c7f6.zip |
Add templatetags for form handling.
-rwxr-xr-x | pytask/settings.py | 1 | ||||
-rw-r--r-- | pytask/templates/templatetags/_as_div_field.html | 11 | ||||
-rw-r--r-- | pytask/templates/templatetags/_as_div_form.html | 12 | ||||
-rw-r--r-- | pytask/templatetags/__init__.py | 2 | ||||
-rw-r--r-- | pytask/templatetags/form_helpers.py | 37 |
5 files changed, 63 insertions, 0 deletions
diff --git a/pytask/settings.py b/pytask/settings.py index 000d3af..20dc680 100755 --- a/pytask/settings.py +++ b/pytask/settings.py @@ -93,6 +93,7 @@ INSTALLED_APPS = ( 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.admin', + 'pytask', 'pytask.profile', 'pytask.taskapp', ) diff --git a/pytask/templates/templatetags/_as_div_field.html b/pytask/templates/templatetags/_as_div_field.html new file mode 100644 index 0000000..fa82fdb --- /dev/null +++ b/pytask/templates/templatetags/_as_div_field.html @@ -0,0 +1,11 @@ +{% load form_helpers %} + +{%if field.field.required %} +<div id="field-required"> +{% else %} +<div id="field"> +{% endif %} + {{ field.errors }} + {{ field.label_tag }} + {{ field }} +</div> diff --git a/pytask/templates/templatetags/_as_div_form.html b/pytask/templates/templatetags/_as_div_form.html new file mode 100644 index 0000000..2804133 --- /dev/null +++ b/pytask/templates/templatetags/_as_div_form.html @@ -0,0 +1,12 @@ +{% load form_helpers %} + +<form action="{{ action_url }}" method="post"> + {% csrf_token %} + <div id="form"> + {% for field in form %} + {% as_div_field field %} + {% endfor %} + <p class="submit"><button type="submit">{{ button_label }}</button></p> + </div> +</form> + diff --git a/pytask/templatetags/__init__.py b/pytask/templatetags/__init__.py new file mode 100644 index 0000000..8727752 --- /dev/null +++ b/pytask/templatetags/__init__.py @@ -0,0 +1,2 @@ +"""Package containing templatetags used all across the site. +"""
\ No newline at end of file diff --git a/pytask/templatetags/form_helpers.py b/pytask/templatetags/form_helpers.py new file mode 100644 index 0000000..6242df2 --- /dev/null +++ b/pytask/templatetags/form_helpers.py @@ -0,0 +1,37 @@ +"""Module containing the templatetags for constructing forms. +""" + + +__authors__ = [ + '"Madhusudan.C.S" <madhusudancs@fossee.in>', + ] + + +from django import template + + +register = template.Library() + + +@register.inclusion_tag('templatetags/_as_div_form.html') +def as_div_form(form, form_name, csrf_token, action_url, button_label): + """Returns a form to be constructed by the template specified. + """ + + return { + 'form': form, + 'form_name': form_name, + 'csrf_token': csrf_token, + 'action_url': action_url, + 'button_label': button_label, + } + + +@register.inclusion_tag('templatetags/_as_div_field.html') +def as_div_field(field): + """Returns the field for each div form field. + """ + + return { + 'field': field, + } |