Temporary backup from J621 porting
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
import pymysql
|
||||
|
||||
# Override version to satisfy Django 6.0.3 requirement
|
||||
pymysql.version_info = (2, 2, 1, 'final', 0)
|
||||
pymysql.__version__ = '2.2.1'
|
||||
|
||||
pymysql.install_as_MySQLdb()
|
||||
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
ASGI config for common project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/6.0/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'common.settings')
|
||||
|
||||
application = get_asgi_application()
|
||||
@@ -0,0 +1,17 @@
|
||||
import time
|
||||
from .os_utils import get_os_info
|
||||
from django.conf import settings
|
||||
|
||||
def app_version(request):
|
||||
os_icon, os_name = get_os_info()
|
||||
page_gen_time = ''
|
||||
if hasattr(request, '_start_time') and request._start_time:
|
||||
elapsed = time.time() - request._start_time
|
||||
page_gen_time = f"{elapsed * 1000:.0f}ms"
|
||||
return {
|
||||
'APP_ENV': 'dev' if settings.DEBUG else 'prod',
|
||||
'GIT_COMMIT_HASH': getattr(settings, 'GIT_COMMIT_HASH', 'unknown'),
|
||||
'OS_ICON': os_icon,
|
||||
'OS_NAME': os_name,
|
||||
'PAGE_GEN_TIME': page_gen_time,
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import subprocess
|
||||
import os
|
||||
from functools import lru_cache
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def get_git_commit_hash(short=True):
|
||||
"""
|
||||
Return the current Git commit hash.
|
||||
If not in a git repo or git not available, returns 'unknown'.
|
||||
"""
|
||||
try:
|
||||
# Run from the project root (where manage.py is)
|
||||
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
cmd = ['git', 'rev-parse', '--short', 'HEAD']
|
||||
result = subprocess.run(
|
||||
cmd,
|
||||
cwd=project_root,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=5
|
||||
)
|
||||
if result.returncode == 0:
|
||||
return result.stdout.strip()
|
||||
except Exception:
|
||||
pass
|
||||
return "unknown"
|
||||
@@ -0,0 +1,10 @@
|
||||
import time
|
||||
|
||||
class TimingMiddleware:
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
def __call__(self, request):
|
||||
request._start_time = time.time()
|
||||
response = self.get_response(request)
|
||||
return response
|
||||
@@ -0,0 +1,44 @@
|
||||
# common/os_utils.py
|
||||
import platform
|
||||
import os
|
||||
from functools import lru_cache
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def get_os_info():
|
||||
"""
|
||||
Detect Linux distribution and return (fontawesome_class, display_name).
|
||||
Falls back to generic Linux.
|
||||
"""
|
||||
system = platform.system()
|
||||
if system != 'Linux':
|
||||
return ('fa-brands fa-linux', system)
|
||||
|
||||
# Try to read /etc/os-release
|
||||
os_release_path = '/etc/os-release'
|
||||
distro_id = ''
|
||||
distro_name = ''
|
||||
try:
|
||||
with open(os_release_path, 'r') as f:
|
||||
for line in f:
|
||||
if line.startswith('ID='):
|
||||
distro_id = line.split('=', 1)[1].strip().strip('"').lower()
|
||||
elif line.startswith('NAME='):
|
||||
distro_name = line.split('=', 1)[1].strip().strip('"')
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Map IDs to FontAwesome icons and display names
|
||||
mapping = {
|
||||
'debian': ('fa-brands fa-debian', 'Debian'),
|
||||
'ubuntu': ('fa-brands fa-ubuntu', 'Ubuntu'),
|
||||
'fedora': ('fa-brands fa-fedora', 'Fedora'),
|
||||
'rhel': ('fa-brands fa-redhat', 'RHEL'),
|
||||
'centos': ('fa-brands fa-centos', 'CentOS'),
|
||||
'opensuse': ('fa-brands fa-suse', 'openSUSE'),
|
||||
'suse': ('fa-brands fa-suse', 'SUSE'),
|
||||
}
|
||||
|
||||
if distro_id in mapping:
|
||||
return mapping[distro_id]
|
||||
|
||||
return ('fa-brands fa-linux', distro_name or 'Linux')
|
||||
@@ -0,0 +1,153 @@
|
||||
import os
|
||||
|
||||
from pathlib import Path
|
||||
from dotenv import load_dotenv
|
||||
from .git_utils import get_git_commit_hash
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
load_dotenv()
|
||||
|
||||
# Git commit hash
|
||||
GIT_COMMIT_HASH = get_git_commit_hash()
|
||||
|
||||
DB_HOST = os.getenv('DB_HOST', '127.0.0.1')
|
||||
DB_PORT = int(os.getenv('DB_PORT', 3306))
|
||||
DB_NAME = os.getenv('DB_NAME', 'default')
|
||||
DB_USER = os.getenv('DB_USER', 'default_user')
|
||||
DB_PASSWORD = os.getenv('DB_PASSWORD', '')
|
||||
DB_ROOT_PASSWORD = os.getenv('DB_ROOT_PASSWORD', '')
|
||||
DB_PATH = os.getenv('DB_PATH', './mariadb-data')
|
||||
SECRET_KEY = os.getenv('SECRET_KEY', 'django-insecure-@8e9&qxpwe59^lxa2v&hee1q=%%3*kr#g74k^id328g9m4*2=l')
|
||||
PASSWORD = os.getenv('PASSWORD', 'SetMeYouFuckingIdiot')
|
||||
DEBUG = os.getenv('DEBUG', 'False').lower() == 'true'
|
||||
|
||||
# Defines a display version for templates
|
||||
APP_VERSION = f"{'dev' if DEBUG else 'prod'} @ {GIT_COMMIT_HASH}"
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'api',
|
||||
'landing',
|
||||
'library',
|
||||
'profiles',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'whitenoise.middleware.WhiteNoiseMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
'common.middleware.TimingMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'common.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
'common.context_processors.app_version',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'common.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/6.0/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'NAME': DB_NAME,
|
||||
'USER': DB_USER,
|
||||
'PASSWORD': DB_PASSWORD,
|
||||
'HOST': DB_HOST,
|
||||
'PORT': DB_PORT,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/6.0/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/6.0/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'America/Bogota'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
ALLOWED_HOSTS = ['127.0.0.1', 'jakerasp', 'jakerasp.rainbow-herring.ts.net', 'localhost']
|
||||
|
||||
# Sessions settings
|
||||
SESSION_ENGINE = 'django.contrib.sessions.backends.db'
|
||||
SESSION_COOKIE_AGE = 86400
|
||||
|
||||
# Production Server BS over here
|
||||
CSRF_TRUSTED_ORIGINS = [
|
||||
'https://jakerasp.rainbow-herring.ts.net'
|
||||
]
|
||||
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
||||
USE_X_FORWARDED_HOST = True
|
||||
SESSION_COOKIE_SECURE = True
|
||||
CSRF_COOKIE_SECURE = True
|
||||
|
||||
DATA_UPLOAD_MAX_MEMORY_SIZE = 1073741824 # 1 GB
|
||||
FILE_UPLOAD_MAX_MEMORY_SIZE = 1073741824
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/6.0/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
|
||||
STATIC_ROOT = BASE_DIR / 'staticfiles'
|
||||
|
||||
# Login settings
|
||||
LOGIN_URL = 'login'
|
||||
|
||||
SESSION_EXPIRE_AT_BROWSER_CLOSE = False
|
||||
@@ -0,0 +1,22 @@
|
||||
"""
|
||||
URL configuration for common project.
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/6.0/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
]
|
||||
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
WSGI config for common project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/6.0/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'common.settings')
|
||||
|
||||
application = get_wsgi_application()
|
||||
Reference in New Issue
Block a user