class FileFieldSet(FieldSet): '''FieldSet aggregating fields required for file upload handling:: ''' fields = [ FileField('file', conv=convs.SimpleFile(), widget=widgets.FileInput()), Field('mode', conv=convs.EnumChoice(choices=[('existing', ''), ('transient', ''), ('empty', '')], required=True), widget=widgets.HiddenInput), Field('transient_name', conv=convs.Char(check_file_path, required=False), widget=widgets.HiddenInput), Field('original_name', conv=convs.Char(check_file_path, required=False), widget=widgets.HiddenInput), ] conv = FileFieldSetConv def __init__(self, name, **kwargs): kwargs.setdefault('fields', self.fields) kwargs.setdefault('conv', self.conv) FieldSet.__init__(self, name, **kwargs) def get_initial(self): # Redefine because FieldSet.get_initial returns dict by default, # but python value of FileFieldSet is either None, either BaseFile # instance. return None
class ListItemForm(BaseListItemForm): ordering_field = 'order' template = 'stream_sortables.html' def __init__(self, *args, **kwargs): self.ordering_field = kwargs.pop('ordering_field', self.ordering_field) BaseListItemForm.__init__(self, *args, **kwargs) fields = [ FieldList( 'items', widget=FieldList.widget(template='list_item_form'), field=FieldSet('item', fields=[ Field('item', conv=ListItemModelChoice(required=False), label=u'item'), Field("order", conv=convs.Int(), label=u'Порядок'), ]), ), ] def initial_for_item(self, item): return {"item": item, "order": getattr(item, self.ordering_field)}
class _Form(Form): fields = [ FieldBlock('field block', fields=[ Field('number', convs.Int()), Field('title', convs.Char()), ], permissions='r'), ]
class _Form(Form): fields = [ FieldBlock('field block', [ Field('number', convs.Int()), FieldBlock('field block', [ Field('title', convs.Char()), ]), ]), ]
class f(Form): fields = [ FieldSet('dt', conv=convs.SplitDateTime(**kwargs), fields=[ Field('date', conv=convs.Date()), Field('time', conv=convs.Time()), ]) ]
class F(Form): fields = [ Field('top', conv=convs.Int(), initial=246), FieldBlock('', fields=[ Field('num', conv=convs.Int()), Field('f2', conv=AssertConv()) ]) ]
class f(Form): fields = [ FieldSet('pass', conv=PasswordConv(**kwargs), fields=[ Field('pass'), Field('conf'), ]) ]
class F(Form): fields = [ Field('name', conv=convs.Char(), widget=self.widget(classname="cls")), Field('unreadable', permissions="w", conv=convs.Char(), widget=self.widget(classname="cls")) ]
class F(Form): fields = [ FieldSet('fieldset', fields=[ FieldList('fieldlist', field=FieldSet( None, fields=[Field('subfield')])) ]), FieldBlock('field block', [Field('blocksubfield')], name='block') ]
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
class ListItemForm(Form): template = 'stream_sortables.html' def __init__(self, *args, **kwargs): kwargs['initial'] = self.initial_for_items(kwargs.pop('items', [])) Form.__init__(self, *args, **kwargs) fields = [ FieldList( 'items', widget=FieldList.widget(template='list_item_form'), field=FieldSet('item', fields=[ Field('item', conv=ListItemModelChoice(required=False), label=u'item'), ]), ), ] def initial_for_item(self, item): return {'item': item} def initial_for_items(self, items): return {'items': [self.initial_for_item(item) for item in items]}
class F(Form): fields = [ Field('name', conv=convs.EnumChoice(choices=self.choices, required=True), widget=self.widget()) ]
class F(Form): fields = [ Field('name', conv=convs.Char(), widget=self.widget( getter=lambda x: x.replace('value', 'display'))) ]
class _Form(Form): fields = [ FieldSet('fs', fields=[ FieldBlock('field block', [Field('number', convs.Int())]), ]) ]
def create_field(self, models, factory=None): return Field( self.name, conv=self.create_conv(models, factory), widget=self.create_widget(models, factory), label=self.label, filter_query=self.filter_query, )
class F(Form): fields = [ Field( 'name', conv=convs.Char(), widget=self.widget(), permissions="r", ) ]
class F(Form): fields = [ FieldList('list', field=FieldSet(None, fields=[ Field('name', conv=convs.Char(), widget=widgets.TextInput) ])) ]
class F(Form): fields = [ Field('name', conv=convs.EnumChoice(conv=convs.Bool(), required=True, choices=[(False, u'no'), (True, u'yes')]), initial=False, widget=self.widget()) ]
def create_field(self, models, factory=None): kwargs = {} if self.initial is not None: kwargs['initial'] = self.initial return Field(self.name, conv=self.create_conv(models, factory), widget=self.create_widget(models, factory), permissions=self.permissions_getter(self.permissions), label=self.label, hint=self.hint, **kwargs)
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
class F(Form): fields = [Field('name', conv=convs.Char(), widget=self.widget())]
class F(Form): fields = [Field('name', conv=convs.ListOf(convs.Int))]
class F(Form): fields = [ Field('name', conv=convs.ListOf(convs.Int), initial=[1, 2]) ]
class F(Form): fields = [ Field('obj', conv=conv), ]
class F(Form): fields = [ FieldSet('fs', conv=convs.ModelDictConv(*a, **kw), fields=[Field('a'), Field('b')]), ]
class F(Form): fields = [Field(name, conv)]
class F(Form): fields = [Field('inp')]
class F(Form): fields = [ Field('name', conv=convs.Char(), widget=self.widget(escape=False)) ]
class f(Form): fields = [Field('readonly', conv=convs.DisplayOnly())]
class f(Form): fields = [ FieldBlock('block', fields=[Field('number', conv=convs.Int)]) ]