From 2e6f50de43ea5234064bafe58983f5118e195eff Mon Sep 17 00:00:00 2001 From: behruz-dev Date: Tue, 15 Jul 2025 16:49:43 +0500 Subject: [PATCH] add cacheops and unfold for django admin --- config/conf/redis.py | 27 ++++++++++++++++++++++++++- config/conf/unfold.py | 31 +++++++++++++++++++++++++++++++ config/settings/base.py | 13 ++++++++++++- requirements.txt | 4 +++- 4 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 config/conf/unfold.py diff --git a/config/conf/redis.py b/config/conf/redis.py index 0621902..4520c60 100644 --- a/config/conf/redis.py +++ b/config/conf/redis.py @@ -8,4 +8,29 @@ CACHES = { "CLIENT_CLASS": "django_redis.client.DefaultClient", } } -} \ No newline at end of file +} + +CACHE_MIDDLEWARE_SECONDS = env("CACHE_TIMEOUT") + +CACHEOPS_REDIS = env.str("REDIS_URL") +CACHEOPS_DEFAULTS = { + "timeout": env.str("CACHE_TIMEOUT"), +} +CACHEOPS = { + # !NOTE: api => "you app name" + "accounts.*": { + "ops": "all", # Barcha turdagi so'rovlarni keshga olish + "timeout": 60 * 5, # 5 daqiqa davomida saqlash + }, + "shared.*": { + "ops": "all", # Barcha turdagi so'rovlarni keshga olish + "timeout": 60 * 5, # 5 daqiqa davomida saqlash + }, + "contract.*": { + "ops": "all", # Barcha turdagi so'rovlarni keshga olish + "timeout": 60 * 5, # 5 daqiqa davomida saqlash + }, + +} +CACHEOPS_DEGRADE_ON_FAILURE = True +CACHEOPS_ENABLED = env.bool("CACHE_ENABLED", False) \ No newline at end of file diff --git a/config/conf/unfold.py b/config/conf/unfold.py new file mode 100644 index 0000000..948b824 --- /dev/null +++ b/config/conf/unfold.py @@ -0,0 +1,31 @@ + +UNFOLD = { + "DASHBOARD_CALLBACK": "django_core.views.dashboard_callback", + "SITE_TITLE": None, + "SHOW_LANGUAGES": True, + "SITE_HEADER": None, + "SITE_URL": "/", + "SITE_SYMBOL": "speed", # symbol from icon set + "SHOW_HISTORY": True, # show/hide "History" button, default: True + "SHOW_VIEW_ON_SITE": True, + "COLORS": { + "primary": { + "50": "220 255 230", + "100": "190 255 200", + "200": "160 255 170", + "300": "130 255 140", + "400": "100 255 110", + "500": "70 255 80", + "600": "50 225 70", + "700": "40 195 60", + "800": "30 165 50", + "900": "20 135 40", + "950": "10 105 30", + }, + }, + "SIDEBAR": { + "show_search": True, # Search in applications and models names + "show_all_applications": True, + }, + "SHOW_LANGUAGES": False, +} \ No newline at end of file diff --git a/config/settings/base.py b/config/settings/base.py index 8945d42..a5a51b5 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -27,6 +27,14 @@ DJANGO_APPS = [ 'django.contrib.staticfiles', ] +DJANGO_UNFOLD = [ + "unfold", + "unfold.contrib.filters", + "unfold.contrib.forms", + "unfold.contrib.guardian", + "unfold.contrib.simple_history", +] + APPS = [ 'core.apps.shared', 'core.apps.accounts', @@ -37,9 +45,11 @@ PACKAGES = [ 'drf_spectacular', 'rest_framework', 'rest_framework_simplejwt', + 'cacheops', ] INSTALLED_APPS = [] +INSTALLED_APPS += DJANGO_UNFOLD INSTALLED_APPS += DJANGO_APPS INSTALLED_APPS += PACKAGES INSTALLED_APPS += APPS @@ -140,4 +150,5 @@ from config.conf.drf_spectacular import * from config.conf.rest_framework import * from config.conf.simplejwt import * from config.conf.celery import * -from config.conf.redis import * \ No newline at end of file +from config.conf.redis import * +from config.conf.unfold import * \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 771da6a..32fab1e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,4 +12,6 @@ celery==5.5.3 redis==6.2.0 django-redis==6.0.0 pytest -pytest-django \ No newline at end of file +pytest-django +django-cacheops==7.2 +django-unfold==0.62.0 \ No newline at end of file