Ejemplo n.º 1
0
class ContactSchema(OriginContactSchema):

    public_phone = colander.SchemaNode(
        DictSchemaType(),
        validator=colander.All(
            PhoneValidator()),
        missing="",
        widget=PhoneWidget(css_class="contact-phone"),
        title=_('Public phone'),
        description=_("Indicate the public phone number. Only spaces are allowed as separator for phone numbers.")
        )

    professional_phone = colander.SchemaNode(
        DictSchemaType(),
        validator=colander.All(
            PhoneValidator()),
        missing="",
        widget=PhoneWidget(css_class="contact-phone"),
        title=_('Professional phone'),
        description=_("Indicate the professional phone number. Only spaces are allowed as separator for phone numbers.")
        )

    person_to_contact = colander.SchemaNode(
        colander.String(),
        title=_('Person to contact'),
        )

    @invariant
    def contact_invariant(self, appstruct):
        pass
Ejemplo n.º 2
0
class PatchUserSchema(schemas.MappingNode):
    first_name = schemas.StringNode(
        title='First Name', missing=colander.drop,
        validator=colander.All(
            colander.Length(max=50),
            colander.Regex(r'^[a-zA-z0-9]+$')
        ),
    )
    last_name = schemas.StringNode(
        title='Last Name', missing=colander.drop,
        validator=colander.All(
            colander.Length(max=50),
            colander.Regex(r'^[a-zA-z0-9]+$')
        ),
    )
    age = schemas.UnsignedIntegerNode(
        title='Age', nullable=True, missing=colander.drop,
    )
    sex = schemas.StringNode(
        title='Sex', missing=colander.drop,
        validator=colander.OneOf(['m', 'f']), nullable=True
    )
    children = schemas.SequenceNode(
        Child(title='Child', missing=colander.drop),
        missing=colander.drop,
    )
    current_work = Work(title='Current work', missing=colander.drop)
Ejemplo n.º 3
0
class UpdateAccountSchema(colander.MappingSchema):
    email = colander.SchemaNode(colander.String(),
                                missing=colander.drop,
                                validator=colander.All(
                                    colander.Email(),
                                    colander.Function(
                                        partial(is_unused_user_attribute,
                                                'email'),
                                        'Already used email')))
    name = colander.SchemaNode(colander.String(),
                               missing=colander.drop,
                               validator=colander.Length(min=3))
    forum_username = colander.SchemaNode(
        colander.String(),
        missing=colander.drop,
        validator=colander.All(
            colander.Length(max=25),
            colander.Function(
                partial(is_unused_user_attribute,
                        'forum_username',
                        lowercase=True), 'Already used forum name')))
    currentpassword = colander.SchemaNode(colander.String(encoding=ENCODING),
                                          validator=colander.Length(min=3))
    newpassword = colander.SchemaNode(colander.String(encoding=ENCODING),
                                      missing=colander.drop,
                                      validator=colander.Length(min=3))

    is_profile_public = colander.SchemaNode(colander.Boolean(),
                                            missing=colander.drop)
Ejemplo n.º 4
0
class OrganizationSchema(GroupSchema):
    """Schema for Organization"""

    name = NameSchemaNode(editing=context_is_a_organization, )

    function = colander.SchemaNode(
        colander.String(),
        widget=function_widget,
        title=_('Function'),
    )

    logo = colander.SchemaNode(
        ObjectData(Image),
        widget=get_file_widget(),
        required=False,
        missing=None,
        title=_('Logo'),
    )

    email = colander.SchemaNode(
        colander.String(),
        widget=EmailInputWidget(),
        validator=colander.All(colander.Email(), colander.Length(max=100)),
        missing='',
        title=_('Email'),
    )

    phone = colander.SchemaNode(
        DictSchemaType(),
        validator=colander.All(PhoneValidator()),
        missing="",
        widget=PhoneWidget(css_class="contact-phone"),
        title=_("Phone number"),
        description=
        _("Indicate the phone number. Only spaces are allowed as separator for phone numbers."
          ))

    fax = colander.SchemaNode(
        DictSchemaType(),
        validator=colander.All(
            PhoneValidator(
                _('${phone} fax number not valid for the selected country (${country})'
                  ))),
        widget=PhoneWidget(css_class="contact-fax"),
        title=_("Fax"),
        missing='',
        description=
        _("Indicate the fax number. Only spaces are allowed as separator for fax numbers."
          ))

    managers = colander.SchemaNode(
        colander.Set(),
        widget=members_choice,
        title=_('Managers'),
    )
