(request)
return JsonResponse(response, status=status)
Delete avatar image
Delete avatar image
Delete avatar image
def delete_avatar(request):
    """
    Delete avatar image
    """
    response = {}
    status = 405
    avatar, avatars = avatarviews._get_avatars(request.user)
    if avatar is None:
        response["error"] = "User has no avatar"
    else:
        aid = avatar.id
        for a in avatars:
            if a.id == aid:
                a.primary = True
                a.save()
                avatar_updated.send(
                    sender=Avatar, user=request.user, avatar=avatar
                )
                break
        Avatar.objects.filter(pk=aid).delete()
        response["avatar"] = request.user.avatar_url["url"]
        status = 200
    return JsonResponse(response, status=status)
def delete_avatar ( request ) : response = { } status = 405 avatar , avatars = avatarviews . _get_avatars ( request . user ) if avatar is None : response [ "error" ] = "User has no avatar" else : aid = avatar . id for a in avatars : if a . id == aid : a . primary = True a . save ( ) avatar_updated . send ( sender = Avatar , user = request . user , avatar = avatar ) break Avatar . objects . filter ( pk = aid ) . delete ( ) response [ "avatar" ] = request . user . avatar_url [ "url" ] status = 200 return JsonResponse ( response , status = status )