Validators for fields in Flask-Restless
Project description
OSIRIS VALIDATOR
Osiris Validator is a set of decorators for validation in Flask-restless and SQLAlchemy
(Readme is under construction...)
Getting Started
Installing
pip install osirisvalidator
Usage
The parameter validation_exceptions in APIManager.create_api() from Flask-restless must be set to use osiris' ValidationException.
from osirisvalidator.exceptions import ValidationException
[...]
manager = APIManager(app, flask_sqlalchemy_db=db)
manager.create_api(User, validation_exceptions=[ValidationException], methods=['GET', 'POST'])
To use the decorators, the validates() decorator from SQLAlchemy must be used before, and the pattern must be followed.
See about in: https://flask-restless.readthedocs.io/en/stable/customizing.html#capturing-validation-errors
The parameter "field" is required and you can set a custom message.
from sqlalchemy.orm import validates
from osirisvalidator.string import *
from osirisvalidator.internet import valid_email
class Usuario(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(200), nullable=False)
email = db.Column(db.String(60), nullable=False)
@validates('name')
@not_blank(field='name', message='Custom message')
@is_alpha_space(field='name')
@string_len(field='name', min=3, max=100)
def validate_name(self, key, name):
return name
@validates('email')
@not_blank(field='email')
@valid_email(field='email')
def validate_email(self, key, email):
return email
List of validators
osirisvalidator.string
- not_empty
- not_blank
- is_alpha
- is_alpha_space (alpha characters and space)
- is_alnum
- is_alnum_space (alphanumeric characters and space)
- is_digit
- string_len (mandatory parameters: min and max)
- match_regex (mandatory parameter: regex)
osirisvalidator.number
- min_max (mandatory parameters: min and max)
osirisvalidator.internet
- valid_email
osiris.intl.br
- valid_cpf
- valid_cnpj
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
osirisvalidator-0.1.0.tar.gz
(18.4 kB
view hashes)
Built Distribution
Close
Hashes for osirisvalidator-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 609ee2fc924877efca53746316411fa35e72eb0ab940b0faebef318c8696699d |
|
MD5 | 8a0e550e65c6a8eb40ba2ac94b17ef55 |
|
BLAKE2b-256 | 5650e06c3a5867080a882fe55cabb7805ef70c64784587e6d245421cce460c82 |