Ejemplo n.º 1
0
 def create_conv(self, models, factory=None):
     model_conv = convs.ModelChoice(*self.validators,
                                    model=getattr(models, self.model),
                                    conv=self.conv(required=self.required),
                                    condition=self.condition,
                                    required=self.required)
     if self.multiple:
         return convs.ListOf(model_conv, required=self.required)
     else:
         return model_conv
Ejemplo n.º 2
0
 def create_conv(self, models, factory=None):
     model_conv = convs.ModelChoice(
         model=getattr(models, self.model),
         conv=self.conv(),
         condition=self.condition,
     )
     if self.multiple:
         return convs.ListOf(model_conv)
     else:
         return model_conv
Ejemplo n.º 3
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
Ejemplo n.º 4
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
Ejemplo n.º 5
0
 def __init__(self, *args, **kwargs):
     # XXX hack! do not do in this way. Use class_factory
     streams = kwargs.pop('streams', None)
     types = kwargs.pop('types')
     models = kwargs.pop('models')
     env = args[0]
     fields = []
     for field in self.fields:
         field = field()
         if field.name == 'users':
             AdminUser = env.auth_model
             field = field(conv=convs.ModelChoice(model=AdminUser,
                                                  title_field="login"))
         if field.name == 'streams':
             field = field(
                 conv=convs.ListOf(convs.EnumChoice(choices=streams),
                                   #all_by_default
                                   ))
         if field.name == 'type':
             field = field(conv=convs.EnumChoice(choices=types))
         fields.append(field)
     self.fields = fields
     FilterForm.__init__(self, *args, **kwargs)