Пример #1
0
class UserSchema(ma.ModelSchema):
    name = fields.Str(required=True,
                      validate=[validate.Length(min=2, max=255)])
    surname = fields.Str(required=True,
                         validate=[validate.Length(min=2, max=255)])
    email = fields.Email(required=True)
    password = fields.Str(
        required=True,
        validate=[
            validate.Regexp(
                r"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d@$!%*?#&]{8,}$")
        ])
    password2 = fields.Str(
        required=True,
        validate=[
            validate.Regexp(
                r"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d@$!%*?#&]{8,}$")
        ])

    @validates_schema(skip_on_field_errors=True
                      )  #if there will be an error above, it won't go in here
    def hash_password(self, data, **kwargs):
        hashed_password = get_hash_password(data.get("password"))
        data.update({"password": hashed_password})
        data.update({"email": data.get("email").lower()})
        del data["password2"]

    class Meta:
        model = Users
Пример #2
0
class UserSchema(ma.ModelSchema):

    first_name = fields.Str(required=True,
                            validate=[validate.Length(min=2, max=250)])
    last_name = fields.Str(required=True,
                           validate=[validate.Length(min=2, max=250)])
    user_name = fields.Str(required=True,
                           validate=[validate.Length(min=2, max=250)])
    email = fields.Email(required=True)
    password = fields.Str(
        load_only=True,
        required=True,
        validate=[
            validate.Regexp(
                r"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d@$!%*?#&]{8,}$")
        ])

    @validates_schema(skip_on_field_errors=True)
    def hash_pass(self, data, **kwargs):
        hashed_pass = get_secret_hash(data.get("password"))
        data.update({"password": hashed_pass})

    class Meta:
        model = Users

    todos = fields.Nested('TodoSchema', many=True)
Пример #3
0
class TodoSchema(ma.ModelSchema):

    title = fields.Str(required=True,
                       validate=[validate.Length(min=2, max=250)])
    description = fields.Str(validate=[validate.Length(min=2, max=250)])

    class Meta:
        model = Todo
        include_fk = True
Пример #4
0
class UserUpdateFormSchema(ma.Schema):
    name = fields.Str(validate=[validate.Length(min=2, max=255)])
    surname = fields.Str(validate=[validate.Length(min=2, max=255)])
    email = fields.Email()
    password = fields.Str(validate=[validate.Length(min=3, max=123)])

    @validates_schema(skip_on_field_errors=True)
    def hash_password(self, data, **kwargs):
        hashed_password = get_hash_password(data.get("password"))
        data.update({"password": hashed_password})
Пример #5
0
class UserUpdateSchema(
        ma.Schema
):  #flask-nan integratsiya olunduguna gore flask_marshmallow modulunnan goturulur
    name = fields.Str(validate=[validate.Length(min=2, max=255)])
    surname = fields.Str(validate=[validate.Length(min=2, max=255)])
    email = fields.Email()
    password = fields.Str(validate=[
        validate.Regexp(
            r"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d@$!%*?#&]{8,}$")
    ])

    @validates_schema(skip_on_field_errors=True)
    def hash_password(self, data, **kwargs):
        hashed_password = get_hash_password(data.get("password"))
        data.update({"password": hashed_password})
Пример #6
0
class UpdateSchema(ma.Schema):

    first_name = fields.Str(validate=[validate.Length(min=2, max=250)])
    last_name = fields.Str(validate=[validate.Length(min=2, max=250)])
    user_name = fields.Str(validate=[validate.Length(min=2, max=250)])
    email = fields.Email()
    password = fields.Str(validate=[
        validate.Regexp(
            r"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d@$!%*?#&]{8,}$")
    ])

    @validates_schema(skip_on_field_errors=True)
    def hash_pass(self, data, **kwargs):
        if data.get("password"):
            hashed_pass = get_secret_hash(data.get("password"))
            data.update({"password": hashed_pass})
Пример #7
0
class TodoSchema(
        ma.ModelSchema
):  # db model is required here, flask-nan integratsiya olunduguna gore flask_marshmallow modulunnan goturulur
    date = fields.Date(
        required=True
    )  # by default is used ISO format. fields ise independent funksionalliq 9olduguna gore burda adi marshmallow-dan istifade edirik
    whattodo = fields.Str(
        required=True, validate=[validate.Length(min=2, max=255)]
    )  # validate is a list and several validations can be used, that's why [] brackets are used

    class Meta:
        model = ToDo
Пример #8
0
class TodoUpdateSchema(ma.Schema):

    title = fields.Str(validate=[validate.Length(min=2, max=250)])
    description = fields.Str(validate=[validate.Length(min=2, max=250)])
    user_id = fields.Int()
Пример #9
0
class ToDoUpdateSchema(
        ma.Schema
):  # this one only creates schema for validation and doesn't need db model
    date = fields.Date()
    whattodo = fields.Str(validate=[validate.Length(min=2, max=255)])