Exemplo n.º 1
0
class AddMultiVotesSchema(BaseMultiVotesSchema):
    confirm = colander.SchemaNode(
        colander.Bool(),
        title=_("I understand the consequences of adding this"),
        validator=colander.Function(_only_true_validator,
                                    _("Confirmation not clicked")),
    )
Exemplo n.º 2
0
class DeviceSchema(colander.MappingSchema):
    resourceType = colander.SchemaNode(
        colander.String(),
        description=
        'ResourceType informs the parser which resource type this is',
        missing='Device',
        default='Device',
        validator=colander.Function(lambda x: x == 'Device',
                                    msg="resourceType can't be changed"))
    identifier = colander.SchemaNode(
        colander.String(),
        description='Instance id from manufacturer, owner and others',
        missing=colander.drop,
        default=colander.drop,
    )
    type = colander.SchemaNode(
        colander.String(),
        description="What kind of device this is",
        missing=colander.required,
    )
    manufacturer = colander.SchemaNode(
        colander.String(),
        description='Name of device manufacturer',
        missing=colander.drop,
    )
Exemplo n.º 3
0
class CreateView(colander.MappingSchema):
    label = colander.SchemaNode(colander.String())
    widget = colander.SchemaNode(
        colander.String(),
        validator=colander.Function(valid_widget_name))
    description = colander.SchemaNode(colander.String(),
                                      missing=None)
    state = colander.SchemaNode(JSONSchemaType())
Exemplo n.º 4
0
class TOSAgreeSchema(colander.Schema):
    widget = maybe_modal_form
    agree_check = colander.SchemaNode(
        colander.Bool(),
        title=_("I've read the full agreement and I agree to it"),
        validator=colander.Function(
            _return, _("You must agree to the terms to use this site.")),
    )
Exemplo n.º 5
0
class SingleLine(AdhocracySchemaNode):
    r"""UTF-8 encoded String without line breaks.

    Disallowed characters are linebreaks like: \n, \r.
    Example value: This is a something.
    """

    schema_type = colander.String
    default = ''
    missing = colander.drop
    validator = colander.Function(string_has_no_newlines_validator,
                                  msg='New line characters are not allowed.')
Exemplo n.º 6
0
def deferred_customer_validator(node, kw):
    request = kw['request']
    customers = get_customers_from_request(request)
    customer_ids = [customer.id for customer in customers]

    def customer_oneof(value):
        if value in ("0", 0):
            return u"Veuillez choisir un client"
        elif value not in customer_ids:
            return u"Entrée invalide"
        return True
    return colander.Function(customer_oneof)
Exemplo n.º 7
0
def validate_name(project, obj):
    """ Make sure that an entity's `name` attribute is unique
    within the scope of the project. """
    def check(name):
        entity = Entity.by_name(project, name)
        if entity is not None:
            if obj is None or obj.id != entity.id:
                return False
        return True
    name_unique = colander.Function(check,
                                    message="An entity with this name exists")
    return colander.All(name_unique, colander.Length(min=1))
Exemplo n.º 8
0
class SourceCreateForm(colander.MappingSchema):
    slug = colander.SchemaNode(colander.String(),
                               preparer=slugify,
                               validator=colander.All(
                                   colander.Function(source_slug_available,
                                                     'Invalid slug'),
                                   colander.Length(min=3, max=100)))  # noqa
    label = colander.SchemaNode(colander.String())
    crawler = colander.SchemaNode(colander.String(),
                                  validator=SourceCrawlers([]))
    users = SourceUsers(missing=[])
    config = colander.SchemaNode(colander.Mapping(unknown='preserve'))
Exemplo n.º 9
0
def validate(data, project):
    same_project = lambda s: Project.by_slug(s) == project
    same_project = colander.Function(same_project, message="Project exists")

    class ProjectValidator(colander.MappingSchema):
        slug = colander.SchemaNode(colander.String(),
                                   validator=colander.All(
                                       database_name, same_project))
        label = colander.SchemaNode(colander.String(),
                                    validator=colander.Length(min=3))
        author = colander.SchemaNode(AccountRef())
        settings = colander.SchemaNode(colander.Mapping(), missing={})

    validator = ProjectValidator()
    return validator.deserialize(data)
Exemplo n.º 10
0
def deferred_payment_amount_validation(node, kw):
    """
    Validate that the remittance amount is equal to the sum of the tva parts
    """
    def validate_sum_of_tvapayments(values):
        """
        Validate the sum of the tva payments is equal to the bank_remittance_id
        """
        tva_sum = sum([tvap['amount'] for tvap in values['tvas']])
        bank_remittance_id = values['payment_amount']
        diff = abs(tva_sum - bank_remittance_id)
        if diff >= PAYMENT_SUM_EPSILON:
            return u"Le montant du paiement doit correspondre à la somme \
des encaissements correspondant"

        return True

    return colander.Function(validate_sum_of_tvapayments)
