Exemple #1
0
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)}
Exemple #3
0
 class _Form(Form):
     fields = [
         FieldBlock('field block',
                    fields=[
                        Field('number', convs.Int()),
                        Field('title', convs.Char()),
                    ],
                    permissions='r'),
     ]
Exemple #4
0
 class _Form(Form):
     fields = [
         FieldBlock('field block', [
             Field('number', convs.Int()),
             FieldBlock('field block', [
                 Field('title', convs.Char()),
             ]),
         ]),
     ]
Exemple #5
0
 class f(Form):
     fields = [
         FieldSet('dt',
                  conv=convs.SplitDateTime(**kwargs),
                  fields=[
                      Field('date', conv=convs.Date()),
                      Field('time', conv=convs.Time()),
                  ])
     ]
Exemple #6
0
 class F(Form):
     fields = [
         Field('top', conv=convs.Int(), initial=246),
         FieldBlock('',
                    fields=[
                        Field('num', conv=convs.Int()),
                        Field('f2', conv=AssertConv())
                    ])
     ]
Exemple #7
0
 class f(Form):
     fields = [
         FieldSet('pass',
                  conv=PasswordConv(**kwargs),
                  fields=[
                      Field('pass'),
                      Field('conf'),
                  ])
     ]
Exemple #8
0
 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"))
     ]
Exemple #9
0
 class F(Form):
     fields = [
         FieldSet('fieldset',
                  fields=[
                      FieldList('fieldlist',
                                field=FieldSet(
                                    None, fields=[Field('subfield')]))
                  ]),
         FieldBlock('field block', [Field('blocksubfield')],
                    name='block')
     ]
Exemple #10
0
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
Exemple #11
0
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]}
Exemple #12
0
 class F(Form):
     fields = [
         Field('name',
               conv=convs.EnumChoice(choices=self.choices,
                                     required=True),
               widget=self.widget())
     ]
Exemple #13
0
 class F(Form):
     fields = [
         Field('name',
               conv=convs.Char(),
               widget=self.widget(
                   getter=lambda x: x.replace('value', 'display')))
     ]
Exemple #14
0
 class _Form(Form):
     fields = [
         FieldSet('fs',
                  fields=[
                      FieldBlock('field block',
                                 [Field('number', convs.Int())]),
                  ])
     ]
Exemple #15
0
 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,
     )
Exemple #16
0
 class F(Form):
     fields = [
         Field(
             'name',
             conv=convs.Char(),
             widget=self.widget(),
             permissions="r",
         )
     ]
Exemple #17
0
 class F(Form):
     fields = [
         FieldList('list',
                   field=FieldSet(None,
                                  fields=[
                                      Field('name',
                                            conv=convs.Char(),
                                            widget=widgets.TextInput)
                                  ]))
     ]
Exemple #18
0
 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())
     ]
Exemple #19
0
 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)
Exemple #20
0
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
Exemple #21
0
 class F(Form):
     fields = [Field('name', conv=convs.Char(), widget=self.widget())]
Exemple #22
0
 class F(Form):
     fields = [Field('name', conv=convs.ListOf(convs.Int))]
Exemple #23
0
 class F(Form):
     fields = [
         Field('name', conv=convs.ListOf(convs.Int), initial=[1, 2])
     ]
Exemple #24
0
 class F(Form):
     fields = [
         Field('obj', conv=conv),
     ]
Exemple #25
0
 class F(Form):
     fields = [
         FieldSet('fs',
                  conv=convs.ModelDictConv(*a, **kw),
                  fields=[Field('a'), Field('b')]),
     ]
Exemple #26
0
 class F(Form):
     fields = [Field(name, conv)]
Exemple #27
0
 class F(Form):
     fields = [Field('inp')]
Exemple #28
0
 class F(Form):
     fields = [
         Field('name',
               conv=convs.Char(),
               widget=self.widget(escape=False))
     ]
Exemple #29
0
 class f(Form):
     fields = [Field('readonly', conv=convs.DisplayOnly())]
Exemple #30
0
 class f(Form):
     fields = [
         FieldBlock('block', fields=[Field('number', conv=convs.Int)])
     ]