"""
Django settings for kaznet project.

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

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

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '<KEY>'

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

ALLOWED_HOSTS = []
KAZNET_DEFAULT_CURRENCY = 'KES'

# Application definition

APP_NAME = 'Kaznet'

INSTALLED_APPS = [
    # core django
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    # whitenoice
    'whitenoise.runserver_nostatic',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.gis',
    # third party
    'rest_framework',
    'rest_framework.authtoken',
    'django_prices',
    'django_filters',
    'rest_framework_gis',  # Required for CountryField in Location Model
    'django_countries',  # Required for CountryField in Location Model
    'mptt',
    'phonenumber_field',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth_onadata',
    'corsheaders',
    'crispy_forms',
    # custom apps
    'kaznet.apps.ona',
    'kaznet.apps.main.apps.MainConfig',
    'kaznet.apps.users.apps.UsersConfig',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'corsheaders.middleware.CorsMiddleware',
    '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',
]

ROOT_URLCONF = 'kaznet.urls'

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
    }
}

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',
                "kaznet.apps.main.context_processors.kaznet_processor",
            ],
        },
    },
]

AUTHENTICATION_BACKENDS = (
    # Needed to login by username in Django admin, regardless of `allauth`
    'django.contrib.auth.backends.ModelBackend',
    # `allauth` specific authentication methods, such as login by e-mail
    'allauth.account.auth_backends.AuthenticationBackend',
)

WSGI_APPLICATION = 'kaznet.wsgi.application'
SITE_ID = 1

# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'HOST': os.environ.get('KAZNET_POSTGRES_HOST', 'postgres'),
        'NAME':  os.environ.get('KAZNET_POSTGRES_NAME', 'kaznet'),
        'USER': os.environ.get('KAZNET_POSTGRES_USER', 'kaznet'),
        'PASSWORD': os.environ.get('KAZNET_POSTGRES_PASSWORD', '<PASSWORD>')
    }
}

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

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME':
        'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',  # noqa
    },
    {
        '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/2.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Africa/Nairobi'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
]

# Authentication
TEMP_TOKEN_TIMEOUT = 14400

# Onadata
ONA_BASE_URL = 'https://stage-api.ona.io'
ONA_CROSS_AUTHENTICATION_URL = 'https://stage-api.ona.io/api/v1/user'
ONA_USERNAME = 'kaznettest'
ONA_ORG_NAME = 'kaznettest'
ONA_PASSWORD = '<PASSWORD>'
ONA_MEMBERS_TEAM_ID = 102
ONA_STATUS_FIELD = '_review_status'
ONA_COMMENTS_FIELD = '_review_comment'
ONA_LAST_PASSWORD_EDIT_FIELD = 'last_password_edit'
ONA_GEOLOCATION_FIELD = '_geolocation'
SUBMISSION_AUTO_APPROVAL = False
ONA_SUBMISSION_REVIEW_APPROVED = '1'
ONA_SUBMISSION_REVIEW_REJECTED = '2'
ONA_SUBMISSION_REVIEW_PENDING = '3'
ONA_OWNER_ROLE = "owner"
ONA_CONTRIBUTER_ROLE = "dataentry"
ONA_MANAGER_ROLE = "manager"
ONA_EDITOR_ROLE = "editor"
ONA_XFORM_CONFIGURED_FIELD = "configuration_status"
# Texts
ONA_LOGIN_TEXT = 'Log In With Your Ona Account'

# Allauth
ACCOUNT_AUTHENTICATION_METHOD = "username_email"
ACCOUNT_EMAIL_REQUIRED = False
ACCOUNT_ADAPTER = "kaznet.apps.users.adapter.AccountAdapter"
ACCOUNT_PRESERVE_USERNAME_CASING = False
ACCOUNT_UNIQUE_EMAIL = True
ALLAUTH_ONA_SCOPE = ['read', 'write']
ALLAUTH_ONA_BASE_URL = ONA_BASE_URL
ACCOUNT_LOGOUT_ON_GET = True

SOCIALACCOUNT_ADAPTER = "kaznet.apps.users.adapter.SocialAccountAdapter"

# CELERY
CELERY_BROKER_URL = 'redis://redis:6379/0'
CELERY_RESULT_BACKEND = 'redis://redis:6379/1'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = 'Africa/Nairobi'

CELERY_BEAT_SCHEDULE = {}

# JSON API
REST_FRAMEWORK = {
    'PAGE_SIZE': 20,
    'EXCEPTION_HANDLER':
        'rest_framework_json_api.exceptions.exception_handler',
    'DEFAULT_PAGINATION_CLASS':
        'rest_framework_json_api.pagination.PageNumberPagination',
    'DEFAULT_PARSER_CLASSES': (
        'rest_framework_json_api.parsers.JSONParser',
        'rest_framework.parsers.FormParser',
        'rest_framework.parsers.MultiPartParser'
    ),
    'DEFAULT_RENDERER_CLASSES': (
        'rest_framework_json_api.renderers.JSONRenderer',
        # If you're performance testing, you will want to use the browseable
        # API without forms, as the forms can generate their own queries.
        # If performance testing, enable:
        # 'example.utils.BrowsableAPIRendererWithoutForms',
        # Otherwise, to play around with the browseable API, enable:
        # 'rest_framework.renderers.BrowsableAPIRenderer'
    ),
    'DEFAULT_METADATA_CLASS':
        'rest_framework_json_api.metadata.JSONAPIMetadata',
}

# Exports
EXPORT_FILENAME = "download"

# Tasking
TASKING_ALLOWED_CONTENTTYPES = [
    {'app_label': 'ona', 'model': 'xform'},
    {'app_label': 'ona', 'model': 'instance'}
]
TASKING_CHECK_NUMBER_OF_FILES_IN_SHAPEFILES_DIR = False
TASKING_SHAPEFILE_IGNORE_INVALID_TYPES = True
TASKING_SHAPEFILE_ALLOW_NESTED_MULTIPOLYGONS = True

# XForms
AUTO_CREATE_SUBMISSION_WEBHOOKS = True
AUTO_CREATE_FILTERED_DATASETS = False

# crispy forms
CRISPY_TEMPLATE_PACK = 'bootstrap4'

# try and load local_settings if present
try:
    # pylint: disable=wildcard-import
    # pylint: disable=unused-wildcard-import
    from .local_settings import *  # noqa
except ImportError:
    pass

"""
Django settings for kaznet project.

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

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

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '<KEY>'

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