class BankAccountNumberSchema(colander.MappingSchema):
    title = _(u"Bank Account")
    bic = BicField(title=_(u"BIC"))
    type = TypeField(title=_(u"Type"))
    number = NumberField(title=_(u"Number"))
    validator = colander.All(bank_account_is_complete,
                             bank_account_number_is_valid)
Ejemplo n.º 6
0
class RegisterSchema(CSRFSchema):
    username = colander.SchemaNode(
        colander.String(),
        validator=colander.All(
            validators.Length(min=USERNAME_MIN_LENGTH, max=USERNAME_MAX_LENGTH),
            colander.Regex(
                USERNAME_PATTERN,
                msg=_("Must have only letters, numbers, periods, and " "underscores."),
            ),
            unique_username,
            unblacklisted_username,
        ),
        title=_("Username"),
        hint=_(
            "Must be between {min} and {max} characters, containing only "
            "letters, numbers, periods, and underscores."
        ).format(min=USERNAME_MIN_LENGTH, max=USERNAME_MAX_LENGTH),
        widget=deform.widget.TextInputWidget(autofocus=True),
    )
    email = email_node(title=_("Email address"))
    password = new_password_node(title=_("Password"))

    privacy_accepted = colander.SchemaNode(
        colander.Boolean(),
        description=Markup(_privacy_accepted_message()),
        validator=privacy_acceptance_validator,
        widget=deform.widget.CheckboxWidget(
            omit_label=True, css_class="form-checkbox--inline"
        ),
    )
Ejemplo n.º 7
0
class GroupSchema(CSRFSchema):
    """The schema for the create-a-new-group form."""

    name = colander.SchemaNode(
        colander.String(),
        title=_("Name"),
        validator=colander.All(
            validators.Length(min=GROUP_NAME_MIN_LENGTH,
                              max=GROUP_NAME_MAX_LENGTH),
            unblacklisted_group_name_slug),
        widget=deform.widget.TextInputWidget(
            autofocus=True,
            css_class="group-form__name-input js-group-name-input",
            disable_autocomplete=True,
            label_css_class="group-form__name-label",
            max_length=GROUP_NAME_MAX_LENGTH))

    description = colander.SchemaNode(
        colander.String(),
        title=_("Description"),
        validator=validators.Length(max=GROUP_DESCRIPTION_MAX_LENGTH),
        missing=None,
        widget=deform.widget.TextAreaWidget(
            css_class="group-form__description-input",
            label_css_class="group-form__description-label",
            min_length=0,
            max_length=GROUP_DESCRIPTION_MAX_LENGTH))
Ejemplo n.º 8
0
class RolesSchema(Schema):

    roles = colander.SchemaNode(colander.Set(),
                                validator=colander.All(roles_validator),
                                widget=roles_choice,
                                title=_('Roles'),
                                missing='Member')
Ejemplo n.º 9
0
class SearchableEntitySchema(Schema):
    typ_factory = ObjectData

    tree = colander.SchemaNode(
        typ=DictSchemaType(),
        validator=colander.All(keywords_validator),
        widget=keyword_widget,
        default=DEFAULT_TREE,
        title=_('Categories'),
        description=_('Indicate the category of the event. Please specify a second keyword level for each category chosen.')
        )

    metadata = omit(MetadataSchema(widget=SimpleMappingtWidget(
                                mapping_css_class='controled-form'
                                                  ' object-well default-well hide-bloc',
                                control_css_class='alert alert-success',
                                ajax=True,
                                activator_css_class="glyphicon glyphicon-cog",
                                activator_title=_('Manage metadata'))),
                        ["_csrf_token_"])

    def deserialize(self, cstruct=colander.null):
        appstruct = super(SearchableEntitySchema, self).deserialize(cstruct)
        if 'metadata' not in appstruct:
            return appstruct

        metadata = appstruct.pop('metadata', {})
        appstruct.update(metadata)
        return appstruct
