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>
    ''')