class PendingForm Form id fields HiddenField name fields TextField Nam

 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
40
41
42
43
44
45
46
class PendingForm(Form):
id = fields.HiddenField()
name = fields.TextField(u'Name')
url = fields.HiddenField()
valid = fields.BooleanField('Is Valid')
tags = fields.TextAreaField('Tags')
def __init__(self, obj=None, **kwargs):
super(PendingForm, self).__init__(obj=obj, **kwargs)
def validate_tags(self, field):
if self.valid.data and not self.tags.data:
raise validators.ValidationError('Please provide at least one tag')
def save(self):
if self.valid.data:
try:
tags = _parse_tags(self.tags.data)
avatar = models.Avatar.objects.query.filter(models.Avatar.id==self.id.data).one()
avatar.name = self.name.data
avatar.pending = False
map(avatar.tags.append, tags.values())
except Exception, ex:
# TODO: Fix me
print ex
def pending():
def get_formset(data):
initial = None
if not data:
initial = models.Avatar.objects.query.filter(models.Avatar.pending==True).limit(20).all()
return forms.PendingFormset(data=data, initial=initial)
formset = get_formset(env.request.form)
if env.request.form and formset.validate():
for f in formset.forms:
f.save()
formset = get_formset(None)
return render_to_response('admin/confirm_pending.html', {
'formset': formset,
})