Ejemplo n.º 10
0
class PresentIdeaSchema(Schema):

    members = colander.SchemaNode(
        colander.Set(),
        widget=members_choice,
        validator=colander.All(
            Length(_,
                   min=1,
                   min_message="""Vous devez sélectionner """
                   """au moins {min} membre, ou saisir {min}"""
                   """ adresse courrier électronique."""), emails_validator),
        title=_('Recipients'))

    subject = colander.SchemaNode(
        colander.String(),
        default=default_subject,
        title=_('Subject'),
    )

    message = colander.SchemaNode(
        colander.String(),
        validator=colander.Length(max=2000),
        default=default_message,
        widget=deform.widget.TextAreaWidget(rows=10, cols=60),
    )

    send_to_me = colander.SchemaNode(colander.Boolean(),
                                     widget=deform.widget.CheckboxWidget(),
                                     label=_('Put me in copy'),
                                     title='',
                                     missing=False)
Ejemplo n.º 11
0
def order_id_validator(node, kw):
    request = kw.get('request')

    def validator(node, value):
        invoice = (
            DBSession.query(Invoice)
            .filter(Invoice.order_id == value)
            .first()
        )
        if (
            invoice
            and str(invoice.id) != request.params.get('id')
        ):
            raise colander.Invalid(
                node,
                _(u'Invoice for this order already exists'),
            )
        order = Order.get(value)
        for order_item in order.orders_items:
            if not order_item.calculation and order_item.is_success():
                raise colander.Invalid(
                    node,
                    _(u'Some order items has no calculations'),
                )
    return colander.All(validator,)
Ejemplo n.º 12
0
class KeywordsConfSchema(Schema):

    tree = colander.SchemaNode(
        typ=DictSchemaType(),
        validator=colander.All(keywords_validator),
        widget=keyword_widget,
        default=DEFAULT_TREE,
        title=_('Keywords'),
    )

    can_add_keywords = colander.SchemaNode(
        colander.Boolean(),
        widget=deform.widget.CheckboxWidget(),
        label=_('Authorize the addition of keywords'),
        title='',
        default=True,
        missing=True)

    @invariant
    def contact_invariant(self, appstruct):
        can_add_keywords = appstruct.get('can_add_keywords', 'false')
        can_add_keywords = False if can_add_keywords == 'false' else True
        keywords = appstruct.get('tree', colander.null)
        if not can_add_keywords and keywords is colander.null:
            raise colander.Invalid(self,
                                   _('You must enter at least one keyword.'))
class _PersonsImportSchema(_PassportImportSchema,
                           _ForeignPassportImportSchema):
    file = colander.SchemaNode(File(), validator=extensions_validator)
    first_name = colander.SchemaNode(
        colander.Integer(),
        validator=colander.All(
            colander.Range(min=1, min_err=_(u'Set num of column'))),
    )
    second_name = colander.SchemaNode(colander.Integer(), )
    last_name = colander.SchemaNode(
        colander.Integer(),
        validator=colander.All(
            colander.Range(min=1, min_err=_(u'Set num of column'))),
    )
    phones = colander.SchemaNode(colander.Integer(), )
    emails = colander.SchemaNode(colander.Integer(), )
Ejemplo n.º 14
0
class UserSchema(Schema):
    """ Property schema for :class:`substanced.principal.User` objects.
    """
    name = colander.SchemaNode(
        colander.String(),
        validator=login_validator,
        title='Login',
        )
    email = colander.SchemaNode(
        colander.String(),
        validator=colander.All(
            colander.Email(),
            colander.Length(max=100)
            ),
        )
    tzname = colander.SchemaNode(
        colander.String(),
        title='Timezone',
        widget=tzname_widget,
        validator=colander.OneOf(_ZONES)
        )
    locale = colander.SchemaNode(
        colander.String(),
        title='Locale',
        widget=locale_widget,
        missing=locale_missing,
        validator=colander.OneOf(_LOCALES),
    )
