mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-31 02:21:35 +00:00
Bug fix for ghost avatar images after user deletion
This commit is contained in:
parent
87fdaffa24
commit
e06be9b22f
25
api/views.py
25
api/views.py
@ -17,6 +17,9 @@ from pathlib import Path
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
|
avatar_path = Path('frontend/static/assets/avatars')
|
||||||
|
avatar_path.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
class MakeOrder(APIView):
|
class MakeOrder(APIView):
|
||||||
@ -140,11 +143,8 @@ class UserGenerator(APIView):
|
|||||||
# generate avatar
|
# generate avatar
|
||||||
rh = Robohash(hash)
|
rh = Robohash(hash)
|
||||||
rh.assemble(roboset='set1') # bgset='any' for backgrounds ON
|
rh.assemble(roboset='set1') # bgset='any' for backgrounds ON
|
||||||
|
|
||||||
avatars_path = Path('frontend/static/assets/avatars')
|
|
||||||
avatars_path.mkdir(parents=True, exist_ok=True)
|
|
||||||
|
|
||||||
with open(avatars_path.joinpath(nickname+".png"), "wb") as f:
|
with open(avatar_path.joinpath(nickname+".png"), "wb") as f:
|
||||||
rh.img.save(f, format="png")
|
rh.img.save(f, format="png")
|
||||||
|
|
||||||
# Create new credentials if nickname is new
|
# Create new credentials if nickname is new
|
||||||
@ -178,9 +178,12 @@ class UserGenerator(APIView):
|
|||||||
# Only delete if user live is < 5 minutes
|
# Only delete if user live is < 5 minutes
|
||||||
|
|
||||||
if user is not None:
|
if user is not None:
|
||||||
|
avatar_file = avatar_path.joinpath(str(request.user)+".png")
|
||||||
|
avatar_file.unlink() # Unsafe if avatar does not exist.
|
||||||
logout(request)
|
logout(request)
|
||||||
user.delete()
|
user.delete()
|
||||||
return Response(status=status.HTTP_301_MOVED_PERMANENTLY)
|
|
||||||
|
return Response({'user_deleted':'User deleted permanently'},status=status.HTTP_301_MOVED_PERMANENTLY)
|
||||||
|
|
||||||
return Response(status=status.HTTP_403_FORBIDDEN)
|
return Response(status=status.HTTP_403_FORBIDDEN)
|
||||||
|
|
||||||
@ -188,14 +191,14 @@ class BookView(APIView):
|
|||||||
serializer_class = OrderSerializer
|
serializer_class = OrderSerializer
|
||||||
|
|
||||||
def get(self,request, format=None):
|
def get(self,request, format=None):
|
||||||
currency = request.GET.get('currency_code')
|
currency = request.GET.get('currency')
|
||||||
type = request.GET.get('order_type')
|
type = request.GET.get('type')
|
||||||
queryset = Order.objects.filter(currency=currency, type=type)
|
queryset = Order.objects.filter(currency=currency, type=type)
|
||||||
if len(queryset)== 0:
|
if len(queryset)== 0:
|
||||||
return Response({'not_found':'No orders found, be the first to make one.'}, status=status.HTTP_404_NOT_FOUND)
|
return Response({'not_found':'No orders found, be the first to make one'}, status=status.HTTP_404_NOT_FOUND)
|
||||||
|
|
||||||
book_data = {}
|
book_data = []
|
||||||
for i, order in enumerate(queryset):
|
for order in queryset:
|
||||||
data = OrderSerializer(order).data
|
data = OrderSerializer(order).data
|
||||||
user = User.objects.filter(id=data['maker'])
|
user = User.objects.filter(id=data['maker'])
|
||||||
print(user)
|
print(user)
|
||||||
@ -203,7 +206,7 @@ class BookView(APIView):
|
|||||||
data['maker_nick'] = user[0].username
|
data['maker_nick'] = user[0].username
|
||||||
# TODO avoid sending status and takers for book views
|
# TODO avoid sending status and takers for book views
|
||||||
#data.pop('status','taker')
|
#data.pop('status','taker')
|
||||||
book_data[i] = data
|
book_data.append(data)
|
||||||
|
|
||||||
return Response(book_data, status=status.HTTP_200_OK)
|
return Response(book_data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user