Initial commit

This commit is contained in:
2024-08-27 20:33:44 +02:00
commit 1f1832267d
14794 changed files with 1599592 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
import json
from django.http import HttpResponseBadRequest, JsonResponse
from django.views import View
from wagtail.users.models import UserProfile
class DismissiblesView(View):
def get(self, request, *args, **kwargs):
# The UserProfile may not exist for the user, in which case return an empty object
profile = getattr(request.user, "wagtail_userprofile", None)
dismissibles = profile.dismissibles if profile else {}
return JsonResponse(dismissibles)
def patch(self, request, *args, **kwargs):
try:
updates = json.loads(request.body)
except json.JSONDecodeError:
return HttpResponseBadRequest()
# Make sure the UserProfile exists
profile = UserProfile.get_for_user(request.user)
profile.dismissibles.update(updates)
profile.save(update_fields=["dismissibles"])
return JsonResponse(profile.dismissibles)