MasoniteFramework / masonite

The Modern And Developer Centric Python Web Framework. Be sure to read the documentation and join the Discord channel for questions: https://discord.gg/TwKeFahmPZ
http://docs.masoniteproject.com
MIT License
2.21k stars 126 forks source link

Autoload validation classes from Validator #767

Closed eaguad1337 closed 11 months ago

eaguad1337 commented 1 year ago

In docs, you could see something like this:

from masonite.validation import Validator
from masonite.validation import required, accepted
from masonite.request import Request
from masonite.response import Response

def show(self, request: Request, response: Response, validate: Validator):
    """
    Incoming Input: {
        'user': 'username123',
        'email': 'user@example.com',
        'terms': 'on'
    }
    """
    errors = request.validate(
        validate.required(['user', 'email']),
        validate.accepted('terms')
    )

    if errors:
        return response.back().with_errors(errors)

Specifically, this two lines will raise an error, because required and accepted are not attributes of Validator class. Instead, you should import the class from masonite.validation, but, in order to make it work more naturally, I propose this fix to make it work.

validate.required(['user', 'email']),
validate.accepted('terms')