kwork-poizonstore/core/views.py
phzhik bad6bfb4c0 * Updated field naming in some serializers
* Admin tweaks
* Settings editing only for admin
2024-05-30 21:02:07 +04:00

21 lines
687 B
Python

from rest_framework import generics
from account.permissions import ReadOnly, IsAdmin
from core.models import GlobalSettings
from core.serializers import GlobalSettingsSerializer, AnonymousGlobalSettingsSerializer
class GlobalSettingsAPI(generics.RetrieveUpdateAPIView):
serializer_class = GlobalSettingsSerializer
permission_classes = [IsAdmin | ReadOnly]
def get_serializer_class(self):
if getattr(self.request.user, 'is_manager', False):
return GlobalSettingsSerializer
# Anonymous users can view only a certain set of fields
return AnonymousGlobalSettingsSerializer
def get_object(self):
return GlobalSettings.load()