"""
Django settings for backend project.

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

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

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

import os
import datetime

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'zf=4us9w6fb3@-b@$pp%8p2c(uo8=b7wyczk9v)o_ai4#34(5y'

# SECURITY WARNING: don't run with debug turned on in production!
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',
    'django.contrib.admindocs',
    'rest_framework',
    'rest_framework.authtoken',
    'social.apps.django_app.default', # support python-social-auth for fb, google+, linkedin login
    'corsheaders',
    'rest_auth',
    'rest_auth.registration',
	'rest_framework_swagger',
    'django_nose',
    'rest_framework_jwt',
    'daterange_filter',
    # 'dbsnapshot',
    # 'djcelery',
    'API',
    'users',
    'listing',
    'finance',
    'support',
    'booking',
]

MIDDLEWARE_CLASSES = [
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.admindocs.middleware.XViewMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'corsheaders.middleware.CorsMiddleware',
    'social.apps.django_app.middleware.SocialAuthExceptionMiddleware',
]

AUTHENTICATION_BACKENDS = (
    'social.backends.open_id.OpenIdAuth',
    'social.backends.google.GoogleOAuth2',
    'social.backends.google.GooglePlusAuth',
    'social.backends.twitter.TwitterOAuth',
    'social.backends.facebook.FacebookOAuth2',
    'social.backends.linkedin.LinkedinOAuth2',
    'social.backends.linkedin.LinkedinOAuth',
    'django.contrib.auth.backends.ModelBackend',
)

# Facebook login integration settings
# based on goryd app generated by Shubham Yadav
SOCIAL_AUTH_FACEBOOK_KEY = '1733993156848206'
SOCIAL_AUTH_FACEBOOK_SECRET = 'de529f6029d5d15f65252cd994693d9b'
# Following is added to get extra permissions from facebook, for e.g. to get email
SOCIAL_AUTH_FACEBOOK_SCOPE = [
    'email',
    'user_birthday',
]
# To pass extra parameters when gathering the user profile data. Ask for fields like email, id using fields key
SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {
  'fields': 'id, name, email, age_range'
}

# Google login integration settings
# based on goryd app generated by Shubham Yadav
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = '410728656599-td0bkdem8stj02udfktaisq0nqhnif8i.apps.googleusercontent.com'
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = 'YL-BipZ2gn-lrTGm3B-kg4PA'
SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = [
    'https://www.googleapis.com/auth/plus.login',
    'https://www.googleapis.com/auth/plus.profile.emails.read',
    'https://www.googleapis.com/auth/plus.me',
]
SOCIAL_AUTH_GOOGLE_PLUS_KEY = SOCIAL_AUTH_GOOGLE_OAUTH2_KEY
SOCIAL_AUTH_GOOGLE_PLUS_SECRET = SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET
SOCIAL_AUTH_GOOGLE_PLUS_SCOPE = [
    'https://www.googleapis.com/auth/plus.login',
    'https://www.googleapis.com/auth/plus.profile.emails.read',
    'https://www.googleapis.com/auth/plus.me',
]

#twitter
SOCIAL_AUTH_TWITTER_KEY = '4tVwfEqR5vMIMYaPFzpNBqBjV'
SOCIAL_AUTH_TWITTER_SECRET = 'S41wtfu9UbVBuT3ymOEG0ntvgXbtKxmt5CpluFD7iJM5j5fL4p'

#linkedin
SOCIAL_AUTH_LINKEDIN_OAUTH2_KEY = '75pgoj9bsvpip4'
SOCIAL_AUTH_LINKEDIN_OAUTH2_SECRET = 'xmTzCVDurTMj6NBD'
SOCIAL_AUTH_LINKEDIN_SCOPE = ['r_basicprofile', 'r_emailaddress']
SOCIAL_AUTH_LINKEDIN_FIELD_SELECTORS = ['email-address']
SOCIAL_AUTH_LINKEDIN_EXTRA_DATA = [('id', 'id'),
                                   ('firstName', 'first_name'),
                                   ('lastName', 'last_name'),
                                   ('emailAddress', 'email_address'),
                                   ('pictureUrl', 'picture-url'),
                                   ]

SOCIAL_AUTH_LINKEDIN_KEY = '75pgoj9bsvpip4'
SOCIAL_AUTH_LINKEDIN_SECRET = 'xmTzCVDurTMj6NBD'
SOCIAL_AUTH_LINKEDIN_SCOPE = ['r_basicprofile', 'r_emailaddress']
SOCIAL_AUTH_LINKEDIN_FIELD_SELECTORS = ['email-address']
SOCIAL_AUTH_LINKEDIN_EXTRA_DATA = [('id', 'id'),
                                   ('firstName', 'first_name'),
                                   ('lastName', 'last_name'),
                                   ('emailAddress', 'email_address'),
                                   ('pictureUrl', 'picture-url'),
                                   ]

# for details regarding SOCIAL_AUTH_PIPELINE, see http://psa.matiasaguirre.net/docs/pipeline.html
SOCIAL_AUTH_PIPELINE = (
    'social.pipeline.social_auth.social_details',
    'social.pipeline.social_auth.social_uid',
    'social.pipeline.social_auth.auth_allowed',
    'social.pipeline.social_auth.social_user',
    'social.pipeline.user.create_user',
    'API.pipeline.save_profile',
    'social.pipeline.social_auth.associate_user',
    'social.pipeline.social_auth.load_extra_data',
    'social.pipeline.user.user_details',
)

SOCIAL_AUTH_ADMIN_USER_SEARCH_FIELDS = ['username', 'first_name', 'email']

ROOT_URLCONF = 'backend.urls'

# change this to www.goryd.in in production
LOGIN_REDIRECT_URL = 'http://example2.com:8005'
LOGIN_URL = LOGIN_REDIRECT_URL #if the user is inactive. Login unsuccessful.

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(BASE_DIR, 'templates', 'mail', 'welcome'),
            os.path.join(BASE_DIR, 'templates', 'mail', 'registration'),
            os.path.join(BASE_DIR, 'templates', 'mail', 'booking'),
            os.path.join(BASE_DIR, 'templates', 'mail', 'payment'),
            os.path.join(BASE_DIR, 'templates', 'mail', 'support'),
        ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.template.context_processors.i18n',
                'django.template.context_processors.media',
                'django.template.context_processors.static',
                'django.template.context_processors.tz',
                'django.contrib.messages.context_processors.messages',
                'social.apps.django_app.context_processors.backends',
                'social.apps.django_app.context_processors.login_redirect',
            ],
        },
    },
]

WSGI_APPLICATION = 'backend.wsgi.application'

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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Asia/Kolkata'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

STATIC_URL = '/static/'
CORS_ORIGIN_ALLOW_ALL = True

CORS_ALLOW_HEADERS = (
    'x-requested-with',
    'content-type',
    'accept',
    'origin',
    'authorization'
    )

CORS_ALLOW_CREDENTIALS = True

STATIC_ROOT = (
    os.path.join(BASE_DIR , 'static_root')
)
STATICFILES_DIRS = (
   os.path.join(BASE_DIR , 'static_shared'),
)
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR , 'media_root')


REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
        'rest_framework.authentication.BasicAuthentication',
        'rest_framework.authentication.SessionAuthentication',
    ),
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
    'DEFAULT_METADATA_CLASS': 'rest_framework.metadata.SimpleMetadata',
    'DEFAULT_RENDERER_CLASSES': ('rest_framework.renderers.JSONRenderer',),
}

JWT_AUTH = {
    'JWT_SECRET_KEY': SECRET_KEY,
    # Token expiration time
    'JWT_EXPIRATION_DELTA': datetime.timedelta(days=1),
    # To issue a new brand tokens, with renewed expiration time, in exchange of non-expired tokens
    # Enable token refresh functionality
    'JWT_ALLOW_REFRESH': True,
    # the time till which, token refresh is allowed from origin token
    'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(days=7),
    'JWT_AUTH_HEADER_PREFIX': 'JWT',
}

# Email settings
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_SSL = True
EMAIL_HOST = 'mail.goryd.in'
EMAIL_PORT = 465
EMAIL_HOST_USER = 'support@goryd.in'
EMAIL_HOST_PASSWORD = 'password'

# SMS settings
SMS_LOGIN_USER = 'userid'
SMS_LOGIN_PASSWORD = 'password'

# Google maps API key for distance matrix
GOOGLE_API_MAP_KEY = 'AIzaSyDU0fb08p4igmko-aQK30Y00FF9E6vzpuI'

#use nose to run all test cases
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
NOSE_ARGS = [
    '--with-coverage',
    '--cover-html',
    '--cover-package=subscribeApp',
    '--cover-inclusive',
]

# CELERY STUFF
# CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'
BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = TIME_ZONE
