<gh_stars>1-10
"""
Django settings for astroedu project.

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

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

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

from pathlib import Path
import os
import dj_database_url
from django_storage_url import dsn_configured_storage_class


# 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/3.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('SECRET_KEY', 'z2=$*^40@k+--2u@z8j8&c5!^3_o1-lc06#ih5^uboqtn(*1n0')


# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DJANGO_DEBUG') == "True"

DIVIO_DOMAIN = os.environ.get('DOMAIN', '')

DIVIO_DOMAIN_ALIASES = [
    d.strip()
    for d in os.environ.get('DOMAIN_ALIASES', '').split(',')
    if d.strip()
]

ALLOWED_HOSTS = [DIVIO_DOMAIN] + DIVIO_DOMAIN_ALIASES


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.redirects',
    'django.contrib.sites',
    'django.contrib.sitemaps',
    'parler',
    'easy_thumbnails',
    'pagedown',
    'martor',

    'smartpages',
    'institutions',
    'activities',
    'filemanager',
    'astroedu'
]

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',
    'django.middleware.locale.LocaleMiddleware',
    'django.contrib.redirects.middleware.RedirectFallbackMiddleware'
]

SITE_ID = 1

ROOT_URLCONF = 'astroedu.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates'),],
        '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 = 'astroedu.wsgi.application'


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

DEFAULT_DATABASE_DSN = os.environ.get('DEFAULT_DATABASE_DSN', 'sqlite://:memory:')
DATABASES = {'default': dj_database_url.parse(DEFAULT_DATABASE_DSN)}

# Password validation
# https://docs.djangoproject.com/en/3.1/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/3.1/topics/i18n/

LANGUAGE_CODE = 'en'

LANGUAGES = (
    # ('cs', 'Czech'),
    # ('nl', 'Dutch'),
    ('en', 'English'),
    # ('fr', 'French'),
    # ('de', 'German'),
    # ('el', 'Greek'),
    ('it', 'Italian'),
    ('kr', 'Korean'),
)
# LANGUAGES = sorted(LANGUAGES, key=operator.itemgetter(0))

PARLER_LANGUAGES = {
    1: (
        {'code': 'en'},
        {'code': 'it'},
        {'code': 'kr'},
    ),
    'default': {
        'fallbacks': ['en'],
        'hide_untranslated': True,   # False is the default; let .active_translations() return fallbacks too.
    }
}

ADMIN_SITE_TITLE  = 'astroEDU admin'
DEBUG_PROPAGATE_EXCEPTIONS = True

SITE_ROOT = os.path.dirname(os.path.realpath(__name__))
LOCALE_PATHS = ( os.path.join(SITE_ROOT, 'locale'), )

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

# read the setting value from the environment variable
DEFAULT_STORAGE_DSN = os.environ.get('DEFAULT_STORAGE_DSN')

# dsn_configured_storage_class() requires the name of the setting
DefaultStorageClass = dsn_configured_storage_class('DEFAULT_STORAGE_DSN')

# Django's DEFAULT_FILE_STORAGE requires the class name
DEFAULT_FILE_STORAGE = 'astroedu.settings.DefaultStorageClass'

THUMBNAIL_DEFAULT_STORAGE  = DEFAULT_FILE_STORAGE

MEDIA_URL = 'media/'
MEDIA_ROOT = os.path.join('/data/media/')

THUMBNAIL_ALIASES = {
    '': {
        'thumb': {'size': (334, 180), 'crop': True},
        'thumb2': {'size': (500, 269), 'crop': True},
        'epubcover': {'size': (800,1066), 'crop': True},
        'logo': {'size': (180, 180), 'crop': 'scale'},
        },
}

BLEACH_ALLOWED_TAGS = ('sup', 'sub', 'br', )
BLEACH_ALLOWED_ATTRIBUTES = {}
BLEACH_ALLOWED_STYLES = {}

# Mistune
MISTUNE_STYLES = {
    # 'escape': True,  # all raw html tags will be escaped.
    # 'hard_wrap': True,  # it will has GFM line breaks feature.
    'use_xhtml': True,  # all tags will be in xhtml, for example: <hr />.
    # 'parse_html': True,  # parse text in block level html.
    # 'skip_style': True,
    # 'skip_html': True,
}

MARTOR_THEME = 'semantic'

# Global martor settings
# Input: string boolean, `true/false`
MARTOR_ENABLE_CONFIGS = {
    'emoji': 'false',        # to enable/disable emoji icons.
    'imgur': 'true',        # to enable/disable imgur/custom uploader.
    'mention': 'false',     # to enable/disable mention
    'jquery': 'true',       # to include/revoke jquery (require for admin default django)
    'living': 'false',      # to enable/disable live updates in preview
    'spellcheck': 'false',  # to enable/disable spellcheck in form textareas
    'hljs': 'true',         # to enable/disable hljs highlighting in preview
}

MARTOR_MARKDOWN_EXTENSIONS = [
    'markdown.extensions.extra',
    'markdown.extensions.nl2br',
    'markdown.extensions.smarty',
    'markdown.extensions.fenced_code',
    'markdown.extensions.tables',

    # Custom markdown extensions.
    'martor.extensions.urlize',
    'martor.extensions.del_ins',      # ~~strikethrough~~ and ++underscores++
    'martor.extensions.mention',      # to parse markdown mention
    'martor.extensions.mdx_video',    # to parse embed/iframe video
]

import time
MARTOR_UPLOAD_PATH = 'images/uploads/{}'.format(time.strftime("%Y/%m/%d/"))
MARTOR_UPLOAD_URL = '/api/uploader/'  # change to local uploader
MAX_IMAGE_UPLOAD_SIZE = 5242880  # 5MB



# PAGEDOWN_IMAGE_UPLOAD_PATH = 'activities/attach/'
# PAGEDOWN_IMAGE_UPLOAD_ENABLED=True
# PAGEDOWN_IMAGE_UPLOAD_UNIQUE = True

TEMPLATE_STRING_IF_INVALID = 'temp'

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
        },
    },
    'django': {
        'handlers': ['console'],
        'level': 'DEBUG',
    },
}

"""
Django settings for astroedu project.

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

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

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

