first commit

This commit is contained in:
Beyhan Oğur
2026-04-26 22:27:56 +03:00
commit d9f1ea341e
1021 changed files with 70645 additions and 0 deletions

76
settings/views.py Normal file
View File

@@ -0,0 +1,76 @@
from django.core.cache import cache
from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView
from core.Permission import ReadOnly
from settings.models import Setting, SiteSettings, Banner
from settings.serializers import SettingSerializer, SettingOpenCloseSerializer, BannerSerializer
CACHE_TTL_SECONDS = 60 * 5
# Create your views here.
class SettingDetailView(APIView):
permission_classes = [ReadOnly]
def get(self, request):
try:
cache_key = 'settings:detail'
cached_data = cache.get(cache_key)
if cached_data:
return Response(cached_data)
# İlk kaydı getir (veya istediğin koşula göre)
setting = Setting.objects.filter(is_active=True).first()
if setting:
serializer = SettingSerializer(setting)
cache.set(cache_key, serializer.data, timeout=CACHE_TTL_SECONDS)
return Response(serializer.data)
else:
return Response({"error": "No settings found"}, status=status.HTTP_404_NOT_FOUND)
except Exception as e:
return Response({"error": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
class SettingOpenCloseDetailView(APIView):
permission_classes = [ReadOnly]
def get(self, request):
try:
cache_key = 'settings:site_status'
cached_data = cache.get(cache_key)
if cached_data:
return Response(cached_data)
# İlk kaydı getir (veya istediğin koşula göre)
setting = SiteSettings.objects.filter(is_active=True).first()
if setting:
serializer = SettingOpenCloseSerializer(setting)
cache.set(cache_key, serializer.data, timeout=CACHE_TTL_SECONDS)
return Response(serializer.data)
else:
return Response({"error": "No settings found"}, status=status.HTTP_404_NOT_FOUND)
except Exception as e:
return Response({"error": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
class BannerDetailView(APIView):
permission_classes = [ReadOnly]
def get(self, request):
try:
cache_key = 'settings:banner'
cached_data = cache.get(cache_key)
if cached_data:
return Response(cached_data)
banner = Banner.objects.filter(is_active=True).first()
if banner:
serializer = BannerSerializer(banner)
cache.set(cache_key, serializer.data, timeout=CACHE_TTL_SECONDS)
return Response(serializer.data)
else:
return Response({"error": "No active banner found"}, status=status.HTTP_404_NOT_FOUND)
except Exception as e:
return Response({"error": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)