Skip to main content

Validators to be used as mixins in models

Project description

https://img.shields.io/pypi/v/styler_validation.svg https://github.com/STYLER-Inc/styler-validation/workflows/Python%20package/badge.svg

Validators to be used as mixins in models

  • Free software: MIT license

Usage

Install from pypi:

pip install styler-validation

Set validation rules for a class

from styler_validation import ValidatorMixin
from styler_validation import validators as va


class User(ValidatorMixin):
    validates = [
        ('name', va.is_required()),
        ('age', va.is_required(), va.is_integer())
    ]

my_user = User()
result, errors = my_user.is_valid()

print(result)   # False
print(errors)   # {'user.name': ('required_value',), 'user.age': ('required_value',)}

my_user.name = 'John Doe'
my_user.age = 'nine'
result, errors = my_user.is_valid()

print(result)   # False
print(errors)   # {'user.age': ('invalid_value',)}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

styler_validation-1.0.0.tar.gz (7.1 kB view hashes)

Uploaded Source

Built Distribution

styler_validation-1.0.0-py2.py3-none-any.whl (5.3 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page