"""
Django settings for socialperks project.

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

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

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

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'btkclc0+1($mnno=(0-7*^25535z(+4yb4tb*lso6c1lrp-0fn'

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

PRELAUNCH = True

DEBUG = True
if 'RDS_DB_NAME' in os.environ:
    DEBUG=False
DEBUG = True




ALLOWED_HOSTS = ['.socialperks.co','.socialperks.co.uk']

#Session Cookie settings

SESSION_COOKIE_AGE = 60*60*24*14 #About 2 weeks

#Login url

LOGIN_URL = '/'
LOGIN_REDIRECT_URL='/temporary_redirect/'
SOCIAL_AUTH_LOGIN_REDIRECT_URL='/temporary_redirect/'
SOCIAL_AUTH_NEW_USER_REDIRECT_URL = '/new-users-redirect-url/'
SOCIAL_AUTH_NEW_ASSOCIATION_REDIRECT_URL = '/new-association-redirect-url/'


TWITTER_CONSUMER_KEY='xxxxxxxxxxxxxxx'
TWITTER_CONSUMER_SECRET='xxxxxxxxxxxxxxxxxxx'
INSTAGRAM_CLIENT_ID='xxxxxxxxxxxxxxxxxxx'
INSTAGRAM_CLIENT_SECRET='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
INSTAGRAM_AUTH_EXTRA_ARGUMENTS = {'scope': 'basic'}

SOCIAL_AUTH_DEFAULT_USERNAME = 'new_social_auth_user'
SOCIAL_AUTH_ENABLED_BACKENDS=('twitter','instagram')
SOCIAL_AUTH_UID_LENGTH = 16
SOCIAL_AUTH_ASSOCIATION_HANDLE_LENGTH = 16
SOCIAL_AUTH_NONCE_SERVER_URL_LENGTH = 16
SOCIAL_AUTH_ASSOCIATION_SERVER_URL_LENGTH = 16
SOCIAL_AUTH_ASSOCIATION_HANDLE_LENGTH = 16

YOUTUBE_CLIENT_ID = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'
YOUTUBE_CLIENT_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

if DEBUG==True:
    YOUTUBE_CALLBACK_URL = 'http://127.0.0.1:8000/oauth_callback/'
else:
    YOUTUBE_CALLBACK_URL='http://www.socialperks.co/oauth_callback/'


#Payments
if DEBUG==True:
    PAYPAL_RECEIVER_EMAIL = "xxxxxxxxxxxxxxxxxxxx"
    PAYPAL_TEST=True
else:
    PAYPAL_RECEIVER_EMAIL = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
    PAYPAL_TEST=False

PAYMENT_STANDARD_MONTHLY = 12.99
PAYMENT_STANDARD_6MONTH = 71.94
PAYMENT_STANDARD_YEAR = 119.88

PAYMENT_GOLD_MONTHLY = 49.99
PAYMENT_GOLD_6MONTH = 281.94
PAYMENT_GOLD_YEAR = 539.88

LOCAL_BASE_URL = 'http://c748f7f9.ngrok.io'


    
# Application definition


INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'campaign',
    'userprofile',
    'imagekit',
    'social_auth',
    'notifications',
    'storages',
    'admincontact',
    'paypal.standard.ipn',
    'django_cron',
)

AUTHENTICATION_BACKENDS = (
    'social_auth.backends.twitter.TwitterBackend',
    #'social_auth.backends.contrib.instagram.InstagramBackend',
    'socialperks.workaround.InstagramBackend',
    'django.contrib.auth.backends.ModelBackend',
    )

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',
)

CRON_CLASSES = [
    "socialperks.cron.PrintEveryMinute",
    
    ]

ROOT_URLCONF = 'socialperks.urls'

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',
                "social_auth.context_processors.social_auth_by_type_backends",
            ],
        },
    },
]

WSGI_APPLICATION = 'socialperks.wsgi.application'


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

if 'RDS_DB_NAME' in os.environ:
    DATABASES = {
       'default': {
             'ENGINE':'django.db.backends.postgresql_psycopg2',
             'NAME': os.environ['RDS_DB_NAME'],
             'USER': os.environ['RDS_USERNAME'],
             'PASSWORD': os.environ['RDS_PASSWORD'],
             'HOST': os.environ['RDS_HOSTNAME'],
             'PORT': os.environ['RDS_PORT'],
             }
          }
else:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': 'socialperks',
            'USER': 'postgres',
            'PASSWORD': 'family',
            'HOST':'localhost',
            'PORT':'5432',
        }
    }

#Social Auth
SOCIAL_AUTH_PIPELINE=(
    'social_auth.backends.pipeline.social.social_auth_user',
    #'social_auth.backends.pipeline.associate.associate_by_email',
    'social_auth.backends.pipeline.user.get_username',
    #'social_auth.backends.pipeline.user.create_user',
    #'social_auth.backends.pipeline.social.associate_user',
    'socialperks.views.extract_account_username',
    #'social_auth.backends.pipeline.social.load_extra_data',
    #'social_auth.backends.pipeline.user.update_user_details'
)

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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
MEDIA_CACHE_BUSTER = ''
STATIC_URL = '/static/'#url to reach file

if 'RDS_DB_NAME' in os.environ: #Checks if in the cloud
    STATIC_ROOT = os.path.join(BASE_DIR, "..", "www", "static")
    STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
    MEDIA_ROOT = os.path.join(BASE_DIR, "..", "www", "media")
    MEDIA_URL = '/media/'
else:
    STATIC_ROOT=os.path.join(BASE_DIR,'static')#collected static is put here
    STATICFILES_DIRS=(
    (os.path.join(BASE_DIR,'assets')),#where to put files before serving them as static
    )
    MEDIA_ROOT=os.path.join(BASE_DIR,'media')
    MEDIA_URL='/media/'

USE_S3 = False
if 'RDS_DB_NAME' in os.environ: #Checks if in the cloud 
    USE_S3 = True
    AWS_ACCESS_KEY_ID = 'AKIXXXXXXXXXXXXX'
    AWS_SECRET_ACCESS_KEY = 'XXXXXXXXX'
    AWS_STORAGE_BUCKET_NAME = 'socialperks'

if USE_S3:
  
    DEFAULT_FILE_STORAGE = 'custom_storages.MediaStorage'
    
    # it simple - just use this domain plus the path. (If this isn't set, things get complicated).
    # This controls how the `static` template tag from `staticfiles` gets expanded, if you're using it.
    # We also use it in the next setting.
    AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME

    # This is used by the `static` template tag from `static`, if you're using that. Or if anything else
    # refers directly to STATIC_URL. So it's safest to always set it.
    STATIC_URL = "https://%s/" % AWS_S3_CUSTOM_DOMAIN

    # Tell the staticfiles app to use S3Boto storage when writing the collected static files (when
    # you run `collectstatic`).
    STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'

    STATICFILES_LOCATION = 'static'
    STATICFILES_STORAGE = 'custom_storages.StaticStorage'
    STATIC_URL = "https://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, STATICFILES_LOCATION)

    MEDIAFILES_LOCATION = 'media'
    MEDIA_URL = "https://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, MEDIAFILES_LOCATION)
    

##STATIC_ROOT=os.path.join(BASE_DIR,'static')#collected static is put here
##STATICFILES_DIRS=(
##(os.path.join(BASE_DIR,'assets')),#where to put files before serving them as static
##)
##MEDIA_ROOT=os.path.join(BASE_DIR,'media')
##MEDIA_URL='/media/'

