parameters: (request)
return_statement: return JsonResponse(response, status=status)
docstring: Delete avatar image
docstring_summary: Delete avatar image
docstring_tokens: Delete avatar image
function: 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)
function_tokens: 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 )