debug toolbar dan environment

This commit is contained in:
Irwan Cahyono 2025-06-28 21:38:44 +07:00
parent 0a8b9caed4
commit 151cd89b88
4 changed files with 36 additions and 26 deletions

View File

@ -30,19 +30,20 @@ class ContentTopic(SoftDeleteModel):
class Content(SoftDeleteModel): class Content(SoftDeleteModel):
class ContentFormat(models.TextChoices): CONTENT_FORMAT_CHOICES = [
TEXT = 'Text', 'Teks' ('Text', 'Teks'),
INFOGRAPHIC = 'Infographic', 'Infografis' ('Infographic', 'Infografis'),
IMAGE = 'Image', 'Gambar' ('Image', 'Gambar'),
VIDEO = 'Video', 'Video' ('Video', 'Video'),
BRANCHING_SCENARIO = 'Branching Scenario', 'Pilihan Bercabang' ('Branching Scenario', 'Pilihan Bercabang'),
CROSSWORD = 'Crossword', 'Teka-teki Silang' ('Crossword', 'Teka-teki Silang'),
DRAG_AND_DROP = 'Drag And Drop', 'Pencocokan' ('Drag And Drop', 'Pencocokan'),
FIND_THE_WORDS = 'Find the Words', 'Cari Kata' ('Find the Words', 'Cari Kata'),
MEMORY_GAME = 'Memory Game', 'Permainan Memori' ('Memory Game', 'Permainan Memori'),
PERSONALITY_QUIZ = 'Personality Quiz', 'Permainan Tebak Sifat' ('Personality Quiz', 'Permainan Tebak Sifat'),
GAME_MAP = 'Game Map', 'Peta Permainan' ('Game Map', 'Peta Permainan'),
MULTIPLE_CHOICE = 'Multiple Choice', 'Pilihan Ganda' ('Multiple Choice', 'Pilihan Ganda'),
]
title = models.CharField(max_length=255, null=False) title = models.CharField(max_length=255, null=False)
slug = models.SlugField(max_length=255) slug = models.SlugField(max_length=255)
@ -51,7 +52,7 @@ class Content(SoftDeleteModel):
theme = models.ForeignKey(ContentTheme, on_delete=models.CASCADE, null=False) theme = models.ForeignKey(ContentTheme, on_delete=models.CASCADE, null=False)
topic = models.ForeignKey(ContentTopic, 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) content = models.TextField(null=True)
data = models.JSONField(null=True) data = models.JSONField(null=True)

View File

@ -1,5 +1,5 @@
from rest_framework import generics, filters 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 from content import models, serializers
@ -7,6 +7,7 @@ class ContentFilter(FilterSet):
grade = CharFilter( grade = CharFilter(
method='filter_grades_contains', label="Grade/Class" 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): def filter_grades_contains(self, queryset, name, value):
try: try:
@ -17,14 +18,13 @@ class ContentFilter(FilterSet):
class Meta: class Meta:
model = models.Content model = models.Content
fields = ['format', 'theme', 'topic', 'grade'] fields = ['format_type', 'theme', 'topic', 'grade']
class ContentList(generics.ListCreateAPIView): class ContentList(generics.ListCreateAPIView):
queryset = models.Content.objects.all() queryset = models.Content.objects.all()
serializer_class = serializers.ContentSerializer serializer_class = serializers.ContentSerializer
filter_backends = [filters.SearchFilter, filters.OrderingFilter, DjangoFilterBackend] filter_backends = [filters.SearchFilter, filters.OrderingFilter, DjangoFilterBackend]
search_fields = ['title'] search_fields = ['title']
#filterset_fields = ['format', 'theme', 'topic']
filterset_class = ContentFilter filterset_class = ContentFilter
ordering_fields = '__all__' ordering_fields = '__all__'

View File

@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/5.1/ref/settings/
""" """
from pathlib import Path from pathlib import Path
from decouple import config
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent 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/ # See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret! # 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! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True DEBUG = config('DEBUG', default=False, cast=bool)
ALLOWED_HOSTS = [] ALLOWED_HOSTS = []
@ -44,6 +45,7 @@ INSTALLED_APPS = [
'psycopg2', 'psycopg2',
'corsheaders', 'corsheaders',
'django_filters', 'django_filters',
'debug_toolbar',
'core', 'core',
'content', 'content',
@ -61,6 +63,8 @@ MIDDLEWARE = [
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
] ]
ROOT_URLCONF = 'freekake_api.urls' ROOT_URLCONF = 'freekake_api.urls'
@ -90,11 +94,11 @@ WSGI_APPLICATION = 'freekake_api.wsgi.application'
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', 'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'freekake_app_db', 'NAME': config('DB_NAME'),
'USER': 'postgres', 'USER': config('DB_USER'),
'PASSWORD': 'asalada123', 'PASSWORD': config('DB_PASSWORD'),
'HOST': 'localhost', 'HOST': config('DB_HOST', default='localhost'),
'PORT': '5432', 'PORT': config('DB_PORT', default='5432'),
} }
} }
@ -176,3 +180,7 @@ DJOSER = {
'SEND_ACTIVATION_EMAIL': True, 'SEND_ACTIVATION_EMAIL': True,
'SERIALIZERS': {}, 'SERIALIZERS': {},
} }
INTERNAL_IPS = [
'127.0.0.1',
]

View File

@ -17,6 +17,7 @@ Including another URLconf
from django.contrib import admin from django.contrib import admin
from django.urls import path, include from django.urls import path, include
from oauth2_provider import urls as oauth2_urls from oauth2_provider import urls as oauth2_urls
from debug_toolbar.toolbar import debug_toolbar_urls
urlpatterns = [ urlpatterns = [
# path('admin/', admin.site.urls), # path('admin/', admin.site.urls),
@ -27,4 +28,4 @@ urlpatterns = [
path('core/', include('core.urls')), path('core/', include('core.urls')),
path('content/', include('content.urls')), path('content/', include('content.urls')),
path('character/', include('character.urls')), path('character/', include('character.urls')),
] ]+ debug_toolbar_urls()