From 24d43660b30bd6d51da57fb1d777c8960569f980 Mon Sep 17 00:00:00 2001 From: "user@node5.net" Date: Tue, 16 Dec 2025 22:04:36 +0100 Subject: Rename django folder --- web_interface/django_project/ColorLogFormatter.py | 60 +++++++ web_interface/django_project/__init__.py | 0 web_interface/django_project/asgi.py | 16 ++ web_interface/django_project/settings.py | 189 ++++++++++++++++++++++ web_interface/django_project/urls.py | 30 ++++ web_interface/django_project/wsgi.py | 16 ++ web_interface/drinks_machine/ColorLogFormatter.py | 60 ------- web_interface/drinks_machine/__init__.py | 0 web_interface/drinks_machine/asgi.py | 16 -- web_interface/drinks_machine/settings.py | 189 ---------------------- web_interface/drinks_machine/urls.py | 30 ---- web_interface/drinks_machine/wsgi.py | 16 -- web_interface/manage.py | 2 +- 13 files changed, 312 insertions(+), 312 deletions(-) create mode 100644 web_interface/django_project/ColorLogFormatter.py create mode 100644 web_interface/django_project/__init__.py create mode 100644 web_interface/django_project/asgi.py create mode 100644 web_interface/django_project/settings.py create mode 100644 web_interface/django_project/urls.py create mode 100644 web_interface/django_project/wsgi.py delete mode 100644 web_interface/drinks_machine/ColorLogFormatter.py delete mode 100644 web_interface/drinks_machine/__init__.py delete mode 100644 web_interface/drinks_machine/asgi.py delete mode 100644 web_interface/drinks_machine/settings.py delete mode 100644 web_interface/drinks_machine/urls.py delete mode 100644 web_interface/drinks_machine/wsgi.py (limited to 'web_interface') diff --git a/web_interface/django_project/ColorLogFormatter.py b/web_interface/django_project/ColorLogFormatter.py new file mode 100644 index 0000000..939d591 --- /dev/null +++ b/web_interface/django_project/ColorLogFormatter.py @@ -0,0 +1,60 @@ +import logging + + +class ColorFormatter(logging.Formatter): + grey = "\x1b[90;20m" + cyan = "\x1b[96;20m" + yellow = "\x1b[33;20m" + red = "\x1b[31;20m" + bold_red = "\x1b[31;1m" + reset = "\x1b[0m" + format = "%(asctime)s,%(msecs)03d %(levelname)-8s %(filename)s:%(lineno)d %(message)s" + + FORMATS = { + logging.DEBUG: grey + format + reset, + logging.INFO: cyan + format + reset, + logging.WARNING: yellow + format + reset, + logging.ERROR: red + format + reset, + logging.CRITICAL: bold_red + format + reset, + } + + def format(self, record): + log_fmt = self.FORMATS.get(record.levelno) + formatter = logging.Formatter(log_fmt) + formatted = formatter.format(record) + return formatted + + +class SysLogColorFormatter(logging.Formatter): + grey = "\x1b[90;20m" + cyan = "\x1b[96;20m" + yellow = "\x1b[33;20m" + red = "\x1b[31;20m" + bold_red = "\x1b[31;1m" + reset = "\x1b[0m" + format = "%(levelname)-8s %(filename)s:%(lineno)d %(message)s" + + FORMATS = { + logging.DEBUG: grey + format + reset, + logging.INFO: cyan + format + reset, + logging.WARNING: yellow + format + reset, + logging.ERROR: red + format + reset, + logging.CRITICAL: bold_red + format + reset, + } + + def format(self, record): + log_fmt = self.FORMATS.get(record.levelno) + formatter = logging.Formatter(log_fmt) + formatted = formatter.format(record) + return formatted + + +""" Example how to log in other modules: +logger = logging.getLogger(__name__) # Instantiate a logger to be used in this module + +logger.debug("debug message") +logger.info("info message") +logger.warning("warning message") +logger.error("error message") +logger.critical("critical message") +""" diff --git a/web_interface/django_project/__init__.py b/web_interface/django_project/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/web_interface/django_project/asgi.py b/web_interface/django_project/asgi.py new file mode 100644 index 0000000..c4af364 --- /dev/null +++ b/web_interface/django_project/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for drinks_machine 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', 'drinks_machine.settings') + +application = get_asgi_application() diff --git a/web_interface/django_project/settings.py b/web_interface/django_project/settings.py new file mode 100644 index 0000000..4f23ce3 --- /dev/null +++ b/web_interface/django_project/settings.py @@ -0,0 +1,189 @@ +""" +Django settings for drinks-machine project. + +Generated by 'django-admin startproject' using Django 6.0. + +For more information on this file, see +https://docs.djangoproject.com/en/6.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/6.0/ref/settings/ +""" + +from pathlib import Path +import os +import sys + +from django.core.management.utils import get_random_secret_key + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + +MEDIA_URL = '/media/' +MEDIA_ROOT = os.path.join(BASE_DIR, 'media') + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! + +# Define the path to your secret key file inside the .secrets folder +secret_key_file = os.path.join(BASE_DIR, '.secrets', 'secret_key.txt') + +# Ensure the .secrets directory exists +os.makedirs(os.path.dirname(secret_key_file), exist_ok=True) + +# Check if the file exists +if not os.path.exists(secret_key_file): + # Generate a new secret key + secret_key = get_random_secret_key() + + # Save the secret key to the file + with open(secret_key_file, 'w') as f: + f.write(secret_key) +else: + # Read the secret key from the file + with open(secret_key_file, 'r') as f: + secret_key = f.read().strip() + +# Set the SECRET_KEY setting +SECRET_KEY = secret_key + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = "DEBUG" in os.environ and os.environ["DEBUG"] == "INSECURE" +print(f"Debug is: {'on' if DEBUG else 'off'}") + +ALLOWED_HOSTS = ['127.0.0.1', 'drinks-machine.node5.net'] + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'drinks', + 'colorfield', + 'motor_controls', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + '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', +] + +ROOT_URLCONF = 'django_project.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', + ], + }, + }, +] + +WSGI_APPLICATION = 'django_project.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/6.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# 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 = 'UTC' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/6.0/howto/static-files/ + +STATIC_URL = '/static/' +#STATIC_ROOT = os.path.join(BASE_DIR, "static") +STATICFILES_DIRS = [BASE_DIR / "static"] + +LOGGING = { + "version": 1, + "disable_existing_loggers": False, + "handlers": { + "console": { + "stream": sys.stdout, + "class": "logging.StreamHandler", + "formatter": "verbose", + }, + "syslog": { + "address": "/dev/log", + "class": "logging.handlers.SysLogHandler", + "formatter": "verbose", + }, + }, + "root": { + "handlers": ["console" if DEBUG is True else "syslog"], + "level": "DEBUG", + }, + "loggers": { + "django": { + "handlers": ["console" if DEBUG is True else "syslog"], + "level": "INFO", + "propagate": False, + }, + }, + "formatters": { + "verbose": { + "()": ( + "django_project.ColorLogFormatter.ColorFormatter" + if DEBUG is True + else "django_project.ColorLogFormatter.SysLogColorFormatter" + ), + "format": "{asctime:s} {levelname:8s} {filename}:{lineno:d} \t {message}", + "style": "{", + }, + }, +} diff --git a/web_interface/django_project/urls.py b/web_interface/django_project/urls.py new file mode 100644 index 0000000..aaafc65 --- /dev/null +++ b/web_interface/django_project/urls.py @@ -0,0 +1,30 @@ +""" +URL configuration for drinks_machine 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, include +from django.views.generic import RedirectView +from django.conf.urls.static import static +from django.conf import settings + +urlpatterns = [ + path('admin/', admin.site.urls), + path("drinks/", include("drinks.urls")), + path('', RedirectView.as_view(url='/drinks/', permanent=False), name='redirect'), + path("motor-controls/", include("motor_controls.urls")), +] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + \ + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + diff --git a/web_interface/django_project/wsgi.py b/web_interface/django_project/wsgi.py new file mode 100644 index 0000000..a5d2224 --- /dev/null +++ b/web_interface/django_project/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for drinks_machine 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', 'drinks_machine.settings') + +application = get_wsgi_application() diff --git a/web_interface/drinks_machine/ColorLogFormatter.py b/web_interface/drinks_machine/ColorLogFormatter.py deleted file mode 100644 index 939d591..0000000 --- a/web_interface/drinks_machine/ColorLogFormatter.py +++ /dev/null @@ -1,60 +0,0 @@ -import logging - - -class ColorFormatter(logging.Formatter): - grey = "\x1b[90;20m" - cyan = "\x1b[96;20m" - yellow = "\x1b[33;20m" - red = "\x1b[31;20m" - bold_red = "\x1b[31;1m" - reset = "\x1b[0m" - format = "%(asctime)s,%(msecs)03d %(levelname)-8s %(filename)s:%(lineno)d %(message)s" - - FORMATS = { - logging.DEBUG: grey + format + reset, - logging.INFO: cyan + format + reset, - logging.WARNING: yellow + format + reset, - logging.ERROR: red + format + reset, - logging.CRITICAL: bold_red + format + reset, - } - - def format(self, record): - log_fmt = self.FORMATS.get(record.levelno) - formatter = logging.Formatter(log_fmt) - formatted = formatter.format(record) - return formatted - - -class SysLogColorFormatter(logging.Formatter): - grey = "\x1b[90;20m" - cyan = "\x1b[96;20m" - yellow = "\x1b[33;20m" - red = "\x1b[31;20m" - bold_red = "\x1b[31;1m" - reset = "\x1b[0m" - format = "%(levelname)-8s %(filename)s:%(lineno)d %(message)s" - - FORMATS = { - logging.DEBUG: grey + format + reset, - logging.INFO: cyan + format + reset, - logging.WARNING: yellow + format + reset, - logging.ERROR: red + format + reset, - logging.CRITICAL: bold_red + format + reset, - } - - def format(self, record): - log_fmt = self.FORMATS.get(record.levelno) - formatter = logging.Formatter(log_fmt) - formatted = formatter.format(record) - return formatted - - -""" Example how to log in other modules: -logger = logging.getLogger(__name__) # Instantiate a logger to be used in this module - -logger.debug("debug message") -logger.info("info message") -logger.warning("warning message") -logger.error("error message") -logger.critical("critical message") -""" diff --git a/web_interface/drinks_machine/__init__.py b/web_interface/drinks_machine/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/web_interface/drinks_machine/asgi.py b/web_interface/drinks_machine/asgi.py deleted file mode 100644 index c4af364..0000000 --- a/web_interface/drinks_machine/asgi.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -ASGI config for drinks_machine 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', 'drinks_machine.settings') - -application = get_asgi_application() diff --git a/web_interface/drinks_machine/settings.py b/web_interface/drinks_machine/settings.py deleted file mode 100644 index 3dd92fc..0000000 --- a/web_interface/drinks_machine/settings.py +++ /dev/null @@ -1,189 +0,0 @@ -""" -Django settings for drinks_machine project. - -Generated by 'django-admin startproject' using Django 6.0. - -For more information on this file, see -https://docs.djangoproject.com/en/6.0/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/6.0/ref/settings/ -""" - -from pathlib import Path -import os -import sys - -from django.core.management.utils import get_random_secret_key - -# Build paths inside the project like this: BASE_DIR / 'subdir'. -BASE_DIR = Path(__file__).resolve().parent.parent - -MEDIA_URL = '/media/' -MEDIA_ROOT = os.path.join(BASE_DIR, 'media') - - -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! - -# Define the path to your secret key file inside the .secrets folder -secret_key_file = os.path.join(BASE_DIR, '.secrets', 'secret_key.txt') - -# Ensure the .secrets directory exists -os.makedirs(os.path.dirname(secret_key_file), exist_ok=True) - -# Check if the file exists -if not os.path.exists(secret_key_file): - # Generate a new secret key - secret_key = get_random_secret_key() - - # Save the secret key to the file - with open(secret_key_file, 'w') as f: - f.write(secret_key) -else: - # Read the secret key from the file - with open(secret_key_file, 'r') as f: - secret_key = f.read().strip() - -# Set the SECRET_KEY setting -SECRET_KEY = secret_key - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = "DEBUG" in os.environ and os.environ["DEBUG"] == "INSECURE" -print(f"Debug is: {'on' if DEBUG else 'off'}") - -ALLOWED_HOSTS = ['127.0.0.1', 'drinks-machine.node5.net'] - -# Application definition - -INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'drinks', - 'colorfield', - 'motor_controls', -] - -MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - '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', -] - -ROOT_URLCONF = 'drinks_machine.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', - ], - }, - }, -] - -WSGI_APPLICATION = 'drinks_machine.wsgi.application' - - -# Database -# https://docs.djangoproject.com/en/6.0/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', - } -} - - -# 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 = 'UTC' - -USE_I18N = True - -USE_TZ = True - - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/6.0/howto/static-files/ - -STATIC_URL = '/static/' -#STATIC_ROOT = os.path.join(BASE_DIR, "static") -STATICFILES_DIRS = [BASE_DIR / "static"] - -LOGGING = { - "version": 1, - "disable_existing_loggers": False, - "handlers": { - "console": { - "stream": sys.stdout, - "class": "logging.StreamHandler", - "formatter": "verbose", - }, - "syslog": { - "address": "/dev/log", - "class": "logging.handlers.SysLogHandler", - "formatter": "verbose", - }, - }, - "root": { - "handlers": ["console" if DEBUG is True else "syslog"], - "level": "DEBUG", - }, - "loggers": { - "django": { - "handlers": ["console" if DEBUG is True else "syslog"], - "level": "INFO", - "propagate": False, - }, - }, - "formatters": { - "verbose": { - "()": ( - "drinks_machine.ColorLogFormatter.ColorFormatter" - if DEBUG is True - else "drinks_machine.ColorLogFormatter.SysLogColorFormatter" - ), - "format": "{asctime:s} {levelname:8s} {filename}:{lineno:d} \t {message}", - "style": "{", - }, - }, -} diff --git a/web_interface/drinks_machine/urls.py b/web_interface/drinks_machine/urls.py deleted file mode 100644 index aaafc65..0000000 --- a/web_interface/drinks_machine/urls.py +++ /dev/null @@ -1,30 +0,0 @@ -""" -URL configuration for drinks_machine 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, include -from django.views.generic import RedirectView -from django.conf.urls.static import static -from django.conf import settings - -urlpatterns = [ - path('admin/', admin.site.urls), - path("drinks/", include("drinks.urls")), - path('', RedirectView.as_view(url='/drinks/', permanent=False), name='redirect'), - path("motor-controls/", include("motor_controls.urls")), -] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + \ - static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) - diff --git a/web_interface/drinks_machine/wsgi.py b/web_interface/drinks_machine/wsgi.py deleted file mode 100644 index a5d2224..0000000 --- a/web_interface/drinks_machine/wsgi.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -WSGI config for drinks_machine 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', 'drinks_machine.settings') - -application = get_wsgi_application() diff --git a/web_interface/manage.py b/web_interface/manage.py index 57cbb60..5ffd8de 100755 --- a/web_interface/manage.py +++ b/web_interface/manage.py @@ -6,7 +6,7 @@ import sys def main(): """Run administrative tasks.""" - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'drinks_machine.settings') + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') try: from django.core.management import execute_from_command_line except ImportError as exc: -- cgit v1.3.1