Exemplo n.º 11
0
def deferred_amount_by_tva_validation(node, kw):
    invoice = kw['request'].context
    tva_parts = invoice.tva_ttc_parts()

    def validate_amount_by_tva(values):
        tva_id = values.get('tva_id')
        tva = Tva.get(tva_id)
        if tva is None:
            return u"Tva inconnue"
        amount = values.get('amount')
        # Fix #433 : encaissement et tva multiples
        # Add a tolerance for 5 € of difference
        if amount > tva_parts[tva.value] + PAYMENT_EPSILON:
            return u"Le montant de l'encaissement doit être inférieur à la \
part de cette Tva dans la facture"

        return True

    return colander.Function(validate_amount_by_tva)
Exemplo n.º 12
0
class TOSRevokeSchema(colander.Schema):
    typed_revoke = colander.SchemaNode(
        colander.String(),
        title=_("Type confirmation"),
        description=typed_revoke_description,
        validator=TypedRevokeValidator,
    )
    checked_revoke = colander.SchemaNode(
        colander.Bool(),
        title=_(
            "I understand the consequences and want to revoke my agreement."),
        validator=colander.Function(
            _return, _("Read above and tick here if you want to do this.")),
    )
    current_password = colander.SchemaNode(
        colander.String(),
        title=_("Password check due to severe consequences of revoking this"),
        widget=deform.widget.PasswordWidget(size=20),
        validator=deferred_current_password_validator,
    )

    def after_bind(self, schema, kw):
        request = kw["request"]
        view = kw["view"]
        tos = view.tos
        remove_fields = set()
        # If current user doesn't have a password, we can't really check against that
        if not request.profile.password:
            remove_fields.add("current_password")
        # Don't enforce fields on inactive TOS
        if tos.wf_state == "enabled":
            if not tos.check_password_on_revoke:
                remove_fields.add("current_password")
            if not tos.check_typed_on_revoke:
                remove_fields.add("typed_revoke")
        else:
            remove_fields.update(["current_password", "typed_revoke"])
        if "typed_revoke" not in remove_fields:
            remove_fields.add("checked_revoke")
        for k in remove_fields:
            if k in schema:
                del schema[k]
Exemplo n.º 13
0
def get_list_schema(is_global=False, excludes=()):
    """
    Return a schema for invoice listing

    is_global

        If True, customer select is only related to the current company
    """
    schema = forms.lists.BaseListsSchema().clone()

    if 'paid_status' not in excludes:
        schema.insert(
            0,
            colander.SchemaNode(
                colander.String(),
                name='paid_status',
                widget=deform.widget.SelectWidget(values=PAID_STATUS_OPTIONS),
                validator=colander.OneOf([s[0] for s in PAID_STATUS_OPTIONS]),
                missing='all',
                default='all',
            ))

    if 'status' not in excludes:
        schema.insert(
            0,
            colander.SchemaNode(
                colander.String(),
                name='status',
                widget=deform.widget.SelectWidget(values=STATUS_OPTIONS),
                validator=colander.OneOf([s[0] for s in STATUS_OPTIONS]),
                missing='all',
                default='all',
            ))

    schema.insert(
        0,
        colander.SchemaNode(
            colander.String(),
            name='doctype',
            widget=deform.widget.SelectWidget(values=TYPE_OPTIONS),
            validator=colander.OneOf([s[0] for s in TYPE_OPTIONS]),
            missing='both',
            default='both',
        ))

    if 'customer' not in excludes:
        schema.insert(
            0,
            customer_filter_node_factory(
                is_admin=is_global,
                name='customer_id',
            ))

    if 'company_id' not in excludes:
        schema.insert(0, company_filter_node_factory(name='company_id'))

    schema.insert(
        0,
        PeriodSchema(
            name='period',
            title="",
            validator=colander.Function(
                forms.range_validator,
                msg=u"La date de début doit précéder la date de début"),
            widget=CleanMappingWidget(),
            missing=colander.drop,
        ))
    schema.insert(
        0,
        AmountRangeSchema(
            name='ttc',
            title="",
            validator=colander.Function(
                forms.range_validator,
                msg=u"Le montant de départ doit être inférieur ou égale \
à celui de la fin"),
            widget=CleanMappingWidget(),
            missing=colander.drop,
        ))

    if 'year' not in excludes:

        def get_year_options(kw):
            values = invoice.get_invoice_years(kw)
            values.insert(0, u'')
            return values

        node = forms.year_select_node(name='year',
                                      query_func=get_year_options,
                                      missing=-1,
                                      description=u"Année fiscale")

        schema.insert(0, node)

    schema['search'].description = u"Identifiant du document"

    return schema
