Scaffolding for newforms form

 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

  1. newforms field callback helper by SmileyChris 4 years, 9 months ago
  2. Automatic stripping textual form fields by nail.xx 3 years, 6 months ago
  3. SectionedForm by marinho 3 years, 8 months ago
  4. Form field sets by gonz 2 years ago
  5. newforms and ModelForm by danfairs 4 years, 1 month ago

Comments

(Forgotten your password?)