diff options
-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, + } |