Beispiel #1
0
 def get_image_profile(self, request, pk=None, id_image=None):
     instance = self.get_object()
     service = accounts_services.ProfileUser()
     try:
         images_profile = service.list_image_profile(instance)
     except Exception as e:
         return Response(json.loads(str(e)), status=status.HTTP_400_BAD_REQUEST)
     serializer = accounts_serializers.ImageSerializer(images_profile, many=True).data
     return Response(serializer, status=status.HTTP_200_OK)
Beispiel #2
0
 def update_distance(self, request, pk=None):
     instance = self.get_object()
     service = accounts_services.ProfileUser()
     try:
         user = service.update_distance(instance, request.data)
     except Exception as e:
         return Response({"detail": json.loads(str(e).replace("'", '"'))}, status=status.HTTP_400_BAD_REQUEST)
     return Response({"detail": str(_("You have edited the user search distance")), "distance": user.distance},
                     status=status.HTTP_200_OK)
Beispiel #3
0
 def delete_image(self, request, pk=None, id_image=None):
     instance = request.user
     service = accounts_services.ProfileUser()
     try:
         user = service.delete_images(instance, id_image)
     except Exception as e:
         return Response(json.loads(str(e)), status=status.HTTP_400_BAD_REQUEST)
     serializer = self.get_serializer(user, many=False).data
     serializer['detail'] = str(_("You have successfully deleted an image of your profile"))
     return Response(serializer, status=status.HTTP_200_OK)
Beispiel #4
0
 def assign_image(self, request, pk=None, id_image=None):
     instance = self.get_object()
     service = accounts_services.ProfileUser()
     try:
         profile = service.assing_image_profile(instance, id_image)
     except Exception as e:
         return Response(json.loads(str(e)), status=status.HTTP_400_BAD_REQUEST)
     serializer = self.get_serializer(profile, many=False).data
     serializer['detail'] = str(_("Your profile image has been successfully changed"))
     return Response(serializer, status=status.HTTP_200_OK)
Beispiel #5
0
 def list(self, request, *args, **kwargs):
     service = accounts_services.ProfileUser()
     try:
         profile = service.list(request.user)
     except Exception as e:
         return Response(json.loads(str(e)), status=status.HTTP_400_BAD_REQUEST)
     if len(profile) != 1:
         serializer = self.get_serializer(profile, many=True)    
     serializer = self.get_serializer(profile[0], many=False)
     return Response(serializer.data, status=status.HTTP_200_OK)
Beispiel #6
0
 def update(self, request, *args, **kwargs):
     partial = kwargs.pop('partial', False)
     instance = self.get_object()
     service = accounts_services.ProfileUser()
     try:
         profile = service.update(instance, request.data)
     except Exception as e:
         return Response({"detail": json.loads(str(e).replace("'", '"'))}, status=status.HTTP_400_BAD_REQUEST)
     serializer = self.get_serializer(profile, many=False).data
     serializer['detail'] = str(_("Your personal information has been successfully edited"))
     return Response(serializer, status=status.HTTP_200_OK)
Beispiel #7
0
 def change_password(self, request, pk=None):
     instance = request.user
     service = accounts_services.ProfileUser()
     try:
         profile = service.change_password(instance, request.data)
     except Exception as e:
         return Response(json.loads(str(e)), status=status.HTTP_400_BAD_REQUEST)
     profile.auth_token.delete()
     token, created = Token.objects.get_or_create(user=profile)
     return Response({'detail': str(_("The password has been successfully changed")),
                      'token': token.key,
                      'id': profile.id,
                      'username': profile.username, 
                      'last_login': profile.last_login}, status=status.HTTP_200_OK)