Ejemplo n.º 15
0
def name_validator(node, kw):
    """Validate that the short name doesn't exist in the parent already.
    """
    request = kw['request']
    context = request.context

    # Add or edit form?
    if request.registry.content.typeof(context) == 'Analysis':
        parent = context.__parent__
        instance = context
    else:
        parent = context
        instance = None

    def namecheck(node, value):
        try:
            new_name = short_name(value)

            # Only check if we are creating new content or actually changing the name
            if instance is None or instance.__name__ != new_name:
                parent.check_name(new_name)
        except FolderKeyError:
            raise colander.Invalid(
                node, "Another analysis already exists with this name", value)
        except Exception as e:
            raise colander.Invalid(node, e.args[0], value)

    return colander.All(
        colander.Length(1),
        namecheck,
    )
Ejemplo n.º 16
0
 def add_unique_validator(self, column, column_id):
     validator = partial(unique_validator, self.class_, column, column_id)
     if self[column.name].validator is None:
         self[column.name].validator = validator
     else:
         self[column.name].validator = colander.All(
             self[column.name].validator, validator)
Ejemplo n.º 17
0
def login_validator(node, kw):
    request = kw['request']
    context = request.context
    adding = not request.registry.content.istype(context, 'User')

    def exists(node, value):
        principals = find_service(context, 'principals')
        if adding:
            try:
                context.check_name(value)
            except Exception as e:
                raise colander.Invalid(node, e.args[0], value)
        else:
            users = principals['users']
            if value != context.__name__:
                try:
                    users.check_name(value)
                except Exception as e:
                    raise colander.Invalid(node, e.args[0], value)

        groups = principals['groups']
        if value in groups:
            raise colander.Invalid(node,
                                   'Group named "%s" already exists' % value)

    return colander.All(
        colander.Length(min=1, max=100),
        exists,
    )
Ejemplo n.º 18
0
class UserSchema(Schema):
    """ The property schema for :class:`substanced.principal.User`
    objects."""
    name = colander.SchemaNode(
        colander.String(),
        validator=login_validator,
        title='Login',
        )
    email = colander.SchemaNode(
        colander.String(),
        validator=colander.All(
            colander.Email(),
            colander.Length(max=100)
            ),
        )
    tzname = colander.SchemaNode(
        colander.String(),
        title='Timezone',
        widget=ChosenSingleWidget(
            values=zip(pytz.all_timezones, pytz.all_timezones)
            ),
        validator=colander.OneOf(pytz.all_timezones),
        )
    groupids = MultireferenceIdSchemaNode(
        choices_getter=groups_choices,
        title='Groups',
        )
Ejemplo n.º 19
0
class EditProfileSchema(CSRFSchema):
    display_name = colander.SchemaNode(
        colander.String(),
        missing=None,
        validator=validators.Length(max=DISPLAY_NAME_MAX_LENGTH),
        title=_('Display name'))

    description = colander.SchemaNode(colander.String(),
                                      missing=None,
                                      validator=validators.Length(max=250),
                                      widget=deform.widget.TextAreaWidget(
                                          max_length=250,
                                          rows=4,
                                      ),
                                      title=_('Description'))

    location = colander.SchemaNode(colander.String(),
                                   missing=None,
                                   validator=validators.Length(max=100),
                                   title=_('Location'))

    link = colander.SchemaNode(colander.String(),
                               missing=None,
                               validator=colander.All(
                                   validators.Length(max=250), validate_url),
                               title=_('Link'))
Ejemplo n.º 20
0
class PublishProposalSchema(Schema):

    vote = colander.SchemaNode(
        colander.Boolean(false_val='False', true_val='True'),
        default=False,
        title=_('Options'),
        )

    work_mode = colander.SchemaNode(
        colander.String(),
        widget=mode_choice,
        default=mode_choice_default,
        title=_('Work mode'),
        description=_('Choose the work mode')
        )

    elected = colander.SchemaNode(
        colander.String(),
        title=_('Duration of the amendment cycle'),
    )

    members_to_invite = colander.SchemaNode(
        colander.Set(),
        widget=members_choice,
        validator=colander.All(emails_validator),
        title=_('Members to invite'),
        description= _('You can invite members to join the workgroup'),
        default=[],
        missing=[]
        )
