From 151cd89b8897ae65fe015e26f8f8dc95741b5542 Mon Sep 17 00:00:00 2001 From: Irwan Cahyono Date: Sat, 28 Jun 2025 21:38:44 +0700 Subject: [PATCH] debug toolbar dan environment --- freekake_api/content/models.py | 29 ++++++++++++++------------- freekake_api/content/views.py | 6 +++--- freekake_api/freekake_api/settings.py | 24 ++++++++++++++-------- freekake_api/freekake_api/urls.py | 3 ++- 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/freekake_api/content/models.py b/freekake_api/content/models.py index 7e6acef..baea7e1 100644 --- a/freekake_api/content/models.py +++ b/freekake_api/content/models.py @@ -30,19 +30,20 @@ class ContentTopic(SoftDeleteModel): class Content(SoftDeleteModel): - class ContentFormat(models.TextChoices): - TEXT = 'Text', 'Teks' - INFOGRAPHIC = 'Infographic', 'Infografis' - IMAGE = 'Image', 'Gambar' - VIDEO = 'Video', 'Video' - BRANCHING_SCENARIO = 'Branching Scenario', 'Pilihan Bercabang' - CROSSWORD = 'Crossword', 'Teka-teki Silang' - DRAG_AND_DROP = 'Drag And Drop', 'Pencocokan' - FIND_THE_WORDS = 'Find the Words', 'Cari Kata' - MEMORY_GAME = 'Memory Game', 'Permainan Memori' - PERSONALITY_QUIZ = 'Personality Quiz', 'Permainan Tebak Sifat' - GAME_MAP = 'Game Map', 'Peta Permainan' - MULTIPLE_CHOICE = 'Multiple Choice', 'Pilihan Ganda' + CONTENT_FORMAT_CHOICES = [ + ('Text', 'Teks'), + ('Infographic', 'Infografis'), + ('Image', 'Gambar'), + ('Video', 'Video'), + ('Branching Scenario', 'Pilihan Bercabang'), + ('Crossword', 'Teka-teki Silang'), + ('Drag And Drop', 'Pencocokan'), + ('Find the Words', 'Cari Kata'), + ('Memory Game', 'Permainan Memori'), + ('Personality Quiz', 'Permainan Tebak Sifat'), + ('Game Map', 'Peta Permainan'), + ('Multiple Choice', 'Pilihan Ganda'), + ] title = models.CharField(max_length=255, null=False) slug = models.SlugField(max_length=255) @@ -51,7 +52,7 @@ class Content(SoftDeleteModel): theme = models.ForeignKey(ContentTheme, on_delete=models.CASCADE, null=False) topic = models.ForeignKey(ContentTopic, on_delete=models.CASCADE, null=False) - format = models.CharField(max_length=25, choices=ContentFormat.choices, default=ContentFormat.TEXT) + format = models.CharField(max_length=25, choices=CONTENT_FORMAT_CHOICES) content = models.TextField(null=True) data = models.JSONField(null=True) diff --git a/freekake_api/content/views.py b/freekake_api/content/views.py index c40df0d..0992463 100644 --- a/freekake_api/content/views.py +++ b/freekake_api/content/views.py @@ -1,5 +1,5 @@ from rest_framework import generics, filters -from django_filters.rest_framework import DjangoFilterBackend, FilterSet, CharFilter +from django_filters.rest_framework import DjangoFilterBackend, FilterSet, CharFilter, ChoiceFilter from content import models, serializers @@ -7,6 +7,7 @@ class ContentFilter(FilterSet): grade = CharFilter( method='filter_grades_contains', label="Grade/Class" ) + format_type = ChoiceFilter(choices=models.Content.CONTENT_FORMAT_CHOICES, label="Format", field_name="format") def filter_grades_contains(self, queryset, name, value): try: @@ -17,14 +18,13 @@ class ContentFilter(FilterSet): class Meta: model = models.Content - fields = ['format', 'theme', 'topic', 'grade'] + fields = ['format_type', 'theme', 'topic', 'grade'] class ContentList(generics.ListCreateAPIView): queryset = models.Content.objects.all() serializer_class = serializers.ContentSerializer filter_backends = [filters.SearchFilter, filters.OrderingFilter, DjangoFilterBackend] search_fields = ['title'] - #filterset_fields = ['format', 'theme', 'topic'] filterset_class = ContentFilter ordering_fields = '__all__' diff --git a/freekake_api/freekake_api/settings.py b/freekake_api/freekake_api/settings.py index baf0b7d..833aec0 100644 --- a/freekake_api/freekake_api/settings.py +++ b/freekake_api/freekake_api/settings.py @@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/5.1/ref/settings/ """ from pathlib import Path +from decouple import config # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -20,10 +21,10 @@ BASE_DIR = Path(__file__).resolve().parent.parent # See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'django-insecure-@wf_1z20edr655upw6t3tf==56!t%vk(oky=v4+n0io+om=4^x' +SECRET_KEY = config('SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = config('DEBUG', default=False, cast=bool) ALLOWED_HOSTS = [] @@ -44,6 +45,7 @@ INSTALLED_APPS = [ 'psycopg2', 'corsheaders', 'django_filters', + 'debug_toolbar', 'core', 'content', @@ -61,6 +63,8 @@ MIDDLEWARE = [ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', + + 'debug_toolbar.middleware.DebugToolbarMiddleware', ] ROOT_URLCONF = 'freekake_api.urls' @@ -90,11 +94,11 @@ WSGI_APPLICATION = 'freekake_api.wsgi.application' DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': 'freekake_app_db', - 'USER': 'postgres', - 'PASSWORD': 'asalada123', - 'HOST': 'localhost', - 'PORT': '5432', + 'NAME': config('DB_NAME'), + 'USER': config('DB_USER'), + 'PASSWORD': config('DB_PASSWORD'), + 'HOST': config('DB_HOST', default='localhost'), + 'PORT': config('DB_PORT', default='5432'), } } @@ -175,4 +179,8 @@ DJOSER = { 'ACTIVATION_URL': '#/activate/{uid}/{token}', 'SEND_ACTIVATION_EMAIL': True, 'SERIALIZERS': {}, -} \ No newline at end of file +} + +INTERNAL_IPS = [ + '127.0.0.1', +] \ No newline at end of file diff --git a/freekake_api/freekake_api/urls.py b/freekake_api/freekake_api/urls.py index 76c4a5f..3a5670d 100644 --- a/freekake_api/freekake_api/urls.py +++ b/freekake_api/freekake_api/urls.py @@ -17,6 +17,7 @@ Including another URLconf from django.contrib import admin from django.urls import path, include from oauth2_provider import urls as oauth2_urls +from debug_toolbar.toolbar import debug_toolbar_urls urlpatterns = [ # path('admin/', admin.site.urls), @@ -27,4 +28,4 @@ urlpatterns = [ path('core/', include('core.urls')), path('content/', include('content.urls')), path('character/', include('character.urls')), -] +]+ debug_toolbar_urls()