from pathlib import Path
import os
import dj_database_url
from django_storage_url import dsn_configured_storage_class


# 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/3.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('SECRET_KEY', 'z2=$*^40@k+--2u@z8j8&c5!^3_o1-lc06#ih5^uboqtn(*1n0')


# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DJANGO_DEBUG') == "True"

DIVIO_DOMAIN = os.environ.get('DOMAIN', '')

DIVIO_DOMAIN_ALIASES = [
    d.strip()
    for d in os.environ.get('DOMAIN_ALIASES', '').split(',')
    if d.strip()
]

ALLOWED_HOSTS = [DIVIO_DOMAIN] + DIVIO_DOMAIN_ALIASES


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.redirects',
    'django.contrib.sites',
    'django.contrib.sitemaps',
    'parler',
    'easy_thumbnails',
    'pagedown',
    'martor',

    'smartpages',
    'institutions',
    'activities',
    'filemanager',
    'astroedu'
]

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',
    'django.middleware.locale.LocaleMiddleware',
    'django.contrib.redirects.middleware.RedirectFallbackMiddleware'
]

SITE_ID = 1

ROOT_URLCONF = 'astroedu.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates'),],
        '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 = 'astroedu.wsgi.application'


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

DEFAULT_DATABASE_DSN = os.environ.get('DEFAULT_DATABASE_DSN', 'sqlite://:memory:')
DATABASES = {'default': dj_database_url.parse(DEFAULT_DATABASE_DSN)}

# Password validation
# https://docs.djangoproject.com/en/3.1/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/3.1/topics/i18n/

LANGUAGE_CODE = 'en'

LANGUAGES = (
    # ('cs', 'Czech'),
    # ('nl', 'Dutch'),
    ('en', 'English'),
    # ('fr', 'French'),
    # ('de', 'German'),
    # ('el', 'Greek'),
    ('it', 'Italian'),
    ('kr', 'Korean'),
)
# LANGUAGES = sorted(LANGUAGES, key=operator.itemgetter(0))

PARLER_LANGUAGES = {
    1: (
        {'code': 'en'},
        {'code': 'it'},
        {'code': 'kr'},
    ),
    'default': {
        'fallbacks': ['en'],
        'hide_untranslated': True,   # False is the default; let .active_translations() return fallbacks too.
    }
}

ADMIN_SITE_TITLE  = 'astroEDU admin'
DEBUG_PROPAGATE_EXCEPTIONS = True

SITE_ROOT = os.path.dirname(os.path.realpath(__name__))
LOCALE_PATHS = ( os.path.join(SITE_ROOT, 'locale'), )

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

# read the setting value from the environment variable
DEFAULT_STORAGE_DSN = os.environ.get('DEFAULT_STORAGE_DSN')

# dsn_configured_storage_class() requires the name of the setting
DefaultStorageClass = dsn_configured_storage_class('DEFAULT_STORAGE_DSN')

# Django's DEFAULT_FILE_STORAGE requires the class name
DEFAULT_FILE_STORAGE = 'astroedu.settings.DefaultStorageClass'

THUMBNAIL_DEFAULT_STORAGE  = DEFAULT_FILE_STORAGE

MEDIA_URL = 'media/'
MEDIA_ROOT = os.path.join('/data/media/')

