init
This commit is contained in:
parent
d596e319f0
commit
aa14ae0f1f
2 changed files with 41 additions and 13 deletions
|
|
@ -4,8 +4,9 @@ from datetime import datetime
|
|||
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.core.cache import cache
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class BaseModel(models.Model):
|
||||
id = None
|
||||
|
|
@ -28,6 +29,7 @@ class ConfigValueChoices(models.TextChoices):
|
|||
|
||||
|
||||
class Config(BaseModel):
|
||||
value_dict = {}
|
||||
key = models.CharField(_('key'), max_length=255, unique=True, db_index=True)
|
||||
value = models.TextField(_('value'), null=True, blank=True)
|
||||
value_type = models.CharField(choices=ConfigValueChoices.choices, max_length=64)
|
||||
|
|
@ -37,6 +39,7 @@ class Config(BaseModel):
|
|||
def get_value(self):
|
||||
return Config.get_value_of(self.key)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def type_cast(value, value_type):
|
||||
|
||||
|
|
@ -67,14 +70,16 @@ class Config(BaseModel):
|
|||
|
||||
return value
|
||||
|
||||
|
||||
# TODO: revoke cache mechanism
|
||||
@staticmethod
|
||||
def get_value_of(key, default=None, casting_type=None):
|
||||
# TODO: use cache
|
||||
config, created = Config.objects.get_or_create(key=key, defaults={'value': default})
|
||||
if not key in Config.value_dict:
|
||||
config, created = Config.objects.get_or_create(key=key, defaults={'value': default})
|
||||
Config.value_dict[key] = Config.type_cast(config.value, casting_type or config.value_type)
|
||||
logger.info(f'getting value of {key} from db: {Config.value_dict[key]}')
|
||||
|
||||
if config.value is None:
|
||||
return default
|
||||
|
||||
value = Config.type_cast(config.value, casting_type or config.value_type)
|
||||
value = Config.value_dict[key]
|
||||
|
||||
return value
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ from decouple import config
|
|||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/
|
||||
|
||||
|
|
@ -24,7 +25,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
|||
SECRET_KEY = 'django-insecure-fmk!je04bz^-o#tuevr4wafj&1jna6*8*rh8f8po^is3k-0%oe'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
DEBUG = config('DEBUG', default=True, cast=bool)
|
||||
|
||||
ALLOWED_HOSTS = ['*']
|
||||
|
||||
|
|
@ -38,22 +39,31 @@ INSTALLED_APPS = [
|
|||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
"django.contrib.gis",
|
||||
"django.contrib.sitemaps",
|
||||
|
||||
# pip installed apps
|
||||
'drf_spectacular',
|
||||
'oauth2_provider',
|
||||
'rest_framework',
|
||||
'rest_framework_gis',
|
||||
'corsheaders',
|
||||
'crispy_forms',
|
||||
'crispy_bootstrap5',
|
||||
'django_filters',
|
||||
'jalali_date',
|
||||
'django_admin_logs',
|
||||
# 'jalali_date',
|
||||
'taggit',
|
||||
'colorfield',
|
||||
# 'django_minio_backend',
|
||||
'django_minio_backend.apps.DjangoMinioBackendConfig',
|
||||
|
||||
# local apps
|
||||
'apps.core',
|
||||
'apps.users',
|
||||
'apps.gooyal_oauth2',
|
||||
'apps.stores',
|
||||
'apps.suggestions',
|
||||
'apps.crm'
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
|
@ -91,7 +101,7 @@ OAUTH2_PROVIDER = {
|
|||
# 'introspection': 'Introspect token scope'},
|
||||
'OAUTH2_VALIDATOR_CLASS': 'apps.gooyal_oauth2.validators.OAuth2Validator',
|
||||
'RESOURCE_SERVER_INTROSPECTION_URL': OAUTH2_PROVIDER_BASE_PRIVATE_URL + '/introspect/',
|
||||
# 'RESOURCE_SERVER_AUTH_TOKEN': '3yUqsWtwKYKHnfivFcJu', # OR this but not both:
|
||||
# ' RESOURCE_SERVER_AUTH_TOKEN': '3yUqsWtwKYKHnfivFcJu', # OR this but not both:
|
||||
'RESOURCE_SERVER_INTROSPECTION_CREDENTIALS': (OAUTH2_PROVIDER_CLIENT_ID, OAUTH2_PROVIDER_CLIENT_SECRET),
|
||||
}
|
||||
|
||||
|
|
@ -145,7 +155,17 @@ DATABASES = {
|
|||
'PASSWORD': config('DB_PASSWORD'),
|
||||
'HOST': config('DB_HOST', '127.0.0.1'),
|
||||
'PORT': config('DB_PORT', ''),
|
||||
"TEST": {
|
||||
# psql commands: CREATE DATABASE template_postgis OWNER config('DB_USER') ; \c template_postgis; CREATE EXTENSION postgis;
|
||||
"NAME": "test_{}".format(config('DB_NAME')),
|
||||
# "TEMPLATE": "template_postgis",
|
||||
},
|
||||
# "CONN_MAX_AGE": 10,
|
||||
"OPTIONS": {
|
||||
"pool": True,
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
# Password validation
|
||||
|
|
@ -200,7 +220,7 @@ else:
|
|||
|
||||
|
||||
SPECTACULAR_SETTINGS = {
|
||||
'TITLE': 'IPG',
|
||||
'TITLE': 'chat',
|
||||
'DESCRIPTION': 'service api reference',
|
||||
'VERSION': '1.0.0',
|
||||
'SERVE_INCLUDE_SCHEMA': False,
|
||||
|
|
@ -235,5 +255,8 @@ CACHES = {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
from main.other_settings.logging import get_logging_setting
|
||||
LOGGING = get_logging_setting()
|
||||
LOGGING = get_logging_setting()
|
||||
|
||||
NOTIFICATIONS_BASE_PUBLIC_URL = config('NOTIFICATIONS_BASE_PUBLIC_URL', default=None, cast=str)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue