예제 #1
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
예제 #2
0
 def create_conv(self, models, factory=None):
     return convs.Char(
         convs.length(0, max_length),
         NoUpperConv,
         StripTrailingDotConv,
         required=self.required,
     )
예제 #3
0
 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)
예제 #4
0
파일: admins.py 프로젝트: motor23/cms34
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
예제 #5
0
 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)
예제 #6
0
 def create_conv(self, models, factory=None):
     return convs.Char(required=self.required)
예제 #7
0
 def create_conv(self, models, factory=None):
     return convs.EnumChoice(conv=convs.Char(),
                             choices=self.get_choices(models, factory))
예제 #8
0
 def create_conv(self, models, factory=None):
     return convs.Char()
예제 #9
0
                             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
예제 #10
0
        class EditorNoteForm(Form):

            fields = object_ref_fields + [
                Field('body', conv=convs.Char(required=True)),
            ]
예제 #11
0
        class MyTrayObjectForm(Form):

            fields = object_ref_fields + [
                Field('comment',
                      conv=convs.Char(required=False)),
            ]