Clean up docker-compose and run Black formatter over entire codebase

This commit is contained in:
Keannu Christian Bernasol 2024-10-30 22:09:58 +08:00
parent 6c232b3e89
commit 069aba80b1
60 changed files with 1946 additions and 1485 deletions

View file

@ -6,30 +6,33 @@ from django.core.cache import cache
class NotificationViewSet(viewsets.ModelViewSet):
http_method_names = ['get', 'patch', 'delete']
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}'
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)
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.")
"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.")
"You do not have permission to delete this notification."
)
return super().destroy(request, *args, **kwargs)