<filename>App/project/settings.py
"""
Django settings for project project.

Generated by 'django-admin startproject' using Django 2.2.7.

For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""

import os

from django.core.management.utils import get_random_secret_key


def get_hardware_serial():
    # Extract serial from cpu info file
    cpuserial = "0000000000000000"
    try:
        with open("/sys/firmware/devicetree/base/serial-number", "r") as f:
            cpuserial = f.read()
    except:  # noqa
        cpuserial = "ERROR000000000"
    return cpuserial


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.getenv("DJANGO_SECRET_KEY", get_random_secret_key())

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

ALLOWED_HOSTS = [
    "localhost",
    "hefesto.local",
    "192.168.137.212",
    "hefesto",
    "*",
]

USE_X_FORWARDED_HOST = False

# Application definition

INSTALLED_APPS = [
    "hefesto_logging",
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "solo",
    "hefesto_core",
    "hefesto_http_agent",
    "hefesto_azure_iothub",
    "hefesto_network",
    "hefesto_modbus",
]

MIDDLEWARE = [
    "django.middleware.security.SecurityMiddleware",
    "django.middleware.gzip.GZipMiddleware",
    "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 = "project.urls"

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [],
        "APP_DIRS": True,
        "OPTIONS": {
            "context_processors": [
                "django.template.context_processors.debug",
                "django.template.context_processors.request",
                "django.contrib.auth.context_processors.auth",
                "django.contrib.messages.context_processors.messages",
            ]
        },
    }
]

WSGI_APPLICATION = "project.wsgi.application"


# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql",
        "NAME": os.getenv("HEFESTO_DB", "hefestodb"),
        "USER": os.getenv("HEFESTO_DB_USER", "hefesto"),
        "PASSWORD": os.getenv("HEFESTO_DB_PASSWORD", "<PASSWORD>"),
        "HOST": os.getenv("HEFESTO_DB_HOST", "postgres"),
        "PORT": os.getenv("HEFESTO_DB_PORT", ""),
    }
}


# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"  # noqa: E501
    },
    {"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
    {
        "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"  # noqa: E501
    },
    {
        "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"  # noqa: E501
    },
]


# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/

LANGUAGE_CODE = "es-co"

TIME_ZONE = "America/Lima"

USE_I18N = True

USE_L10N = False

USE_TZ = True

DATETIME_FORMAT = "Y-m-d H:i:s"

DATA_UPLOAD_MAX_NUMBER_FIELDS = 15000
DATA_UPLOAD_MAX_MEMORY_SIZE = 100*1024*1024

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = "/hefesto/static/"
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_DIR, "static")

LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "handlers": {
        "console": {"class": "logging.StreamHandler", "formatter": "verbose"},
        "db_log": {
            "level": "INFO",
            "class": "hefesto_logging.log_handler.DatabaseLogHandler",
            "formatter": "verbose",
        },
    },
    "loggers": {
        "": {"handlers": ["console", "db_log"], "level": "INFO"},
        "apscheduler": {
            "handlers": ["console", "db_log"],
            "level": "ERROR",
            "propagate": False,
        }
    },
    "formatters": {
        "verbose": {
            "format": "[%(levelname)s] - %(asctime)s | %(name)s | %(module)s.%(funcName)s(%(lineno)s): %(message)s"  # noqa
        }
    },
}

HEFESTO_SERIAL = os.getenv("HEFESTO_SERIAL", None)
HARDWARE_SERIAL = get_hardware_serial()

if HEFESTO_SERIAL is None:
    HEFESTO_SERIAL = HARDWARE_SERIAL

<filename>App/project/settings.py
"""
Django settings for project project.

Generated by 'django-admin startproject' using Django 2.2.7.

For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""

import os

from django.core.management.utils import get_random_secret_key


