Пример #1
0
    def authenticate_credentials(self, userid, password):
        """
        Authenticate the userid and password against username and password.
        """
        user = User.objects.authenticate_user(userid, password)
        if user is not None:
            return (user, None)

        raise exceptions.AuthenticationFailed(error_messages.get("invalid_user_or_pass"))
Пример #2
0
    def authenticate_credentials(self, userid, password):
        """
        Authenticate the userid and password against username and password.
        """
        user = User.objects.authenticate_user(userid, password)
        if user is not None:
            return (user, None)

        raise exceptions.AuthenticationFailed(
            error_messages.get("invalid_user_or_pass"))
Пример #3
0
def get_by_id(request, id_supply):
 
    try:
        supply = Supply.objects.get_by_id_and_user(id_supply, request.user)
         
        return response_commit(model_to_dict(supply))
     
    except ObjectDoesNotExist, e:
        logger.error(e)
        return ServiceExceptionSerializer.response_exception(error_messages.get("invalid") % u"Abastecimento")
Пример #4
0
def get_by_id(request, id_supply):

    try:
        supply = Supply.objects.get_by_id_and_user(id_supply, request.user)

        return response_commit(model_to_dict(supply))

    except ObjectDoesNotExist, e:
        logger.error(e)
        return ServiceExceptionSerializer.response_exception(
            error_messages.get("invalid") % u"Abastecimento")
Пример #5
0
def get_by_id(request, id_car):

    try:
        vehicle = Vehicle.objects.get_vehicle_by_id_and_user(id_car, request.user)
        
        return response_commit({"id": vehicle.pk, 
                                "model": vehicle.model.name, 
                                "motor": vehicle.motor,
                                "manufactured": vehicle.manufactured})
    
    except ObjectDoesNotExist, e:
        logger.error(e)
        return ServiceExceptionSerializer.response_exception(error_messages.get("invalid") % u"Veículo")
Пример #6
0
def delete(request, id_user):

    try:

        # Valid ID
        try:
            is_valid_int_greater_zero_param(id_user)
        except ValidationError, e:
            return ValidationExceptionSerializer.response_exception({"id_user": e.messages})

        # Find User by ID to check if it exist
        try:
            user = User.objects.get_by_pk(id_user)
        except ObjectDoesNotExist, e:
            return ServiceExceptionSerializer.response_exception(error_messages.get("invalid") % "Usuário")
Пример #7
0
def get_by_id(request, id_car):

    try:
        vehicle = Vehicle.objects.get_vehicle_by_id_and_user(
            id_car, request.user)

        return response_commit({
            "id": vehicle.pk,
            "model": vehicle.model.name,
            "motor": vehicle.motor,
            "manufactured": vehicle.manufactured
        })

    except ObjectDoesNotExist, e:
        logger.error(e)
        return ServiceExceptionSerializer.response_exception(
            error_messages.get("invalid") % u"Veículo")
Пример #8
0
def update(request):

    try:

        vehicle = Vehicle.objects.get_by_pk(request.DATA.get('car_id'))

        serializer = SaveSerializer(clone(vehicle), data=request.DATA)

        if serializer.is_valid():

            vehicle = serializer.object
            vehicle.save()

            return response_commit(model_to_dict(vehicle))

        else:
            return ValidationExceptionSerializer.response_exception(serializer.errors)

    except ObjectDoesNotExist, e:
        logger.error(e)
        return ServiceExceptionSerializer.response_exception(error_messages.get("invalid") % u"Veículo")
Пример #9
0
def update(request):

    try:

        user = User.objects.get_by_pk(request.user.id)

        serializer = UpdateSerializer(clone(user), data=request.DATA)

        if serializer.is_valid():

            user = serializer.object
            user.save()

            return response_commit({"user": model_to_dict(user, exclude=["password", "token"])})

        else:
            return ValidationExceptionSerializer.response_exception(serializer.errors)

    except ObjectDoesNotExist, e:
        logger.error(e)
        return ServiceExceptionSerializer.response_exception(error_messages.get("invalid") % "Usuário")
Пример #10
0
def update(request):

    try:

        vehicle = Vehicle.objects.get_by_pk(request.DATA.get('car_id'))

        serializer = SaveSerializer(clone(vehicle), data=request.DATA)

        if serializer.is_valid():

            vehicle = serializer.object
            vehicle.save()

            return response_commit(model_to_dict(vehicle))

        else:
            return ValidationExceptionSerializer.response_exception(
                serializer.errors)

    except ObjectDoesNotExist, e:
        logger.error(e)
        return ServiceExceptionSerializer.response_exception(
            error_messages.get("invalid") % u"Veículo")
Пример #11
0
@renderer_classes(Renderer)
def get_by_username(request, username):

    try:

        # Valid Username
        validate_required(username)
        # Find User by username to check if it exist
        user = User.objects.get_by_username(username)

        return response_commit({"user": model_to_dict(user, exclude=["password", "token"])})

    except ValidationError, e:
        return ValidationExceptionSerializer.response_exception({"username": e.messages})
    except ObjectDoesNotExist, e:
        return ObjectDoesNotExistExceptionSerializer.response_exception(error_messages.get("invalid") % "Usuário")    
    except Exception, e:
        logger.error(e)
        return ServiceExceptionSerializer.response_exception(error_messages.get("default_error"))