Exemplo n.º 14
0
def deferred_product_validator(node, kw):
    options = [option[0] for option in get_product_choices()]
    return colander.Function(_is_in(options))
Exemplo n.º 15
0
    """ Composite validator which succeeds if none of its
    subvalidators raises an :class:`colander.Invalid` exception"""
    def __init__(self, *validators):
        self.validators = validators

    def __call__(self, node, value):
        for validator in self.validators:
            validator(node, value)


FORBIDDEN = [
    'project', 'source', 'target', 'id', 'created_at', 'updated_at', 'author',
    'author_id'
]
database_format = colander.Regex(r'^[a-zA-Z][a-zA-Z0-9_-]+[a-zA-Z0-9]$')
database_forbidden = colander.Function(lambda t: t not in FORBIDDEN)
database_name = All(database_format, database_forbidden)


class FixedValue(object):
    def __init__(self, value):
        self.value = value

    def serialize(self, node, appstruct):
        return colander.null

    def deserialize(self, node, cstruct):
        return self.value

    def cstruct_children(self, node, cstruct):
        return []
Exemplo n.º 16
0
def get_list_schema(is_admin=False):
    """
    Return a schema for invoice listing

    is_admin

        If True, we don't provide the company selection node and we reduce the
        customers to the current company's
    """
    schema = forms.lists.BaseListsSchema().clone()

    schema.insert(
        0,
        colander.SchemaNode(
            colander.String(),
            name='status',
            widget=deform.widget.SelectWidget(values=STATUS_OPTIONS),
            validator=colander.OneOf([s[0] for s in STATUS_OPTIONS]),
            missing='both',
            default='both',
        ))

    schema.insert(
        0,
        colander.SchemaNode(
            colander.String(),
            name='doctype',
            widget=deform.widget.SelectWidget(values=TYPE_OPTIONS),
            validator=colander.OneOf([s[0] for s in TYPE_OPTIONS]),
            missing='both',
            default='both',
        ))

    schema.insert(0, company.customer_node(is_admin))

    if is_admin:
        schema.insert(
            0,
            company.company_node(
                name='company_id',
                missing=colander.drop,
                widget_options={'default': ('', u'Toutes les entreprises')},
            ))

    schema.insert(
        0,
        PeriodSchema(
            name='period',
            title="",
            validator=colander.Function(
                forms.range_validator,
                msg=u"La date de début doit précéder la date de début"),
            widget=CleanMappingWidget(),
            missing=colander.drop,
        ))
    schema.insert(
        0,
        AmountRangeSchema(
            name='ttc',
            title="",
            validator=colander.Function(
                forms.range_validator,
                msg=u"Le montant de départ doit être inférieur ou égale \
à celui de la fin"),
            widget=CleanMappingWidget(),
            missing=colander.drop,
        ))

    def get_year_options():
        values = invoice.get_invoice_years()
        values.insert(0, u'')
        return values

    node = forms.year_select_node(name='year',
                                  query_func=get_year_options,
                                  missing=-1,
                                  description=u"Année fiscale")

    schema.insert(0, node)

    schema['search'].description = u"Identifiant du document"

    return schema
Exemplo n.º 17
0
def get_list_schema(is_global=False):
    """
    Return the estimation list schema

    :param bool is_global: Should we include global search fields (CAE wide)
    :returns: The list schema
    :rtype: colander.SchemaNode
    """
    schema = forms.lists.BaseListsSchema().clone()

    del schema['search']

    schema.insert(0, company.customer_node(is_global))

    if is_global:
        schema.insert(
            0,
            company.company_node(
                name='company_id',
                missing=colander.drop,
                widget_options={'default': ('', u'Toutes les entreprises')}))

    schema.insert(
        0,
        PeriodSchema(
            name='period',
            title="",
            validator=colander.Function(
                forms.range_validator,
                msg=u"La date de début doit précéder la date de début"),
            widget=deform.widget.MappingWidget(template=TEMPLATES_URL +
                                               'clean_mapping.pt', ),
            missing=colander.drop,
        ))
    schema.insert(
        0,
        AmountRangeSchema(
            name='ttc',
            title="",
            validator=colander.Function(
                forms.range_validator,
                msg=u"Le montant de départ doit être inférieur ou égale \
à celui de la fin"),
            widget=deform.widget.MappingWidget(template=TEMPLATES_URL +
                                               'clean_mapping.pt', ),
            missing=colander.drop,
        ))

    schema.insert(
        0,
        colander.SchemaNode(
            colander.String(),
            name='status',
            widget=deform.widget.SelectWidget(values=STATUS_OPTIONS),
            validator=colander.OneOf([s[0] for s in STATUS_OPTIONS]),
            missing='all'))
    node = forms.year_select_node(
        name='year',
        query_func=get_invoice_years,
    )
    schema.insert(0, node)

    return schema