class SubscribeForm(BaseContactsForm): """ Subscribe form. """ phone = wtf.TextField(_('Phone'), validators=[Required()]) skype = wtf.TextField(_('Skype'), validators=[Required()]) flow = wtf.SelectField(_('Flow'), choices=FLOW_CHOICES, validators=[Required()]) comments = wtf.TextField(_('Additional comments'), widget=wtf.TextArea()) template = 'mails/subscribe.txt' title = _('Flow subscription')
class ContactsForm(BaseContactsForm): """ Feedback form. """ subject = wtf.TextField(_('Subject')) message = wtf.TextField(_('Message'), validators=[Required()], widget=wtf.TextArea()) template = 'mails/contacts.txt' title = _('Feedback') def send(self): """ Use custom subject for email message if user filled in "Subject" field. """ self.title = self.data['subject'] or self.title super(ContactsForm, self).send()
class DictField(wtf.fields.Field): widget = wtf.TextArea() description = u'One per line, as {"key": "value"}' def __init__(self, *args, **kwargs): if not 'description' in kwargs: kwargs['description'] = self.description super(DictField, self).__init__(*args, **kwargs) def _value(self): if isinstance(self.data, dict): return '\r\n'.join( [json.dumps({key: value}) for key, value in self.data.items()]) return '' def process_formdata(self, valuelist): self.data = {} if valuelist: for row in valuelist[0].split('\n'): if row: rowdata = json.loads(row) if isinstance(rowdata, dict): self.data.update(rowdata)