git ignore and minor webpush fix

This commit is contained in:
2021-04-01 16:20:17 +01:00
parent 49148320ee
commit 252ac0ef7b
7 changed files with 41 additions and 4 deletions

View File

@ -3,7 +3,7 @@ from django.views.decorators.http import require_GET
from django.http.response import JsonResponse, HttpResponse
from django.views.decorators.http import require_GET, require_POST
from django.shortcuts import render, get_object_or_404
from django.contrib.auth.models import User
from djangoldp_account.models import LDPUser
from django.views.decorators.csrf import csrf_exempt
from webpush import send_user_notification
from django.conf import settings
@ -27,10 +27,10 @@ def send_push(request):
return JsonResponse(status=400, data={"message": "Invalid data format"})
user_id = data['id']
user = get_object_or_404(User, pk=user_id)
user = get_object_or_404(LDPUser, pk=user_id)
payload = {'head': data['head'], 'body': data['body']}
send_user_notification(user=user, payload=payload, ttl=1000)
return JsonResponse(status=200, data={"message": "Web push successful"})
except TypeError:
return JsonResponse(status=500, data={"message": "An error occurred"})
return JsonResponse(status=500, data={"message": "An error occurred"})