ALLOWED_HOSTS = []
KAZNET_DEFAULT_CURRENCY = 'KES'

# Application definition

APP_NAME = 'Kaznet'

INSTALLED_APPS = [
    # core django
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    # whitenoice
    'whitenoise.runserver_nostatic',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.gis',
    # third party
    'rest_framework',
    'rest_framework.authtoken',
    'django_prices',
    'django_filters',
    'rest_framework_gis',  # Required for CountryField in Location Model
    'django_countries',  # Required for CountryField in Location Model
    'mptt',
    'phonenumber_field',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth_onadata',
    'corsheaders',
    'crispy_forms',
    # custom apps
    'kaznet.apps.ona',
    'kaznet.apps.main.apps.MainConfig',
    'kaznet.apps.users.apps.UsersConfig',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'corsheaders.middleware.CorsMiddleware',
    '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',
]

ROOT_URLCONF = 'kaznet.urls'

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
    }
}

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',
                "kaznet.apps.main.context_processors.kaznet_processor",
            ],
        },
    },
]

AUTHENTICATION_BACKENDS = (
    # Needed to login by username in Django admin, regardless of `allauth`
    'django.contrib.auth.backends.ModelBackend',
    # `allauth` specific authentication methods, such as login by e-mail
    'allauth.account.auth_backends.AuthenticationBackend',
)

WSGI_APPLICATION = 'kaznet.wsgi.application'
SITE_ID = 1

# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'HOST': os.environ.get('KAZNET_POSTGRES_HOST', 'postgres'),
        'NAME':  os.environ.get('KAZNET_POSTGRES_NAME', 'kaznet'),
        'USER': os.environ.get('KAZNET_POSTGRES_USER', 'kaznet'),
        'PASSWORD': os.environ.get('KAZNET_POSTGRES_PASSWORD', '<PASSWORD>')
    }
}

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

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME':
        'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',  # noqa
    },
    {
        '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/2.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Africa/Nairobi'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
]

# Authentication
TEMP_TOKEN_TIMEOUT = 14400

# Onadata
ONA_BASE_URL = 'https://stage-api.ona.io'
ONA_CROSS_AUTHENTICATION_URL = 'https://stage-api.ona.io/api/v1/user'
ONA_USERNAME = 'kaznettest'
ONA_ORG_NAME = 'kaznettest'
ONA_PASSWORD = '<PASSWORD>'
ONA_MEMBERS_TEAM_ID = 102
ONA_STATUS_FIELD = '_review_status'
ONA_COMMENTS_FIELD = '_review_comment'
ONA_LAST_PASSWORD_EDIT_FIELD = 'last_password_edit'
ONA_GEOLOCATION_FIELD = '_geolocation'
SUBMISSION_AUTO_APPROVAL = False
ONA_SUBMISSION_REVIEW_APPROVED = '1'
ONA_SUBMISSION_REVIEW_REJECTED = '2'
ONA_SUBMISSION_REVIEW_PENDING = '3'
ONA_OWNER_ROLE = "owner"
ONA_CONTRIBUTER_ROLE = "dataentry"
ONA_MANAGER_ROLE = "manager"
ONA_EDITOR_ROLE = "editor"
ONA_XFORM_CONFIGURED_FIELD = "configuration_status"
# Texts
ONA_LOGIN_TEXT = 'Log In With Your Ona Account'