def get_hardware_serial():
    # Extract serial from cpu info file
    cpuserial = "0000000000000000"
    try:
        with open("/sys/firmware/devicetree/base/serial-number", "r") as f:
            cpuserial = f.read()
    except:  # noqa
        cpuserial = "ERROR000000000"
    return cpuserial


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.getenv("DJANGO_SECRET_KEY", get_random_secret_key())

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

ALLOWED_HOSTS = [
    "localhost",
    "hefesto.local",
    "192.168.137.212",
    "hefesto",
    "*",
]

USE_X_FORWARDED_HOST = False

# Application definition

INSTALLED_APPS = [
    "hefesto_logging",
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "solo",
    "hefesto_core",
    "hefesto_http_agent",
    "hefesto_azure_iothub",
    "hefesto_network",
    "hefesto_modbus",
]

MIDDLEWARE = [
    "django.middleware.security.SecurityMiddleware",
    "django.middleware.gzip.GZipMiddleware",
    "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 = "project.urls"

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [],
        "APP_DIRS": True,
        "OPTIONS": {
            "context_processors": [
                "django.template.context_processors.debug",
                "django.template.context_processors.request",
                "django.contrib.auth.context_processors.auth",
                "django.contrib.messages.context_processors.messages",
            ]
        },
    }
]

WSGI_APPLICATION = "project.wsgi.application"


# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql",
        "NAME": os.getenv("HEFESTO_DB", "hefestodb"),
        "USER": os.getenv("HEFESTO_DB_USER", "hefesto"),
        "PASSWORD": os.getenv("HEFESTO_DB_PASSWORD", "<PASSWORD>"),
        "HOST": os.getenv("HEFESTO_DB_HOST", "postgres"),
        "PORT": os.getenv("HEFESTO_DB_PORT", ""),
    }
}


# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"  # noqa: E501
    },
    {"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
    {
        "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"  # noqa: E501
    },
    {
        "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"  # noqa: E501
    },
]


# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/

LANGUAGE_CODE = "es-co"

TIME_ZONE = "America/Lima"

USE_I18N = True

USE_L10N = False

USE_TZ = True

DATETIME_FORMAT = "Y-m-d H:i:s"

DATA_UPLOAD_MAX_NUMBER_FIELDS = 15000
DATA_UPLOAD_MAX_MEMORY_SIZE = 100*1024*1024

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = "/hefesto/static/"
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_DIR, "static")

LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "handlers": {
        "console": {"class": "logging.StreamHandler", "formatter": "verbose"},
        "db_log": {
            "level": "INFO",
            "class": "hefesto_logging.log_handler.DatabaseLogHandler",
            "formatter": "verbose",
        },
    },
    "loggers": {
        "": {"handlers": ["console", "db_log"], "level": "INFO"},
        "apscheduler": {
            "handlers": ["console", "db_log"],
            "level": "ERROR",
            "propagate": False,
        }
    },
    "formatters": {
        "verbose": {
            "format": "[%(levelname)s] - %(asctime)s | %(name)s | %(module)s.%(funcName)s(%(lineno)s): %(message)s"  # noqa
        }
    },
}

HEFESTO_SERIAL = os.getenv("HEFESTO_SERIAL", None)
HARDWARE_SERIAL = get_hardware_serial()

if HEFESTO_SERIAL is None:
    HEFESTO_SERIAL = HARDWARE_SERIAL

Django settings for project project.  Generated by 'django-admin startproject' using Django 2.2.7.  For more information on this file, see https://docs.djangoproject.com/en/2.2/topics/settings/  For the full list of settings and their values, see https://docs.djangoproject.com/en/2.2/ref/settings/ # Extract serial from cpu info file # noqa # Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! # SECURITY WARNING: don't run with debug turned on in production! # Application definition # Database # https://docs.djangoproject.com/en/2.2/ref/settings/#databases # Password validation # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators # noqa: E501 # noqa: E501 # noqa: E501 # Internationalization # https://docs.djangoproject.com/en/2.2/topics/i18n/ # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.2/howto/static-files/ # noqa