"""
Django settings for project_base project.

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

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

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

import os
from django.utils.translation import ugettext_lazy as _

try:
    from .settings_local import *
except:
    pass


# SECURITY WARNING: don't run with debug turned on in production!
try:
    os.environ['django_DEBUG']
    if os.environ['django_DEBUG'] == 'True':
        DEBUG = True
    else:
        DEBUG = False
except KeyError:
    DEBUG = True


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

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

#STATIC_URL = "https://cdn.awards.mediaarchitecture.org/site_media/static/"
#MEDIA_URL = "https://cdn.awards.mediaarchitecture.org/site_media/media/"

STATIC_ROOT = os.path.join(PROJECT_ROOT, "site_media", "static")
MEDIA_ROOT = os.path.join(PROJECT_ROOT, "site_media", "media")

try:
    os.environ['django_MEDIA_URL']
    MEDIA_URL =  os.environ['django_MEDIA_URL']
except:
    MEDIA_URL = '/site_media/media/'

try:
    os.environ['django_STATIC_URL']
    STATIC_URL =  os.environ['django_STATIC_URL']
except:
    STATIC_URL = '/site_media/static/'




try:
    os.environ['django_IMPORT_PATH']
    IMPORT_PATH = os.environ['django_IMPORT_PATH']
except KeyError:
    IMPORT_PATH = '/'

try:
    os.environ['django_OLD_IMPORT_PATH']
    OLD_IMPORT_PATH = os.environ['django_OLD_IMPORT_PATH']
except KeyError:
    OLD_IMPORT_PATH = '/'

try:
    os.environ['django_TEMP_PATH']
    TEMP_PATH = os.environ['django_TEMP_PATH']
except KeyError:
    TEMP_PATH = '/'


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

# SECURITY WARNING: keep the secret key used in production secret!
try:
    os.environ['django_SECRET_KEY']
    SECRET_KEY = os.environ['django_SECRET_KEY']
except KeyError:
    SECRET_KEY = 'KsN_QZ_fWqs18Z-3o}2~z0-@NA+/lP{YwVosC>6:Gxbu>ePUw=+Gv6lIZWR'


try:
    os.environ['django_ALLOWED_HOSTS']
    ENV_ALLOWED_HOSTS = os.environ['django_ALLOWED_HOSTS']
    ALLOWED_HOSTS = []
    ALLOWED_HOSTS.extend( ENV_ALLOWED_HOSTS.split() )
except KeyError:
    ALLOWED_HOSTS = ['*']


#if DEBUG == True:
#    ALLOWED_HOSTS = ['*']
#else:
#    ALLOWED_HOSTS = ['awards.mediaarchitecture.org', 'devawards.mediaarchitecture.org', 'devcatalog.mediaarchitecture.org' 'catalog.mediaarchitecture.org', 'localhost']


# Constance settings

SPONSOR_CARDS = """
{% load static %}
<div class="mab-card card border-thin border-0 rounded-0" style="">
    <a href="https://www.mediaarchitecture.org">
        <div style="position: relative;text-align: center;">
            <img class="card-img-top rounded-0" src="{% static 'logo_end_card.jpg' %}" style=" " alt="image">
        </div>
    </a>
    <div class="card-body" style="padding: 5px">
        <div class="border-0 d-flex justify-content">
            <p class="card-title"><a href="{% static 'MAB2018logo.png' %}">MAI<br>MAI Sponsor - YEAR, CITY, COUNTRY<br></a></p>
        </div>
        <p class="card-text" style="color: black; margin-top:0px">
            <a href="https://www.mediaarchitecture.org">
                <nobr>
                    <button class="border-thin mybtn" style="margin-right: 2px;margin-bottom: 2px">#MAB</button>
                </nobr>
            </a>
            <a href="">
                <nobr>
                    <button class="border-thin mybtn" style="margin-right: 2px;margin-bottom: 2px">#Sponsor</button>
                </nobr>
            </a>
            <a href="https://www.mediaarchitecture.org">
                <nobr>
                    <button class="border-thin mybtn" style="margin-right: 2px;margin-bottom: 2px">#NAME</button>
                </nobr>
            </a>
        </p>
    </div>
