Login

Scaffolding for newforms form

Author:
fivethreeo
Posted:
August 25, 2007
Language:
Python
Version:
.96
Tags:
newforms form scaffold
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

  1. Password Reset Form Newforms by glisha 7 years, 11 months ago
  2. isUnique validator for newforms by clamothe 6 years, 7 months ago
  3. newforms self-contained login form by miracle2k 7 years, 7 months ago
  4. Using Textarea by joshua 8 years ago
  5. create_object and update_object for newforms by danjak 7 years, 11 months ago

Comments

Please login first before commenting.