"""
Django settings for Reskreen project.

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

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

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

from pathlib import Path
import os
from config.server_config import *

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

VERSION_FILE_PATH = os.path.join(BASE_DIR, 'VERSION')

try:
    with open(VERSION_FILE_PATH) as version_file:
        VERSION = version_file.read().strip()
except FileNotFoundError:
    VERSION = "unknown"


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



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


# Application definition
LOGIN_REDIRECT_URL = '/admin'
INSTALLED_APPS = [    
    'jazzmin',
    'django_cron',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'polls.apps.PollsConfig',
    'vehicles.apps.VehiclesConfig',
    'collabs.apps.CollabsConfig',
    'mycaldav.apps.CaldavConfig',
    'studenteval.apps.StudentevalConfig',
    'comm_op.apps.CommOpConfig',
    'custom_admin.apps.CustomAdminConfig',
    'vsl.apps.VslConfig',
    'rangefilter',
    'django.contrib.admin',
    'carnet_rouge.apps.CarnetRougeConfig',
    'django_summernote',    
    'authapp',
]

INSTALLED_APPS += ( 'apilog.apps.ApilogConfig',)
INSTALLED_APPS += ( 'corsheaders',)
'',

#Ajout de rest_framework
INSTALLED_APPS += ('rest_framework', 'rest_framework.authtoken',)
'''REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.TokenAuthentication', #Todo prod: replace by TokenAuthentication
    ),
    # Autres paramètres de configuration...
}'''
REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework.authentication.TokenAuthentication',
        'rest_framework.authentication.SessionAuthentication',
    ],
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.IsAuthenticated',
    ],
    'DEFAULT_FILTER_BACKENDS': [
        'django_filters.rest_framework.DjangoFilterBackend',
        'rest_framework.filters.OrderingFilter',
    ]
}


LANGUAGE_CODE = 'fr-CH'



MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
X_FRAME_OPTIONS = 'SAMEORIGIN'

MAX_IMAGE_PIXELS = int(1024 * 1024 * 1024 // 4 // 3)
SUMMERNOTE_THEME = 'bs4'
SUMMERNOTE_CONFIG = {
    # Using SummernoteWidget - iframe mode, default
    'iframe': True,
    'attachment_filesize_limit': 2621440 ,


    'summernote': {
            # As an example, using Summernote Air-mode
            'airMode': False,


            # Change editor size
            'width': '100%',
            'height': '480',

            # Use proper language setting automatically (default)
            'lang': "fr-FR",

            # Toolbar customization
            # https://summernote.org/deep-dive/#custom-toolbar-popover
            'toolbar': [
                ['view', ['undo','redo','fullscreen', 'codeview', 'help']],
                ['fontfamily',['fontsize']],
                ['font', ['bold', 'italic', 'underline', 'superscript', 'subscript', 'clear']],
                ['color', ['forecolor','backcolor']],
                ['para', ['ul', 'ol', 'paragraph']],
                ['table', ['table']],
                ['insert', ['link', 'picture', 'video', 'hr']],
                ['style', ['style']],
            ],
    }
}

DATA_UPLOAD_MAX_NUMBER_FIELDS = 2500


MIDDLEWARE = [
    'corsheaders.middleware.CorsMiddleware',
    '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_autologin.middleware.AutomaticLoginMiddleware',
    'language.DefaultLanguageMiddleware',
    'django.middleware.locale.LocaleMiddleware',
]

CRON_CLASSES = [
    "mycaldav.cron.InitTaskSync",    
]    


MIDDLEWARE += ('apilog.middleware.APILogMiddleware',)


ROOT_URLCONF = 'Reskreen.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [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 = 'Reskreen.wsgi.application'


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


# Password validation
# https://docs.djangoproject.com/en/4.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',
    },
]

AUTOMATIC_LOGIN_MAX_AGE = 500 * 60*60*24 # 500 jours


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


TIME_ZONE = 'Europe/Zurich'

USE_I18N = True
USE_L10N = False

USE_TZ = False

DATE_FORMAT = "d.m.Y"


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

STATIC_URL = '/static/'
LOCALE_PATHS = (os.path.join(BASE_DIR, 'locale'),)

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
]
STATIC_ROOT = "/var/www/reskreen/static"

#STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')



# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

JAZZMIN_SETTINGS = {
    # title of the window (Will default to current_admin_site.site_title if absent or None)
    "site_title": "ClercNet-Admin",

    # Title on the login screen (19 chars max) (defaults to current_admin_site.site_header if absent or None)
    "site_header": f"ClercNet {VERSION}",

    # Title on the brand (19 chars max) (defaults to current_admin_site.site_header if absent or None)
    "site_brand": f"ClercNet {VERSION}",

    # Logo to use for your site, must be present in static files, used for brand on top left
    "site_logo": "img/logo_clerc_200.png",

    # CSS classes that are applied to the logo above
    "site_logo_classes": "img-circle",

    # Relative path to a favicon for your site, will default to site_logo if absent (ideally 32x32 px)
    "site_icon": None,

    # Welcome text on the login screen
    "welcome_sign": "Bienvenue sur le ClercNet",

    # Copyright on the footer
    "copyright": f'<img src="{cfg_status_badge}"/> Ambulance Clerc & Resk-U',

    # The model admin to search from the search bar, search bar omitted if excluded
    "search_model": "auth.User",

    # Field name on user model that contains avatar ImageField/URLField/Charfield or a callable that receives the user
    "user_avatar": None,

    ############
    # Top Menu #
    ############

    # Links to put along the top menu
    "topmenu_links": [

        # Url that gets reversed (Permissions can be added)
        {"name": "Home",  "url": "admin:index", "permissions": ["auth.view_user"]},
        {"name": f'Status des serveurs',  "url": "https://status.ambulance-clerc.ch", "new_window": True},

        # external url that opens in a new window (Permissions can be added)
        #{"name": "Support", "url": "https://gitea.prod.resk-u.ch/CLERC/Reskreen/issues", "new_window": True},

        # model admin to link to (Permissions checked against model)
        {"model": "auth.User"},

        # App with dropdown menu to all its models pages (Permissions checked against models)
        {"app": "carnet_rouge"},
    ],

    #############
    # User Menu #
    #############

    # Additional links to include in the user menu on the top right ("app" url type is not allowed)
    "usermenu_links": [
        {"name": "Annonce de bug", "url": "https://gitea.prod.resk-u.ch/CLERC/Reskreen/issues", "new_window": True},
        {"name": f'Status des serveurs',  "url": "https://status.ambulance-clerc.ch", "new_window": True},
        {"model": "auth.user"}
    ],

    #############
    # Side Menu #
    #############

    # Whether to display the side menu
    "show_sidebar": True,

    # Whether to aut expand the menu
    "navigation_expanded": False,

    # Hide these apps when generating side menu e.g (auth)
    "hide_apps": [],

    # Hide these models when generating side menu (e.g auth.user)
    "hide_models": [],

    # List of apps (and/or models) to base side menu ordering off of (does not need to contain all apps/models)
    "order_with_respect_to": ["auth", "books", "books.author", "books.book"],

    # Custom links to append to app groups, keyed on app name
    "custom_links": {
        "books": [{
            "name": "Make Messages",
            "url": "make_messages",
            "icon": "fas fa-comments",
            "permissions": ["books.view_book"]
        }]
    },

    # Custom icons for side menu apps/models See https://fontawesome.com/icons?d=gallery&m=free&v=5.0.0,5.0.1,5.0.10,5.0.11,5.0.12,5.0.13,5.0.2,5.0.3,5.0.4,5.0.5,5.0.6,5.0.7,5.0.8,5.0.9,5.1.0,5.1.1,5.2.0,5.3.0,5.3.1,5.4.0,5.4.1,5.4.2,5.13.0,5.12.0,5.11.2,5.11.1,5.10.0,5.9.0,5.8.2,5.8.1,5.7.2,5.7.1,5.7.0,5.6.3,5.5.0,5.4.2
    # for the full list of 5.13.0 free icon classes
    "icons": {
        "auth": "fas fa-users-cog",
        "auth.user": "fas fa-user",
        "auth.Group": "fas fa-users",
        "vehicles": "fas fa-truck-medical",        
        "vehicles.Vehicles_infos": "fas fa-circle-info",    
        "vehicles.Vehicles": "fas fa-truck-medical",    
        "collabs": "fas fa-users",
        "collabs.Collabs_hour": "fas fa-business-time",
        "comm_op": "fas fa-user-check",
        "comm_op.comm_opMessage": "fas fa-circle-exclamation",
        "studenteval": "fas fa-graduation-cap",
    },
    # Icons that are used when one is not manually specified
    "default_icon_parents": "fas none",
    "default_icon_children": "fas fa-circle",

    #################
    # Related Modal #
    #################
    # Use modals instead of popups
    "related_modal_active": False,

    #############
    # UI Tweaks #
    #############
    # Relative paths to custom CSS/JS scripts (must be present in static files)
    "custom_css": "css/global.css",
    "custom_js": None,
    # Whether to show the UI customizer on the sidebar
    "show_ui_builder": False,

    ###############
    # Change view #
    ###############
    # Render out the change view as a single form, or in tabs, current options are
    # - single
    # - horizontal_tabs (default)
    # - vertical_tabs
    # - collapsible
    # - carousel
    "changeform_format": "horizontal_tabs",
    # override change forms on a per modeladmin basis
    "changeform_format_overrides": {"auth.user": "collapsible", "auth.group": "vertical_tabs"},
    # Add a language dropdown into the admin
    "language_chooser": False,
}

JAZZMIN_UI_TWEAKS = {
    "navbar_small_text": True,
    "footer_small_text": False,
    "body_small_text": False,
    "brand_small_text": False,
    "brand_colour": False,
    "accent": "accent-teal",
    "navbar": "navbar-dark",
    "no_navbar_border": False,
    "navbar_fixed": True,
    "layout_boxed": False,
    "footer_fixed": True,
    "sidebar_fixed": True,
    "sidebar": "sidebar-dark-info",
    "sidebar_nav_small_text": False,
    "sidebar_disable_expand": False,
    "sidebar_nav_child_indent": True,
    "sidebar_nav_compact_style": True,
    "sidebar_nav_legacy_style": False,
    "sidebar_nav_flat_style": False,
    "theme": "united",
    "dark_mode_theme": None,
    "actions_sticky_top": True,
    "button_classes": {
        "primary": "btn-primary",
        "secondary": "btn-secondary",
        "info": "btn-info",
        "warning": "btn-warning",
        "danger": "btn-danger",
        "success": "btn-success",
    },
}


# Simplified static file serving.
# https://pypi.org/project/whitenoise/
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

