From 331d6066ef64d55d0f314cf7523f3b9ed4a257ed Mon Sep 17 00:00:00 2001 From: tzangms Date: Sun, 21 Aug 2011 09:07:02 -0700 Subject: [PATCH] initial commit --- .gitignore | 1 + README | 5 +++++ __init__.py | 0 models.py | 3 +++ templates/bootstrap_form/form.html | 27 +++++++++++++++++++++++++++ templatetags/__init__.py | 0 templatetags/bootstrap.py | 15 +++++++++++++++ tests.py | 16 ++++++++++++++++ views.py | 1 + 9 files changed, 68 insertions(+) create mode 100644 .gitignore create mode 100644 README create mode 100644 __init__.py create mode 100644 models.py create mode 100644 templates/bootstrap_form/form.html create mode 100644 templatetags/__init__.py create mode 100644 templatetags/bootstrap.py create mode 100644 tests.py create mode 100644 views.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d20b64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc diff --git a/README b/README new file mode 100644 index 0000000..07b4b8c --- /dev/null +++ b/README @@ -0,0 +1,5 @@ +Generate twitter-bootstrap form output for django form + +{% load bootstrap %} + +{{ form|bootstrape }} diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/models.py b/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/templates/bootstrap_form/form.html b/templates/bootstrap_form/form.html new file mode 100644 index 0000000..173b5a5 --- /dev/null +++ b/templates/bootstrap_form/form.html @@ -0,0 +1,27 @@ +{% load bootstrap %} + +{% for field in form %} +
+ {% if field|is_checkbox %} + + {% else %} + {{ field.label_tag }} +
+ {{ field }} + {% if field.errors %} + {% for error in field.errors %} + {{ error }} + {% endfor %} + {% endif %} +
+ {% endif %} +
+{% endfor %} diff --git a/templatetags/__init__.py b/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/templatetags/bootstrap.py b/templatetags/bootstrap.py new file mode 100644 index 0000000..f49af35 --- /dev/null +++ b/templatetags/bootstrap.py @@ -0,0 +1,15 @@ +from django.template import Context +from django.template.loader import get_template +from django import template + +register = template.Library() + +@register.filter +def bootstrap(form): + template = get_template("bootstrap_form/form.html") + context = Context({'form': form}) + return template.render(context) + +@register.filter +def is_checkbox(field): + return field.field.widget.__class__.__name__.lower() == "checkboxinput" diff --git a/tests.py b/tests.py new file mode 100644 index 0000000..501deb7 --- /dev/null +++ b/tests.py @@ -0,0 +1,16 @@ +""" +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) diff --git a/views.py b/views.py new file mode 100644 index 0000000..60f00ef --- /dev/null +++ b/views.py @@ -0,0 +1 @@ +# Create your views here.