# Allauth
ACCOUNT_AUTHENTICATION_METHOD = "username_email"
ACCOUNT_EMAIL_REQUIRED = False
ACCOUNT_ADAPTER = "kaznet.apps.users.adapter.AccountAdapter"
ACCOUNT_PRESERVE_USERNAME_CASING = False
ACCOUNT_UNIQUE_EMAIL = True
ALLAUTH_ONA_SCOPE = ['read', 'write']
ALLAUTH_ONA_BASE_URL = ONA_BASE_URL
ACCOUNT_LOGOUT_ON_GET = True

SOCIALACCOUNT_ADAPTER = "kaznet.apps.users.adapter.SocialAccountAdapter"

# CELERY
CELERY_BROKER_URL = 'redis://redis:6379/0'
CELERY_RESULT_BACKEND = 'redis://redis:6379/1'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = 'Africa/Nairobi'

CELERY_BEAT_SCHEDULE = {}

# JSON API
REST_FRAMEWORK = {
    'PAGE_SIZE': 20,
    'EXCEPTION_HANDLER':
        'rest_framework_json_api.exceptions.exception_handler',
    'DEFAULT_PAGINATION_CLASS':
        'rest_framework_json_api.pagination.PageNumberPagination',
    'DEFAULT_PARSER_CLASSES': (
        'rest_framework_json_api.parsers.JSONParser',
        'rest_framework.parsers.FormParser',
        'rest_framework.parsers.MultiPartParser'
    ),
    'DEFAULT_RENDERER_CLASSES': (
        'rest_framework_json_api.renderers.JSONRenderer',
        # If you're performance testing, you will want to use the browseable
        # API without forms, as the forms can generate their own queries.
        # If performance testing, enable:
        # 'example.utils.BrowsableAPIRendererWithoutForms',
        # Otherwise, to play around with the browseable API, enable:
        # 'rest_framework.renderers.BrowsableAPIRenderer'
    ),
    'DEFAULT_METADATA_CLASS':
        'rest_framework_json_api.metadata.JSONAPIMetadata',
}

# Exports
EXPORT_FILENAME = "download"

# Tasking
TASKING_ALLOWED_CONTENTTYPES = [
    {'app_label': 'ona', 'model': 'xform'},
    {'app_label': 'ona', 'model': 'instance'}
]
TASKING_CHECK_NUMBER_OF_FILES_IN_SHAPEFILES_DIR = False
TASKING_SHAPEFILE_IGNORE_INVALID_TYPES = True
TASKING_SHAPEFILE_ALLOW_NESTED_MULTIPOLYGONS = True

# XForms
AUTO_CREATE_SUBMISSION_WEBHOOKS = True
AUTO_CREATE_FILTERED_DATASETS = False

# crispy forms
CRISPY_TEMPLATE_PACK = 'bootstrap4'

# try and load local_settings if present
try:
    # pylint: disable=wildcard-import
    # pylint: disable=unused-wildcard-import
    from .local_settings import *  # noqa
except ImportError:
    pass

Django settings for kaznet project.  Generated by 'django-admin startproject' using Django 2.0.5.  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/ # 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.0/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 # core django # whitenoice # third party # Required for CountryField in Location Model # Required for CountryField in Location Model # custom apps # Needed to login by username in Django admin, regardless of `allauth` # `allauth` specific authentication methods, such as login by e-mail # Database # https://docs.djangoproject.com/en/2.0/ref/settings/#databases # Password validation # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators # noqa # Internationalization # https://docs.djangoproject.com/en/2.0/topics/i18n/ # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.0/howto/static-files/ # Authentication # Onadata # Texts # Allauth # CELERY # JSON API # If you're performance testing, you will want to use the browseable # API without forms, as the forms can generate their own queries. # If performance testing, enable: # 'example.utils.BrowsableAPIRendererWithoutForms', # Otherwise, to play around with the browseable API, enable: # 'rest_framework.renderers.BrowsableAPIRenderer' # Exports # Tasking # XForms # crispy forms # try and load local_settings if present # pylint: disable=wildcard-import # pylint: disable=unused-wildcard-import # noqa