Parent: [a0374c] (diff)

Child: [c1be33] (diff)

Download this file

forms.py    31 lines (26 with data), 1.1 kB

 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
from pylons import c
from formencode import validators as fev
import ew
class ForgeForm(ew.SimpleForm):
template='jinja:forge_form.html'
params=['submit_text','enctype']
submit_text = 'Save'
enctype=None
def display_field_by_idx(self, idx, ignore_errors=False):
field = self.fields[idx]
ctx = c.widget.context_for(field.name)
display = field.display(**ctx)
if ctx['errors'] and field.show_errors and not ignore_errors:
display = "%s<div class='error'>%s</div>" % (display, ctx['errors'])
return display
class NeighborhoodAddProjectForm(ForgeForm):
submit_text = 'Create'
@property
def fields(self):
fields = [
ew.InputField(name='project_unixname', label='Project ID',
validator=fev.Regex(r'^[A-z][-A-z0-9]{2,}$', messages={'invalid':'Please use only letters, numbers, and dash characters.'})),
ew.HiddenField(name='project_name', label='Project Name'),
ew.HiddenField(name='project_description', label='Public Description')
]
return fields