- Author:
- fivethreeo
- Posted:
- August 25, 2007
- Language:
- Python
- Version:
- .96
- Score:
- 2 (after 2 ratings)
s = Scaffold(SomeForm)
print s.as_dl()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | class Scaffold(object):
def __init__(self, formclass):
self.formclass = formclass
def generate(self, row):
html = ''
fields = self.formclass.base_fields
for i in fields:
html += row % {'field': i}
return html
def as_dl(self):
return self.generate('''
<dt><label>{{ form.%(field)s.label }}</label></dt>
<dd>{{ form.%(field)s }}
{%% if form.%(field)s.errors %%}
<ul>
{%% for error in form.%(field)s.errors %%}
<li>{{ error }}</li>
{%% endfor %%}
</ul>
{%% endif %%}
</dd>
''')
def as_ul(self):
return self.generate('''
<li><label>{{ form.%(field)s.label }}</label></li>
<li>{{ form.%(field)s }}
{%% if form.%(field)s.errors %%}
<ul>
{%% for error in form.%(field)s.errors %%}
<li>{{ error }}</li>
{%% endfor %%}
</ul>
{%% endif %%}
</li>
''')
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 6 months ago
Comments
Please login first before commenting.