Skip to main content

Python3 Validation in another way

Project description

SmileValidation

smilevalidator

Python3 Validation in another way

I hurt enough for validating those form's elements. Time to bring a new technique type. It's gonna solve like this way:

Validator class

That's core class of the tool. It contains the validation element after added element into collect and it will valid the element by called isValid()

from Validator import Validator

# validition instance
v	= Validator()

## float validation
# add element with  
v.addElement(
    elementName= 'computer-quantity'
    , elementValue= 2
    , rule= TypeSchema().getFloat(
			require= True
			, max= 5
			, min= 1
			, negative= False
		)
)

## start validating
# true if every element is correct
if v.isValid():
    print(f'Everything is fine')
else:
    print(f'Error: {v.getError()}')

Rule class

It is the collection of what we wanna validate to those element objects. What Rule will help validation class is, make it all reusable.

Example:

# sample
class Rule:

    def getQuantityOne(self) -> dict:
        """

        :return:
        """
        return TypeSchema().getFloat(
                require= True
                , max= 5
                , min= 1
                , negative= False
        )

getQualityOne will replace previous one.

# sample with two elements
from Validator import Validator

# validition instance
v	= Validator()

## float validation
# add element with  
v.addElement(
    elementName= 'computer-quantity'
    , elementValue= 2
    , rule= Rule.getQuantityOne()
)

v.addElement(
    elementName= 'tv-quantity'
    , elementValue= 4
    , rule= Rule.getQuantityOne()
)

## start validating
# true if every element is correct
if v.isValid():
    print(f'Everything is fine')
else:
    print(f'Error: {v.getError()}')

It is available on PyPi store via https://pypi.org/project/SmileValidation/
To Support my work, please donate me via Buy me a PizzaBuy me a Coffee

My unique slogan is:

a little developer in the big world \o/

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

SmileValidation-1.1.1.tar.gz (9.4 kB view hashes)

Uploaded Source

Built Distribution

SmileValidation-1.1.1-py3-none-any.whl (19.8 kB view hashes)

Uploaded 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