Exemple #1
0
class ProfileSelectionApiSchema(base_schema.Schema):
    id = fields.String(required=False)
    user_id = fields.Integer(required=False)
    phone_number = fields.String(required=False)
    followed = fields.List(fields.Integer(), required=False)
    increase_follow = fields.Boolean(required=False)
    follower_change = fields.Boolean(required=False)
Exemple #2
0
class LoginSchema(base_schema.Schema):
    username_or_email = fields.String(required=True)
    password = fields.String(required=True)

    @pre_load
    def check_login_details(self, data):
        if 'username_or_email' not in data:
            raise exceptions.MissingDataException(
                "Email or Username is required to login")
        query = Q(email=data['username_or_email']) | Q(
            username=data['username_or_email'])
        if not User.objects.filter(query).exists():
            raise exceptions.DataNotFoundException("Such user doesnot exist")
        else:
            username = User.objects.filter(query).first().username
            user = authenticate(username=username, password=data['password'])
            if not user:
                raise exceptions.DataNotFoundException("Invalid Credentials")
            self.user = user
        return data

    @post_load
    def get_user(self, data):
        data['user'] = self.user
        return data
Exemple #3
0
class TruckSchema(base_schema.Schema):

    locationid = fields.Integer(required=False)
    applicant = fields.String(required=True)
    facilitytype = fields.Integer(required=False, default=1)
    status = fields.Integer(required=False)
    cnn = fields.Integer(required=False)
    latitude = fields.Float(required=False)
    longitude = fields.Float(required=False)
    full_address = fields.String(required=False)
    address = fields.String(required=False)
    permit = fields.String(required=False)
    busy = fields.Boolean(required=False, default=False)
    approved = fields.DateTime(required=False, format='%m/%d/%Y')
    expiration = fields.DateTime(required=False, format='%m/%d/%Y')
Exemple #4
0
class LogoutSchema(base_schema.Schema):
    username = fields.String(required=True)

    @pre_load
    def check_username(self, data):
        if not User.objects.filter(username=data['username']).exists():
            raise exceptions.DataNotFoundException("Invalid User")
Exemple #5
0
class TweetSchema(base_schema.Schema):

    id = fields.Integer(required=False)
    title = fields.String(required=False)  # validators should be a list
    msg = fields.String(required=False)
    like = fields.Integer(required=False)
    people_id = fields.Integer(required=True)
    created = fields.Date(required=False)

    @pre_load
    def check_msg(self, data):
        if 'msg' not in data and self.context['method'] == 'POST':
            raise exceptions.WrongDataException("tweet content is missing")
        if 'msg' in data and len(data['msg']) > 140:
            raise exceptions.WrongDataException(
                "tweet is exceeding 140 characters.")
        if not People.objects.filter(id=data['people_id']).exists():
            raise exceptions.DataNotFoundException("No such user exists")
Exemple #6
0
class PeopleSchema(base_schema.Schema):
    id = fields.String(required=False)
    user = fields.Nested(UserSchema, attribute='user')
    phone_number = fields.String(required=False)
    birth_date = fields.Date(required=False)
    followed = fields.List(fields.Integer(), required=False)

    @pre_load
    def check_email(self, data):
        if 'email' not in data['user']:
            raise exceptions.WrongDataException("Email id is must")
        if User.objects.filter(email=data['user']['email']).exists():
            raise exceptions.DuplicateDataException(
                "Email already taken. Try something else")
        return data

    @post_load
    def get_user(self, data):
        data['user'] = data['user']['user_obj']
        return data
Exemple #7
0
class UserSchema(base_schema.Schema):
    username = fields.String(required=True)
    first_name = fields.String(required=False)
    last_name = fields.String(required=False)
    email = fields.String(required=True)
    password = fields.String(required=True)

    @validates_schema
    def validates_payload_data(self, data):
        if User.objects.filter(username=data['username']).exists():
            raise exceptions.DuplicateDataException(
                "Username already taken. Try something else")
        data['user_obj'] = User.objects.create_user(
            username=data['username'],
            password=data['password'],
            email=data.get('email', ''),
            first_name=data.get('first_name', data['username']),
            last_name=data.get('last_name', ''))
        return data

    @post_dump
    def remove_password(self, data):
        data.pop('password', None)
        return data
Exemple #8
0
class ApplicantSchema(base_schema.Schema):

    name = fields.String(required=True)
Exemple #9
0
class StreetSchema(base_schema.Schema):

    street = fields.String(required=True)