</div>
"""

ABOUT_TEXT = """
  {% load static %}
<p>Marktplatz </p>
<p>&nbsp;</p>
<p>Unsere Sponsoren:<br />- -</p>
<p>Systementwickler<br />- -</p>
<p>Dies ist eine Website von</p>
<p>RealityLab</p>
<p>Gisela Legath-Gasse 5/1<br />1220 Wien - &Ouml;sterreich<br />www.realitylab.at<br />office@realitylab.at</p>
<p>Bitte beachten Sie unsere Datenschutzbestimmungen:<br />https://www.realitylab.at/privacy-policy/</p>
"""

MAIN_CARD = """
  {% load static %}
  <div class="card rounded-0 border-0" style="width: 97%; height: 95%; display:inline-block; margin-top:4px; max-width: 100%">
    <a href="">
      <div style="position: relative;text-align: center;">
        <img class="card-img-top rounded-0" src="{% static 'main_card_pic.png' %}" alt="image">
        <div style="position: absolute;bottom: 8px;left: 16px;color: white; font-size: medium; font-weight: bold; text-align: left;background-color: rgba(0,0,0,0.21)">Title</div>
      </div>
    </a>
    <div class="card-body" style="padding: 5px">
      <div class="border-0 d-flex justify-content">
        <p class="card-title" style="margin-bottom: 3px"><a href=""> Header </a></p>
      </div>
      <p class="card-text" style="color: black;margin-top: 0px">
        <button id='' class="border-thin mybtn" style="">Tag A</button>
        <button id='' class="border-thin mybtn" style="">Tag B</button>
        <button id='' class="border-thin mybtn" style="">Tag C</button>
      </p>
    </div>
  </div>
  """

INFO_TXT = """
<p>Bitte beachten Sie:</p>
<p>F&uuml;llen Sie so viele Felder wie m&ouml;glich aus.<br /> Pflichtfelder sind mit einem Sternchen gekennzeichnet*.</p>
"""

SUBMIT_TEXT = """
<p><br />Wir m&ouml;chten uns bei unseren Sponsoren bedanken:</p>
<p>Sponsoren</p>
"""

CONSTANCE_ADDITIONAL_FIELDS = {
    'image_field': ['django.forms.ImageField', {}]
}

CONSTANCE_BACKEND = 'constance.backends.database.DatabaseBackend'
CONSTANCE_CONFIG = {
    'ABOUT_CONTENT': (ABOUT_TEXT, 'Text for the about page'),
    'SPONSOR_CARDS': (SPONSOR_CARDS, 'HTML for the sponsor cards'),
    'MAIN_CARD':     (MAIN_CARD, 'HTML for the main card'),
    'CURRENT_EVENT': ('MAB20', 'Filter for the projects that should be evaluated'),
    'INFO_TXT': (INFO_TXT, 'Text to help with the fill in the submitform'),
    'SUBMIT_TEXT': (SUBMIT_TEXT, 'Text to welcome to the submitpage'),
    'IMPRESSUM': ('Impressum text.', 'Impressum'),
    'TEILNAHME': ('Teilnahmebedingungen text.', 'Teilnahmebedingungen'),
    'DATENSCHUTZRICHTLINIE': ('Datenschutzrichtlinie text.', 'Datenschutzrichtlinie'),
    'WEITERFUEHRENDES': ('-', 'Weiterführendes'),
    'INFO': ('-', 'Info'),
    'ADMIN_EMAIL': ('juan@mediaarchitecture.org', 'Admin email'),
    'WEBSITE_TITEL': ('Markplatz', 'Name von der Webseite'),
    'WEBSEITE_URI': ('gemeinschaffen.com', 'Url von der Webseite, zB. gemeinschaffen.com'),
    'LOGO_IMAGE': ('logo.png', 'Company logo', 'image_field'),
    'EMAIL_NOREPLY' : ('no-reply@gemeinschaffen.com', 'No-reply email')
}


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    # 'django.contrib.auth',
    'project_base.apps.AuthConfigBase',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'marktplatz.apps.marktplatzConfig',
    #'constance',
    'project_base.apps.ConstanceBase',
    'constance.backends.database',
    'sorl.thumbnail',
    'newsletter',
    'django_crontab',
    'imagekit',
    'tinymce',
    'multiselectfield',
    'crispy_forms',
    'django_file_form',
    'django_file_form.ajaxuploader',
    'django_countries',
    'captcha',
    'debug_toolbar',
    'fullurl',
    'django_user_agents',
    'email_obfuscator',
    'compressor',
    'csvexport',

    'project_base.apps.PostOfficeBase',
    'project_base.apps.project_base',
]

SETTINGS_EXPORT = [
    'DEBUG',
]

SITE_ID = 1



NEWSLETTER_CONFIRM_EMAIL_UNSUBSCRIBE = False
NEWSLETTER_RICHTEXT_WIDGET = "tinymce.widgets.TinyMCE"
# Amount of seconds to wait between each email. Here 100ms is used.
NEWSLETTER_EMAIL_DELAY = 0.2
# Amount of seconds to wait between each batch. Here one minute is used.
NEWSLETTER_BATCH_DELAY = 60
# Number of emails in one batch
NEWSLETTER_BATCH_SIZE = 100


CRONJOBS = [
    ('*/5 * * * *', 'django.core.management.call_command', ['submit_newsletter', ], {}, '>   /dev/null 2>&1' ), #> /dev/null 2>&1
    ('*/5 * * * *', 'django.core.management.call_command', ['send_queued_mail'], {}, '> /dev/null 2>&1'  ), #'> /dev/null 2>&1'
    ('*/10 * * * *', 'marktplatz.signals.process_triggers', [''], {},  ), #'> /dev/null 2>&1'
]

CRISPY_TEMPLATE_PACK = 'bootstrap4'

CAPTCHA_NOISE_FUNCTIONS=('captcha.helpers.noise_dots',)
CAPTCHA_LETTER_ROTATION=(-15,15)

INTERNAL_IPS = [
    # ...
    '127.0.0.1',
    # ...
]

# for compressor
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    # other finders..
    'compressor.finders.CompressorFinder',
)

COMPRESS_ENABLED = True

#
#
#
# CACHES = {
#     'default': {
#         'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
#         'LOCATION': '127.0.0.1:11211',
#     }
# }
#
# USER_AGENTS_CACHE = 'default'

MIDDLEWARE = [
    'debug_toolbar.middleware.DebugToolbarMiddleware',

    '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_user_agents.middleware.UserAgentMiddleware',
    'htmlmin.middleware.HtmlMinifyMiddleware',
    'htmlmin.middleware.MarkRequestMiddleware',
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',

]

# 'htmlmin.middleware.HtmlMinifyMiddleware',
#  'htmlmin.middleware.MarkRequestMiddleware',


ROOT_URLCONF = 'project_base.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(PACKAGE_ROOT, "templates"),'./templates','./project_base', ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'constance.context_processors.config',
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'django_settings_export.settings_export',
            ],
        },
    },
]

WSGI_APPLICATION = 'project_base.wsgi.application'

#EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
EMAIL_BACKEND = 'post_office.EmailBackend'

LOGIN_REDIRECT_URL = '/gem/home/'
LOGOUT_REDIRECT_URL = 'products'


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

try:
    os.environ['django_DB_ENGINE']
    DB_ENGINE  = os.environ['django_DB_ENGINE']
except KeyError:
    DB_ENGINE = 'django.db.backends.sqlite3'

try:
    os.environ['django_DB_NAME']
    DB_NAME  = os.environ['django_DB_NAME']
except KeyError:
    DB_NAME = os.path.join(BASE_DIR, 'db.sqlite3')

try:
    os.environ['django_DB_USER']
    DB_USER  = os.environ['django_DB_USER']
except KeyError:
    DB_USER = ''

try:
    os.environ['django_DB_PASSWORD']
    DB_PASSWORD  = os.environ['django_DB_PASSWORD']
except KeyError:
    DB_PASSWORD = ''

try:
    os.environ['django_DB_HOST']
    DB_HOST  = os.environ['django_DB_HOST']
except KeyError:
    DB_HOST = ''

try:
    os.environ['django_DB_PORT']
    DB_PORT  = os.environ['django_DB_PORT']
except KeyError:
    DB_PORT = ''

if DB_ENGINE == "django.db.backends.mysql" :
    DB_OPTIONS = {'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"}
else:
    DB_OPTIONS = {}

DATABASES = {
    "default": {
        "ENGINE": DB_ENGINE,
        "NAME":  DB_NAME,
        "USER":  DB_USER,
        "PASSWORD":  DB_PASSWORD,
        "HOST":  DB_HOST,
        "PORT":  DB_PORT,
        "OPTIONS" : DB_OPTIONS
    }
}


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

AUTH_PASSWORD_VALIDATORS = [
    # {
    #     'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    # },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
        'OPTIONS': {
            'min_length': 16,
        }
    },
    # {
    #     'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    # },
    # {
    #     'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    # },
]


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

LANGUAGE_CODE = 'de'


# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = "Europe/Vienna"

LANGUAGES = (
    # ('en', _('English') ),
    ('de', _('German') ),
)


DATE_INPUT_FORMATS = [
    '%d.%m.%Y', '%d/%m/%Y', '%d-%m-%Y', # '2006-10-25', '10/25/2006', '10/25/06'
    #'%d %b %Y', '%d %b, %Y',            # '25 Oct 2006', '25 Oct, 2006'
    #'%d %B %Y', '%d %B, %Y',            # '25 October 2006', '25 October, 2006'
]

DATE_FORMAT = '%d.%m.%Y'

# Tell Django where the project's translation files should be.
LOCALE_PATHS = (
    os.path.join(PROJECT_ROOT, "locale"),
)


USE_I18N = True

USE_L10N = True

USE_TZ = True



#MAIL

try:
    os.environ['django_DEFAULT_FROM_EMAIL']
    DEFAULT_FROM_EMAIL =  os.environ['django_DEFAULT_FROM_EMAIL']
except:
    DEFAULT_FROM_EMAIL = 'webmaster@localhost'

try:
    os.environ['django_EMAIL_BACKEND']
    EMAIL_BACKEND = os.environ['django_EMAIL_BACKEND']
except KeyError:
    EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

try:
    os.environ['django_EMAIL_HOST']
    EMAIL_HOST = os.environ['django_EMAIL_HOST']
except KeyError:
    EMAIL_HOST = ''

try:
    os.environ['django_EMAIL_HOST_USER']
    EMAIL_HOST_USER =  os.environ['django_EMAIL_HOST_USER']
except:
    EMAIL_HOST_USER = ''

try:
    os.environ['django_EMAIL_HOST_PASSWORD']
    EMAIL_HOST_PASSWORD  = os.environ['django_EMAIL_HOST_PASSWORD']
except KeyError:
    EMAIL_HOST_PASSWORD = ''

try:
    os.environ['django_EMAIL_PORT']
    EMAIL_PORT = os.environ['django_EMAIL_PORT']
except KeyError:
    EMAIL_PORT = ''

try:
    os.environ['django_EMAIL_USE_SSL']
    if os.environ['django_EMAIL_USE_SSL'] == 'True' :
        EMAIL_USE_SSL = True
    else:
        EMAIL_USE_SSL = False
except KeyError:
    EMAIL_USE_SSL = False
