"""
Generated by 'django-admin startproject' using Django 1.8.2.
"""

import os
import sys
import json

CONF_DIR = os.path.dirname(os.path.abspath(__file__))
BASE_DIR = os.path.dirname(CONF_DIR)
CONF_DIR_NAME = os.path.relpath(CONF_DIR, BASE_DIR)
PROJECT_NAME = "IW16"
PROJECT_TITLE = "Internet Whirlwind 2016"

# Quick-start development settings - unsuitable for production
try:
	sk_fobj = open(os.path.join(CONF_DIR, "secret", "secret_key.txt"))
	SECRET_KEY = sk_fobj.read().strip()
	sk_fobj.close()
except OSError:
	SECRET_KEY = "a9w*6qa8)-)og5l+w1u+sx#6zkav!@u^ev1*1=!$&jr=lh1b1_"
DEBUG = True
ALLOWED_HOSTS = ["*"]


# Application definition

INSTALLED_APPS = (
	"django.contrib.admin",
	"django.contrib.auth",
	"django.contrib.contenttypes",
	"django.contrib.sessions",
	"django.contrib.messages",
	"django.contrib.staticfiles",
	"main",
)

MIDDLEWARE_CLASSES = (
	"django.contrib.sessions.middleware.SessionMiddleware",
	"django.middleware.common.CommonMiddleware",
	"django.middleware.csrf.CsrfViewMiddleware",
	"django.contrib.auth.middleware.AuthenticationMiddleware",
	"django.contrib.auth.middleware.SessionAuthenticationMiddleware",
	"django.contrib.messages.middleware.MessageMiddleware",
	"django.middleware.clickjacking.XFrameOptionsMiddleware",
	"django.middleware.security.SecurityMiddleware",
)

ROOT_URLCONF = CONF_DIR_NAME+".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",
				CONF_DIR_NAME+".settings_processor.settings_processor",
			],
		},
	},
]

WSGI_APPLICATION = CONF_DIR_NAME+".wsgi.application"


# Database

try:
	db_file = open(os.path.join(CONF_DIR, "secret", "db.json"))
	DATABASES = json.load(db_file)
	db_file.close()
except (OSError, ValueError):
	print("Falling back to sqlite3", file=sys.stderr)
	DATABASES = {
		"default": {
			"ENGINE": "django.db.backends.sqlite3",
			"NAME": os.path.join(BASE_DIR, "sqlite3.db"),
		}
	}


# Internationalization

LANGUAGE_CODE = "en-us"
TIME_ZONE = "Asia/Kolkata"
USE_I18N = True
USE_L10N = True
USE_TZ = True


# Static files (CSS, JavaScript, Images)

STATIC_URL = "/static/"
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

# Admin

from django.contrib import admin
admin.site.site_header = PROJECT_TITLE + " admin site"
admin.site.site_title = PROJECT_NAME + " admin site"
admin.site.site_url = STATIC_URL + "index.html"
admin.site.index_title = "App Index"

# Misc

from datetime import datetime, timedelta
from django.utils import timezone
from collections import OrderedDict

if DEBUG:
	JSON_INDENT_LEVEL = 2
	DICT_TYPE = OrderedDict
else:
	JSON_INDENT_LEVEL = None
	DICT_TYPE = dict

TIME_PENALTY_S = 60
# Number of seconds to be added to player's total time.

BASE_DATETIME = timezone.now()
#BASE_DATETIME = datetime(2016, 2, 23, 18, 5, 0, 0, tzinfo=timezone.utc)	# 11:35 pm at 23-2-2016 in IST
# datetime used to calculate total time of a user

LDRBRD_PAGE_SIZE = 20
