Overhauled entire project config, added notifications, email templates, optimized stripe subscriptions, redis caching, and webdriver utilities

This commit is contained in:
Keannu Christian Bernasol 2024-05-10 23:15:29 +08:00
parent 7cbe8fd720
commit 99dfcef67b
84 changed files with 4300 additions and 867 deletions

View file

@ -0,0 +1,35 @@
from rest_framework import viewsets
from notifications.models import Notification
from notifications.serializers import NotificationSerializer
from rest_framework.exceptions import PermissionDenied
from django.core.cache import cache
class NotificationViewSet(viewsets.ModelViewSet):
http_method_names = ['get', 'patch', 'delete']
serializer_class = NotificationSerializer
queryset = Notification.objects.all()
def get_queryset(self):
user = self.request.user
key = f'notifications_user:{user.id}'
queryset = cache.get(key)
if not queryset:
queryset = Notification.objects.filter(
recipient=user).order_by('-timestamp')
cache.set(key, queryset, 60*60)
return queryset
def update(self, request, *args, **kwargs):
instance = self.get_object()
if instance.recipient != request.user:
raise PermissionDenied(
"You do not have permission to update this notification.")
return super().update(request, *args, **kwargs)
def destroy(self, request, *args, **kwargs):
instance = self.get_object()
if instance.recipient != request.user:
raise PermissionDenied(
"You do not have permission to delete this notification.")
return super().destroy(request, *args, **kwargs)