Ejemplo n.º 21
0
class ParticipateSchema(Schema):

    first_name = colander.SchemaNode(
        colander.String(),
        title=_('First name'),
    )

    last_name = colander.SchemaNode(
        colander.String(),
        title=_('Last name'),
    )

    email = colander.SchemaNode(
        colander.String(),
        widget=EmailInputWidget(),
        validator=colander.All(colander.Email(), email_validator,
                               colander.Length(max=100)),
        title=_('Email'),
        description=_('The e-mail address where to send game result'))

    accept_conditions = colander.SchemaNode(
        colander.Boolean(),
        widget=conditions_widget,
        label=_('I have read and accept the terms and conditions.'),
        title='',
        missing=False)
Ejemplo n.º 22
0
class SubscribeSchema(Schema):

    newsletters = colander.SchemaNode(
        SetObjectType(),
        widget=newsletters_choice,
        default=newsletters_default,
        title=_('Newsletters'),
        description=_('Please choose one or more newsletters.'),
        validator=colander.Length(min=1))

    first_name = colander.SchemaNode(
        colander.String(),
        title=_('First name'),
    )

    last_name = colander.SchemaNode(
        colander.String(),
        title=_('Last name'),
    )

    email = colander.SchemaNode(colander.String(),
                                widget=EmailInputWidget(),
                                validator=colander.All(
                                    colander.Email(),
                                    colander.Length(max=100)),
                                title=_('Email'))
Ejemplo n.º 23
0
def resource_validator(node, kw):
    request = kw.get('request')

    def validator(node, value):
        path = value.split('.')
        module, attr = '.'.join(path[:-1]), path[-1]
        try:
            mod = importlib.import_module(module)
            if not hasattr(mod, attr):
                raise colander.Invalid(node, _(u"Resource does not exist"))
        except ImportError:
            raise colander.Invalid(node, _(u"Resource module does not exist"))
        except:
            raise colander.Invalid(node, _(u"Check module name"))

        resource_type = ResourceType.by_resource_name(module, attr)
        if (resource_type
                and (str(resource_type.id) != request.params.get('id') or
                     (str(resource_type.id) == request.params.get('id')
                      and request.view_name == 'copy'))):
            raise colander.Invalid(
                node,
                _(u'Resource Type with the same resource exists'),
            )

    return colander.All(
        colander.Length(max=128),
        validator,
    )
Ejemplo n.º 24
0
def name_validator(node, kw):
    request = kw.get('request')

    def validator(node, value):
        location = (
            DBSession.query(Location)
            .filter(
                Location.region_id == request.params.get('region_id'),
                Location.name == value
            )
            .first()
        )
        if (
            location
            and (
                str(location.id) != request.params.get('id')
                or (
                    str(location.id) == request.params.get('id')
                    and request.view_name == 'copy'
                )
            )
        ):
            raise colander.Invalid(
                node,
                _(u'Location with the same name exists'),
            )
    return colander.All(colander.Length(max=128), validator,)
Ejemplo n.º 25
0
class PrincipalFull(PrincipalBasic):
    name = colander.SchemaNode(
        colander.String(),
        title=_("Name"),
        validator=colander.All(name_pattern_validator, name_new_validator),
    )
    password = colander.SchemaNode(
        colander.String(),
        title=_("Password"),
        validator=colander.Length(min=5),
        missing=None,
        widget=CheckedPasswordWidget(),
    )
    active = colander.SchemaNode(
        colander.Boolean(),
        title=_("Active"),
        description=_("Untick this to deactivate the account."),
    )
    roles = colander.SchemaNode(
        colander.Set(),
        validator=roleset_validator,
        missing=[],
        title=_("Global roles"),
        widget=CheckboxChoiceWidget(),
    )
    groups = Groups(
        title=_("Groups"),
        missing=[],
        # XXX min_len doesn't really do what we want here.  We'd like
        # the close buttons to appear nevertheless (maybe the now
        # deprecated render_initial_item did exactly that).
        widget=SequenceWidget(min_len=1),
    )
Ejemplo n.º 26
0
class RegisterFormSchema(colander.MappingSchema):
	'''
	register form schema define using colander schema pacakge
	'''
	

	name = colander.SchemaNode(
		colander.String(),
		title='First Name'
		)
	lastName = colander.SchemaNode(
		colander.String(),
		title='Last Name'
		)
	email =  colander.SchemaNode(
		colander.String(),
		title='Email',
		validator=colander.All(colander.Email(),ValidateRegistrationForm.uniqe_email_validate),
		widget=deform.widget.TextInputWidget( type='email', placeholder="*****@*****.**"),
		)
	password = colander.SchemaNode(
		colander.String(),
		validator=colander.Length(min=5, max=100),
		widget=deform.widget.CheckedPasswordWidget(redisplay=True),
		)
