Skip to main content

Orator Validator

Downloads

This is a orator plugin that you can use to validate your model when the user is creating a new item or updating one on the database is easy to use and cleans the code a lot

Installation

You can install the plugin by using pip

$ pip install orator-validator

How to use it

Setup

this is an example of how to implement on your orator model

from orator import Model
from orator_validator import Validator


class User(Model, Validator):

    __connection__ = 'local'
    __fillable__ = [
          'name', 'email', 'password', 'phone_number'
    ]
    __guarded__ = ['id', 'password']


class UserValidation(object):
  '''Here goes the validations that you need'''

User.observe(UserValidation())

Functions available

Validate saving function

the validate function accepts this params

  • require: boolean when True checks if they send the value

  • data_type: object Verifies if the value is specific data type

  • regex: string pass a regex to verified

  • date_str: string witch you want to check the format of the date example ‘%H:%M’

Example

def saving(self, user):
    user.validate('name', require=True, data_type=str)
    user.validate(
        'email', regex="(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])"
    )
    user.validate(
        'password', regex="^(?=.*[A-Za-z])(?=.*\\d)(?=.*[@$!%*#?&])[A-Za-z\\d@$!%*#?&]{6,}$"
    )
    user.errors()

Validate update function

the validate_update accepts this params

  • guarded: boolean if True value cannot be updated

  • data_tpe: needs to send specific data type

  • regex: regex to validate the value

  • date_str: string to validate a date format

  • function_callback: callback function if the value was send

  • args: arguments for the function callbacks

Example

def updating(self, user):
    user.validate_update('email', guarded=True)
    user.validate_update(
      'password', function_callback=self.__validate_new_password, user=user
    )
    user.errors()

def __validate_new_password(self, user):
    '''
    Validate that the new password is diferent than the old one
    '''
    User.find(user.id)
    if user.password == User.find(user.id).password:
      raise Exception("Can't update password with old one")

Process function

the process function accepts

  • exist: function uses as a callback if the value was send

  • not_exist: function uses as a callback if the value was not send

  • args: arguments for the function callbacks

Example

def saving(self, user):
    user.process('phone_number', exist=self.__process_phone)
    user.errors()

def __process_phone(self, user):
    '''
    This function process the phone if the user send one
    '''
    if user.phone[0] != "+":
      user.phone = "+1 {}".format(user.phone)

Metadata

Release files for orator-validator 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for orator-validator 0.4.1
File Size Uploaded Provenance Actions
orator_validator-0.4.1.tar.gz 4.4 kB Without provenance Details for orator_validator-0.4.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for orator-validator 0.4.1
File Interpreter ABI Platform Actions
orator_validator-0.4.1-py3-none-any.whl Python 3 none any Details for orator_validator-0.4.1-py3-none-any.whl

Total release size: 11.4 kB

Release files / orator_validator-0.4.1.tar.gz

Download URL orator_validator-0.4.1.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
a23b6832976f412919480c1222b8f40aec78b38decbb6458366802cbf4652cfb
BLAKE2b-256 checksum
How to use checksums
80049172ae408842989a16ed7ed04dfdfd09c53ea342383380a689dcf410a10d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.1

Release files / orator_validator-0.4.1-py3-none-any.whl

Download URL orator_validator-0.4.1-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4d09801f2d3f5552c60c8dbfc68d3bd4c01350906848aab0da55122cfd3b91f8
BLAKE2b-256 checksum
How to use checksums
556dbcd21475dae7314042e10ddcfff7e9e9aa9ec795224146957820518510e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.1

Security for orator-validator 0.4.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page