class ItemForm(ModelForm): ROLES = DEFAULT_ROLES fields = [ Field('name', conv=convs.Char(convs.length(3, 250), required=False), label=u"Имя"), Field('email', conv=convs.Email(convs.length(0, 200), required=False), label=u"E-mail"), Field('login', conv=convs.Char( convs.DBUnique( message=u'Объект с таким значением уже существует'), convs.length(3, 250), required=True, ), label=u"Логин"), shortcuts.PasswordSet( 'password', filters=(clean_password, ), widget=widgets.FieldSetWidget(template='widgets/fieldset-line'), label=u'пароль', confirm_label=u'подтверждение'), Field('active', conv=convs.Bool(), widget=widgets.CheckBox(), initial=True, label=u'Активен', hint=u'Пользователи с этим флагом могут входить в ' u'административный интерфейс'), Field('roles', label=u'Роли', conv=convs.ListOf(RoleConv()), widget=widgets.CheckBoxSelect()) ] def update__password(self, obj, name, value): if value is not None: obj.set_password(value) def update__roles(self, obj, name, value): if obj.roles is not None and 'wheel' in obj.roles and \ 'wheel' not in value: value.append('wheel') if (not obj.roles or 'wheel' not in obj.roles) and 'wheel' in value: value.remove('wheel') obj.roles = value
def create_conv(self, models, factory=None): return convs.Char( convs.length(0, max_length), NoUpperConv, StripTrailingDotConv, required=self.required, )
def create_conv(self, models, factory=None): if self.error_regex is None: self.error_regex = convs.Char.error_regex return convs.Char(convs.length(self.min_length, self.max_length), *self.validators, required=self.required, regex=self.regex, error_regex=self.error_regex)
class ItemForm(ModelForm): fields = [ Field('name', conv=convs.Char(convs.length(3, 250), required=False), label=u"Имя"), Field('email', conv=convs.Char(convs.length(0, 200), required=False), label=u"E-mail"), Field('login', conv=convs.Char( convs.DBUnique( model=Model, message=u'Объект с таким значением уже существует'), convs.length(3, 250), ), label=u"Логин"), shortcuts.PasswordSet( 'password', filters=(clean_password, ), widget=widgets.FieldSetWidget(template='widgets/fieldset-line'), label=u'пароль', confirm_label=u'подтверждение'), Field('groups', label=u'Роли', conv=convs.ListOf( convs.ModelChoice(model=AdminGroup, title_field='ru_title')), widget=widgets.CheckBoxSelect()) ] def update__password(self, obj, name, value): if value is not None: obj.set_password(value) def update__roles(self, obj, name, value): if obj.roles is not None and 'wheel' in obj.roles and \ 'wheel' not in value: value.append('wheel') if (not obj.roles or 'wheel' not in obj.roles) and 'wheel' in value: value.remove('wheel') obj.roles = value
def create_conv(self, models, factory=None): if self.choices: choices = self.choices else: assert factory and hasattr(factory, 'model'), \ 'Field name=%s: You must specify choices or factory.model' % \ self.name model = getattr(models, factory.model) choices = getattr(model, '%s_choices' % self.name) return convs.EnumChoice(conv=convs.Char(required=self.required), choices=choices, required=self.required)
def create_conv(self, models, factory=None): return convs.Char(required=self.required)
def create_conv(self, models, factory=None): return convs.EnumChoice(conv=convs.Char(), choices=self.get_choices(models, factory))
def create_conv(self, models, factory=None): return convs.Char()
self.order_by_default)) return method(query, value, is_desc) def order_by_default(self, query, value, is_desc): value = getattr(self.form.model, value) if is_desc: value = desc(value) return query.order_by(value) def set_raw_value(self, raw_data, value): if value == self.conv.from_python(self.get_initial()): raw_data[self.input_name] = '' else: raw_data[self.input_name] = value object_ref_fields = [ Field('stream_name', conv=convs.Char(convs.length(0, 100), required=True)), Field('object_id', conv=convs.Char(convs.length(0, 100), required=True)), ] # Expose all variables defined after imports and all variables imported from # parent module __all__ = [x for x in set(locals().keys()) - (set(_all2) - set(_all1)) if not x.startswith('_')] del _all1, _all2
class EditorNoteForm(Form): fields = object_ref_fields + [ Field('body', conv=convs.Char(required=True)), ]
class MyTrayObjectForm(Form): fields = object_ref_fields + [ Field('comment', conv=convs.Char(required=False)), ]