updated settings for restframework, spectacular, knox, corsheader and shell_plus
This commit is contained in:
parent
ec680d3610
commit
85dc1665c8
@ -11,11 +11,14 @@ https://docs.djangoproject.com/en/5.1/ref/settings/
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from socket import gethostname
|
||||||
|
from datetime import timedelta
|
||||||
|
from rest_framework.settings import api_settings
|
||||||
|
import requests
|
||||||
|
|
||||||
# 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
|
||||||
|
|
||||||
|
|
||||||
# Quick-start development settings - unsuitable for production
|
# Quick-start development settings - unsuitable for production
|
||||||
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
|
||||||
|
|
||||||
@ -25,8 +28,19 @@ SECRET_KEY = 'django-insecure-wny1^**b1fi$djevi@-sz!k%q&5ql)1#t*d-i61#ce1vc2ta&j
|
|||||||
# 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 = True
|
||||||
|
|
||||||
ALLOWED_HOSTS = []
|
try:
|
||||||
|
HOSTNAME = gethostname()
|
||||||
|
except:
|
||||||
|
HOSTNAME = "puckoprutt.tech"
|
||||||
|
|
||||||
|
try:
|
||||||
|
EXT_IP = requests.get("https://api.ipify.org").text
|
||||||
|
except:
|
||||||
|
EXT_IP = "127.0.0.1"
|
||||||
|
|
||||||
|
LOCAL_IP = "192.168.0.42"
|
||||||
|
|
||||||
|
ALLOWED_HOSTS = [HOSTNAME, EXT_IP, LOCAL_IP, "localhost", "api.puckoprutt.tech"]
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
@ -37,11 +51,23 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
|
|
||||||
|
# 3rd party
|
||||||
|
'django_extensions',
|
||||||
|
'corsheaders',
|
||||||
|
'rest_framework',
|
||||||
|
'drf_spectacular',
|
||||||
|
'drf_spectacular_sidecar',
|
||||||
|
'knox',
|
||||||
|
|
||||||
|
# my shit
|
||||||
|
'user'
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
'django.middleware.security.SecurityMiddleware',
|
'django.middleware.security.SecurityMiddleware',
|
||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
|
'corsheaders.middleware.CorsMiddleware',
|
||||||
'django.middleware.common.CommonMiddleware',
|
'django.middleware.common.CommonMiddleware',
|
||||||
'django.middleware.csrf.CsrfViewMiddleware',
|
'django.middleware.csrf.CsrfViewMiddleware',
|
||||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||||
@ -51,6 +77,81 @@ MIDDLEWARE = [
|
|||||||
|
|
||||||
ROOT_URLCONF = 'settings.urls'
|
ROOT_URLCONF = 'settings.urls'
|
||||||
|
|
||||||
|
#Django REST-Framework
|
||||||
|
REST_FRAMEWORK = {
|
||||||
|
"DEFAULT_PARSER_CLASSES": [
|
||||||
|
"rest_framework.parsers.JSONParser",
|
||||||
|
"rest_framework_yaml.parsers.YAMLParser",
|
||||||
|
"rest_framework_xml.parsers.XMLParser"
|
||||||
|
],
|
||||||
|
"DEFAULT_RENDER_CLASSES": [
|
||||||
|
"rest_framework.renderers.JSONRenderer",
|
||||||
|
"rest_framework_yaml.renderers.YAMLRenderer",
|
||||||
|
"rest_framework_xml.renderers.XMLRenderer"
|
||||||
|
"rest_framework.renderers.BrowsableAPIRender"
|
||||||
|
],
|
||||||
|
"DEFAULT_PERMISSION_CLASSES": [
|
||||||
|
"rest_framework.permissions.AllowAny",
|
||||||
|
"rest_framework.permissions.IsAuthenticated",
|
||||||
|
"rest_framework.permissions.IsAdminUser",
|
||||||
|
"rest_framework.permissions.IsAuthenticatedOrReadOnly"
|
||||||
|
],
|
||||||
|
"DEFAULT_AUTHENTICATION_CLASSES": [
|
||||||
|
"knox.auth.TokenAuthentication",
|
||||||
|
"rest_framework.authentication.SessionAuthentication"
|
||||||
|
],
|
||||||
|
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
|
||||||
|
'DEFAULT_PAGINATION_CLASS': 'puckodjango.rest.pagination.MediumPagination',
|
||||||
|
'PAGE_SIZE': 10
|
||||||
|
}
|
||||||
|
|
||||||
|
# DRF-Spectacular
|
||||||
|
SPECTACULAR_SETTINGS = {
|
||||||
|
"TITLE": "Puckoprutt Pathfinder API",
|
||||||
|
"DESCRIPTION": "A interactive web API for pathfinder stuffs and giggles.",
|
||||||
|
"VERSION": "0.1.0",
|
||||||
|
"SERVE_PUBLIC": False,
|
||||||
|
"SERVE_INCLUDE_SCHEMA": False,
|
||||||
|
"SWAGGER_UI_DIST": "SIDECAR",
|
||||||
|
"SWAGGER_UI_FAVICON_HREF": "SIDECAR",
|
||||||
|
"REDOC_DIST": "SIDECAR",
|
||||||
|
"SWAGGER_UI_SETTINGS": {
|
||||||
|
"deepLinking": True,
|
||||||
|
"persistAuthorization": True,
|
||||||
|
"displayOperationId": True
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Restful Knox
|
||||||
|
KNOX_TOKEN_MODEL = "knox.AuthToken"
|
||||||
|
|
||||||
|
REST_KNOX = {
|
||||||
|
"SECURE_HASH_ALGORITHM": "hashlib.sha3_512",
|
||||||
|
"AUTH_TOKEN_CHARACTER_LENGTH": 64,
|
||||||
|
"TOKEN_TTL": timedelta(days=4, hours=12),
|
||||||
|
"USER_SERIALIZER": "puckodjango.rest.users.serializer.Pucko_User_Serializer",
|
||||||
|
"TOKEN_LIMIT_PER_USER": 3,
|
||||||
|
"AUTO_REFRESH": False,
|
||||||
|
"AUTO_REFRESH_MAX_TTL": None,
|
||||||
|
"MIN_REFRESH_INTERVAL": 60,
|
||||||
|
"AUTH_HEADER_PREFIX": "Bearer",
|
||||||
|
"EXPIRY_DATETIME_FORMAT": api_settings.DATETIME_FORMAT,
|
||||||
|
"TOKEN_MODEL": "knox.AuthToken"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Django Extensions
|
||||||
|
SHELL_PLUS_MODEL_IMPORTS_RESOLVER = 'django_extensions.collision_resolvers.AppNamePrefixCR'
|
||||||
|
|
||||||
|
# CORS
|
||||||
|
if DEBUG:
|
||||||
|
CORS_ALLOW_ALL_ORIGINS = True
|
||||||
|
else:
|
||||||
|
CORS_ALLOW_ORIGIN_REGEXES = [
|
||||||
|
rf"(https|http)://(\w+\.|)(puckoprutt\.tech|{LOCAL_IP})$"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
@ -103,9 +204,9 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/5.1/topics/i18n/
|
# https://docs.djangoproject.com/en/5.1/topics/i18n/
|
||||||
|
|
||||||
LANGUAGE_CODE = 'en-us'
|
LANGUAGE_CODE = 'sv'
|
||||||
|
|
||||||
TIME_ZONE = 'UTC'
|
TIME_ZONE = 'Europe/Stockholm'
|
||||||
|
|
||||||
USE_I18N = True
|
USE_I18N = True
|
||||||
|
|
||||||
@ -116,6 +217,7 @@ USE_TZ = True
|
|||||||
# https://docs.djangoproject.com/en/5.1/howto/static-files/
|
# https://docs.djangoproject.com/en/5.1/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = 'static/'
|
STATIC_URL = 'static/'
|
||||||
|
STATIC_ROOT = BASE_DIR / "static"
|
||||||
|
|
||||||
# Default primary key field type
|
# Default primary key field type
|
||||||
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
|
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user