THUMBNAIL_ALIASES = {
    '': {
        'thumb': {'size': (334, 180), 'crop': True},
        'thumb2': {'size': (500, 269), 'crop': True},
        'epubcover': {'size': (800,1066), 'crop': True},
        'logo': {'size': (180, 180), 'crop': 'scale'},
        },
}

BLEACH_ALLOWED_TAGS = ('sup', 'sub', 'br', )
BLEACH_ALLOWED_ATTRIBUTES = {}
BLEACH_ALLOWED_STYLES = {}

# Mistune
MISTUNE_STYLES = {
    # 'escape': True,  # all raw html tags will be escaped.
    # 'hard_wrap': True,  # it will has GFM line breaks feature.
    'use_xhtml': True,  # all tags will be in xhtml, for example: <hr />.
    # 'parse_html': True,  # parse text in block level html.
    # 'skip_style': True,
    # 'skip_html': True,
}

MARTOR_THEME = 'semantic'

# Global martor settings
# Input: string boolean, `true/false`
MARTOR_ENABLE_CONFIGS = {
    'emoji': 'false',        # to enable/disable emoji icons.
    'imgur': 'true',        # to enable/disable imgur/custom uploader.
    'mention': 'false',     # to enable/disable mention
    'jquery': 'true',       # to include/revoke jquery (require for admin default django)
    'living': 'false',      # to enable/disable live updates in preview
    'spellcheck': 'false',  # to enable/disable spellcheck in form textareas
    'hljs': 'true',         # to enable/disable hljs highlighting in preview
}

MARTOR_MARKDOWN_EXTENSIONS = [
    'markdown.extensions.extra',
    'markdown.extensions.nl2br',
    'markdown.extensions.smarty',
    'markdown.extensions.fenced_code',
    'markdown.extensions.tables',

    # Custom markdown extensions.
    'martor.extensions.urlize',
    'martor.extensions.del_ins',      # ~~strikethrough~~ and ++underscores++
    'martor.extensions.mention',      # to parse markdown mention
    'martor.extensions.mdx_video',    # to parse embed/iframe video
]

import time
MARTOR_UPLOAD_PATH = 'images/uploads/{}'.format(time.strftime("%Y/%m/%d/"))
MARTOR_UPLOAD_URL = '/api/uploader/'  # change to local uploader
MAX_IMAGE_UPLOAD_SIZE = 5242880  # 5MB



# PAGEDOWN_IMAGE_UPLOAD_PATH = 'activities/attach/'
# PAGEDOWN_IMAGE_UPLOAD_ENABLED=True
# PAGEDOWN_IMAGE_UPLOAD_UNIQUE = True

TEMPLATE_STRING_IF_INVALID = 'temp'

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
        },
    },
    'django': {
        'handlers': ['console'],
        'level': 'DEBUG',
    },
}
Django settings for astroedu project.  Generated by 'django-admin startproject' using Django 3.1.2.  For more information on this file, see https://docs.djangoproject.com/en/3.1/topics/settings/  For the full list of settings and their values, see https://docs.djangoproject.com/en/3.1/ref/settings/ # Build paths inside the project like this: BASE_DIR / 'subdir'. # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! #ih5^uboqtn(*1n0') # SECURITY WARNING: don't run with debug turned on in production! # Application definition # Database # https://docs.djangoproject.com/en/3.1/ref/settings/#databases # Password validation # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators # Internationalization # https://docs.djangoproject.com/en/3.1/topics/i18n/ # ('cs', 'Czech'), # ('nl', 'Dutch'), # ('fr', 'French'), # ('de', 'German'), # ('el', 'Greek'), # LANGUAGES = sorted(LANGUAGES, key=operator.itemgetter(0)) # False is the default; let .active_translations() return fallbacks too. # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/3.1/howto/static-files/ # read the setting value from the environment variable # dsn_configured_storage_class() requires the name of the setting # Django's DEFAULT_FILE_STORAGE requires the class name # Mistune # 'escape': True,  # all raw html tags will be escaped. # 'hard_wrap': True,  # it will has GFM line breaks feature. # all tags will be in xhtml, for example: <hr />. # 'parse_html': True,  # parse text in block level html. # 'skip_style': True, # 'skip_html': True, # Global martor settings # Input: string boolean, `true/false` # to enable/disable emoji icons. # to enable/disable imgur/custom uploader. # to enable/disable mention # to include/revoke jquery (require for admin default django) # to enable/disable live updates in preview # to enable/disable spellcheck in form textareas # to enable/disable hljs highlighting in preview # Custom markdown extensions. # ~~strikethrough~~ and ++underscores++ # to parse markdown mention # to parse embed/iframe video # change to local uploader # 5MB # PAGEDOWN_IMAGE_UPLOAD_PATH = 'activities/attach/' # PAGEDOWN_IMAGE_UPLOAD_ENABLED=True # PAGEDOWN_IMAGE_UPLOAD_UNIQUE = True