mirror of
https://github.com/lemeow125/DRF_Template.git
synced 2025-08-03 01:33:15 +08:00
Clean up docker-compose and run Black formatter over entire codebase
This commit is contained in:
parent
6c232b3e89
commit
069aba80b1
60 changed files with 1946 additions and 1485 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue