示例#1
0
class PostEditForm(BasePostForm):
    reason = StringField(
        label=_l("Reason"),
        description=_l("Description of your edit"),
        filters=(strip,),
        validators=(optional(),),
    )
示例#2
0
class UserProfileViewForm(UserProfileForm):
    communautes = QuerySelect2Field(
        u'Communautés d\'appartenance',
        get_label='name',
        view_widget=abilian_widgets.ListWidget(),
        query_factory=lambda: Community.query.all(),
        multiple=True,
        validators=[optional()])
示例#3
0
class BaseUserAdminForm(Form):

    email = StringField(
        _l("Email"),
        description=_l("Users log in with their email address."),
        view_widget=widgets.EmailWidget(),
        filters=(strip,),
        validators=[required()],
    )
    first_name = StringField(
        _l("First Name"),
        description=_l("ex: John"),
        filters=(strip,),
        validators=[required()],
    )
    last_name = StringField(
        _l("Last Name"),
        description=_l("ex: Smith"),
        filters=(strip,),
        validators=[required()],
    )

    can_login = BooleanField(
        _l("Login enabled"),
        description=_l("If unchecked, user will not be able to connect."),
        widget=widgets.BooleanWidget(),
    )

    groups = QuerySelect2Field(
        _l("Groups"),
        validators=(optional(),),
        multiple=True,
        collection_class=set,
        query_factory=lambda: Group.query.order_by(sa.sql.func.lower(Group.name).asc()),
        get_label="name",
    )

    roles = Select2MultipleField(
        _l("Roles"),
        description=_l(
            "Prefer groups to manage access rights. Directly assigning roles "
            "to users is possible but discouraged."
        ),
        choices=lambda: [(r.name, r.label) for r in Role.assignable_roles()],
    )

    password = StringField(
        _l("New Password"),
        description=_l("If empty the current password will not be changed."),
        widget=widgets.PasswordInput(autocomplete="off"),
    )
示例#4
0
    def get_validators(self, *args, **kwargs):
        """Default validators."""
        validators = []
        if self.required:
            validators.append(aw_validators.required())
        else:
            validators.append(aw_validators.optional())

        if self.validator_length_max != -1 or self.validator_length_min != -1:
            validators.append(
                aw_validators.Length(
                    min=self.validator_length_min, max=self.validator_length_max
                )
            )
        return validators
示例#5
0
class BasePostForm(Form):
    message = TextAreaField(label=_l("Message"),
                            widget=RichTextWidget(allowed_tags=WIDGET_ALLOWED),
                            filters=(strip, ),
                            validators=[required()])
    attachments = FileField(label=_l('Attachments'),
                            multiple=True,
                            validators=[optional()])

    def validate_message(self, field):
        field.data = bleach.clean(field.data,
                                  tags=ALLOWED_TAGS,
                                  attributes=ALLOWED_ATTRIBUTES,
                                  styles=ALLOWED_STYLES,
                                  strip=True)