profiles: avatar_url becomes avatar
This commit is contained in:
@ -25,7 +25,7 @@ class ProfileViewSet(viewsets.ModelViewSet):
|
||||
if (not user):
|
||||
return Response({"detail": "Profile not found."}, status=status.HTTP_404_NOT_FOUND)
|
||||
instance = self.queryset().get(pk=user[0].pk)
|
||||
instance.avatar_url.name = instance.avatar_url.name[instance.avatar_url.name.find("static") - 1:]
|
||||
instance.avatar.name = instance.avatar.name[instance.avatar.name.find("static") - 1:]
|
||||
return Response(self.serializer_class(instance).data,
|
||||
status=status.HTTP_200_OK)
|
||||
|
||||
@ -34,14 +34,14 @@ class ProfileViewSet(viewsets.ModelViewSet):
|
||||
if (not user):
|
||||
return Response({"detail": "Profile not found."}, status=status.HTTP_404_NOT_FOUND)
|
||||
instance = self.queryset().get(pk=user[0].pk)
|
||||
instance.avatar_url.name = instance.avatar_url.name[instance.avatar_url.name.find("static") - 1:]
|
||||
instance.avatar.name = instance.avatar.name[instance.avatar.name.find("static") - 1:]
|
||||
return Response(self.serializer_class(instance).data,
|
||||
status=status.HTTP_200_OK)
|
||||
|
||||
def list(self, request: HttpRequest):
|
||||
serializer = ProfileSerializer(self.queryset(), many=True)
|
||||
for profile in serializer.data:
|
||||
profile["avatar_url"] = profile["avatar_url"][profile["avatar_url"].find("static") - 1:]
|
||||
profile["avatar"] = profile["avatar"][profile["avatar"].find("static") - 1:]
|
||||
return Response(serializer.data)
|
||||
|
||||
class MyProfileViewSet(viewsets.ModelViewSet):
|
||||
@ -59,13 +59,13 @@ class MyProfileViewSet(viewsets.ModelViewSet):
|
||||
profile: ProfileModel = self.get_object()
|
||||
avatar : InMemoryUploadedFile = self.request.data.get("file", None)
|
||||
if (avatar is not None and avatar.size <= settings.PROFILE_PICTURE_MAX_SIZE):
|
||||
if (profile.avatar_url.name != "./profiles/static/avatars/default.avif"):
|
||||
profile.avatar_url.storage.delete(profile.avatar_url.name)
|
||||
profile.avatar_url = avatar
|
||||
if (profile.avatar.name != "./profiles/static/avatars/default.avif"):
|
||||
profile.avatar.storage.delete(profile.avatar.name)
|
||||
profile.avatar = avatar
|
||||
profile.save()
|
||||
|
||||
def retrieve(self, request: HttpRequest, pk=None):
|
||||
instance: ProfileModel = self.get_object()
|
||||
instance.avatar_url.name = instance.avatar_url.name[instance.avatar_url.name.find("static") - 1:]
|
||||
instance.avatar.name = instance.avatar.name[instance.avatar.name.find("static") - 1:]
|
||||
return Response(self.serializer_class(instance).data,
|
||||
status=status.HTTP_200_OK)
|
||||
|
Reference in New Issue
Block a user