Ejemplo n.º 27
0
Archivo: schemas.py Proyecto: ziqizh/h
class EditProfileSchema(CSRFSchema):
    display_name = colander.SchemaNode(
        colander.String(),
        missing=None,
        validator=validators.Length(max=DISPLAY_NAME_MAX_LENGTH),
        title=_('Display name'))

    description = colander.SchemaNode(colander.String(),
                                      missing=None,
                                      validator=validators.Length(max=250),
                                      widget=deform.widget.TextAreaWidget(
                                          max_length=250,
                                          rows=4,
                                      ),
                                      title=_('Description'))

    location = colander.SchemaNode(colander.String(),
                                   missing=None,
                                   validator=validators.Length(max=100),
                                   title=_('Location'))

    link = colander.SchemaNode(colander.String(),
                               missing=None,
                               validator=colander.All(
                                   validators.Length(max=250), validate_url),
                               title=_('Link'))

    orcid = colander.SchemaNode(
        colander.String(),
        missing=None,
        validator=validate_orcid,
        title=_('ORCID'),
        hint=
        _('ORCID provides a persistent identifier for researchers (see orcid.org).'
          ))
Ejemplo n.º 28
0
def jira_url_validator(node, kw):
    """Validate that the URL is valid, and also that the short name doesn't
    exist in the parent already.
    """
    request = kw['request']
    context = request.context

    if request.registry.content.typeof(context) == 'JIRA Instance':
        parent = context.__parent__
        instance = context
    else:
        parent = context
        instance = None

    def namecheck(node, value):
        try:
            new_name = short_name(value)

            # Only check if we are creating new content or actually changing the name
            if instance is None or instance.__name__ != new_name:
                parent.check_name(new_name)
        except FolderKeyError:
            raise colander.Invalid(
                node,
                "Another configuration already exists for this JIRA instance",
                value)
        except Exception as e:
            raise colander.Invalid(node, e.args[0], value)

    return colander.All(
        colander.url,
        namecheck,
    )
Ejemplo n.º 29
0
class ContactSchema(Schema):

    services = colander.SchemaNode(colander.Set(),
                                   widget=contact_choice,
                                   title=_("Services to contact"),
                                   validator=colander.Length(min=1))

    name = colander.SchemaNode(colander.String(),
                               title=_('Name'),
                               missing='',
                               description=_('Please enter your full name'))

    email = colander.SchemaNode(
        colander.String(),
        widget=EmailInputWidget(),
        validator=colander.All(colander.Email(), colander.Length(max=100)),
        title=_('Email'),
        description=_('Please enter your email address'))

    subject = colander.SchemaNode(colander.String(), title=_('Subject'))

    message = colander.SchemaNode(
        colander.String(),
        widget=deform.widget.TextAreaWidget(rows=4, cols=60),
        title=_('Message'),
        description=_('Please enter the message you want to send.'))
Ejemplo n.º 30
0
class CreationCulturelleApplicationSchema(VisualisableElementSchema):
    """Schema for application configuration."""

    name = NameSchemaNode(editing=context_is_a_root, )

    titles = colander.SchemaNode(
        colander.Sequence(),
        colander.SchemaNode(colander.String(), name=_("Title")),
        widget=SequenceWidget(),
        default=DEFAULT_TITLES,
        title=_('List of titles'),
    )

    tree = colander.SchemaNode(
        typ=DictSchemaType(),
        validator=colander.All(keywords_validator),
        widget=keyword_widget,
        default=DEFAULT_TREE,
        title=_('Categories'),
    )

    organizations = colander.SchemaNode(
        colander.Sequence(),
        omit(
            OrganizationSchema(factory=Organization,
                               editable=True,
                               name=_('Organization'),
                               widget=SimpleMappingWidget(
                                   css_class='object-well default-well'),
                               omit=['managers']), ['_csrf_token_']),
        widget=organizations_choice,
        title=_('Organizations'),
    )