# Django settings for signbank project.
import os
from signbank.settings.server_specific import *
from datetime import datetime

DEBUG = True

PROJECT_DIR = os.path.dirname(BASE_DIR)

MANAGERS = ADMINS

TIME_ZONE = 'Europe/Amsterdam'

LOCALE_PATHS = [BASE_DIR+'conf/locale']

# in the database, SITE_ID 1 is example.com
SITE_ID = 2
USE_I18N = True
USE_L10N = True
USE_TZ = True


MEDIA_ROOT = WRITABLE_FOLDER
MEDIA_URL = PREFIX_URL+'/media/'
MEDIA_MOBILE_URL = MEDIA_URL

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = PREFIX_URL

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = PREFIX_URL+'/static/'

# Additional locations of static files
STATICFILES_DIRS = (
    os.path.join(PROJECT_DIR, "media"),
)

# STATICFILES_STORAGE = ( os.path.join(PROJECT_DIR, "static"), )

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = '^g=q21r_nnmbz49d!vs*2gvpll-y9b@&amp;t3k2r3c$*u&amp;2la5!%s'

MIDDLEWARE_CLASSES = (
#    'debug_toolbar.middleware.DebugToolbarMiddleware',

    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'signbank.pages.middleware.PageFallbackMiddleware',
#    'django_mobile.middleware.MobileDetectionMiddleware',
#    'django_mobile.middleware.SetFlavourMiddleware',
#    'debug_toolbar.middleware.DebugToolbarMiddleware',
    'reversion.middleware.RevisionMiddleware',
)

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(PROJECT_DIR, 'templates/' + SIGNBANK_VERSION_CODE + '-templates'),
                 os.path.join(PROJECT_DIR, 'signbank/registration/templates/')],
        'OPTIONS': {
            'context_processors': [
                "django.template.context_processors.debug",
                "django.template.context_processors.i18n",
                "django.template.context_processors.media",
                "django.template.context_processors.static",
                "django.template.context_processors.tz",
                "django.template.context_processors.request",
                "django.contrib.auth.context_processors.auth",
                "django.contrib.messages.context_processors.messages",
                "signbank.context_processors.url",
                "signbank.pages.context_processors.menu",
#                "django_mobile.context_processors.flavour",
            ],
            'loaders': [
#                'django_mobile.loader.Loader',
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader',
            ]
        },
    },
]

# add the Email backend to allow logins using email as username
AUTHENTICATION_BACKENDS = (
    "signbank.registration.EmailBackend",
    "django.contrib.auth.backends.ModelBackend",
    'guardian.backends.ObjectPermissionBackend',
)

AUTH_PROFILE_MODULE = 'dictionary.UserProfile'

INTERNAL_IPS = ('127.0.0.1','131.174.132.138')

ROOT_URLCONF = 'signbank.urls'

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'signbank.wsgi.application'

INSTALLED_APPS = (
    'modeltranslation',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
    'django.contrib.admindocs',
    'django.contrib.staticfiles',
    'bootstrap3',
    'django_summernote',
    # 'django_select2',
    # 'easy_select2',
    'signbank.dictionary',
    'signbank.feedback',
    #'signbank.registration',
    'signbank.pages',
    'signbank.attachments',
    'signbank.video',
    'reversion',
    #'django_mobile',
    'tagging',
    'guardian',
    #'debug_toolbar'
)

# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
    }
}


# turn on lots of logging or not
DO_LOGGING = False
LOG_FILENAME = "debug.log"


SOUTH_TESTS_MIGRATE = False


## Application settings for signbank


## Settings controlling page contents

# do we implement safe search for anonymous users?
# if True, any gloss that is tagged lexis:crude will be removed from
# search results for users who are not logged in
ANON_SAFE_SEARCH = False

# do we show the tag based search for anonymous users?
ANON_TAG_SEARCH = False


# do we display the previous/next links to signs, requires gloss.sn to be used consistently
SIGN_NAVIGATION = False

# which definition fields do we show and in what order?
DEFINITION_FIELDS = ['general', 'noun', 'verb', 'interact', 'deictic', 'modifier', 'question', 'augment', 'note']

HANDSHAPE_RESULT_FIELDS = ['machine_value', 'english_name', 'dutch_name', 'chinese_name',
                           'hsFingSel', 'hsFingConf', 'hsFingSel2', 'hsFingConf2', 'hsFingUnsel', 'hsSpread', 'hsAperture']

# location and URL for uploaded files
UPLOAD_ROOT = MEDIA_ROOT + "upload/"
UPLOAD_URL = MEDIA_URL + "upload/"

# Location for comment videos relative to MEDIA_ROOT
COMMENT_VIDEO_LOCATION = "comments"
# Location for videos associated with pages
PAGES_VIDEO_LOCATION = 'pages'
# location for upload of videos relative to MEDIA_ROOT
# videos are stored here prior to copying over to the main
# storage location
VIDEO_UPLOAD_LOCATION = "upload"

# path to store uploaded attachments relative to MEDIA_ROOT
ATTACHMENT_LOCATION = 'attachments'

# which fields from the Gloss model should be included in the quick update form on the sign view
QUICK_UPDATE_GLOSS_FIELDS = ['signlanguage', 'dialect']

# should we always require a login for viewing dictionary content
ALWAYS_REQUIRE_LOGIN = True


# do we allow people to register for the site
ALLOW_REGISTRATION = True

ACCOUNT_ACTIVATION_DAYS = 7



# show the number signs page or an under construction page?
SHOW_NUMBERSIGNS = True

LOGIN_URL = PREFIX_URL+'/accounts/login/'
LOGIN_REDIRECT_URL = PREFIX_URL+'/signs/recently_added/'


# location of ffmpeg, used to convert uploaded videos
# FFMPEG_PROGRAM = "/Applications/ffmpegX.app/Contents/Resources/ffmpeg"
FFMPEG_TIMEOUT = 60
FFMPEG_OPTIONS = ["-vcodec", "h264", "-an"]


# defines the aspect ratio for videos
VIDEO_ASPECT_RATIO = 3.0/4.0

# settings for django-tagging
FORCE_LOWERCASE_TAGS = False

PRIMARY_CSS = "css/"+SIGNBANK_VERSION_CODE+"/main.css"

import mimetypes
mimetypes.add_type("video/mp4", ".mov", True)



# a list of tags we're allowed to use
XALLOWED_TAGS = [ '',
                 'workflow:needs video',
                 'workflow:redo video',
                 'workflow:problematic',
                 'corpus:attested',
                 'lexis:doubtlex',
                 'phonology:alternating',
                 'phonology:dominant hand only',
                 'phonology:double handed',
                 'phonology:forearm rotation',
                 'phonology:handshape change',
                 'phonology:onehand',
                 'phonology:parallel',
                 'phonology:symmetrical',
                 'phonology:two handed',
                ]

TEST_RUNNER = 'django.test.runner.DiscoverRunner'

EARLIEST_GLOSS_CREATION_DATE = datetime(2015,1,1)
SUPPORTED_CITATION_IMAGE_EXTENSIONS = ['.jpg','.jpeg','.png']
MAXIMUM_UPLOAD_SIZE = 5000000

MINIMUM_OVERLAP_BETWEEN_SIGNING_HANDS_IN_CNGT = 40
DISABLE_MOVING_THUMBNAILS_ABOVE_NR_OF_GLOSSES = 200

DATA_UPLOAD_MAX_NUMBER_FIELDS = None
DATA_UPLOAD_MAX_MEMORY_SIZE = None
[((8, 14, 8, 39), 'os.path.dirname', 'os.path.dirname', ({(8, 30, 8, 38): 'BASE_DIR'}, {}), '(BASE_DIR)', False, 'import os\n'), ((256, 0, 256, 45), 'mimetypes.add_type', 'mimetypes.add_type', ({(256, 19, 256, 30): '"""video/mp4"""', (256, 32, 256, 38): '""".mov"""', (256, 40, 256, 44): '(True)'}, {}), "('video/mp4', '.mov', True)", False, 'import mimetypes\n'), ((280, 31, 280, 49), 'datetime.datetime', 'datetime', ({(280, 40, 280, 44): '2015', (280, 45, 280, 46): '1', (280, 47, 280, 48): '1'}, {}), '(2015, 1, 1)', False, 'from datetime import datetime\n'), ((39, 4, 39, 38), 'os.path.join', 'os.path.join', ({(39, 17, 39, 28): 'PROJECT_DIR', (39, 30, 39, 37): '"""media"""'}, {}), "(PROJECT_DIR, 'media')", False, 'import os\n'), ((75, 17, 75, 95), 'os.path.join', 'os.path.join', ({(75, 30, 75, 41): 'PROJECT_DIR', (75, 43, 75, 94): "('templates/' + SIGNBANK_VERSION_CODE + '-templates')"}, {}), "(PROJECT_DIR, 'templates/' + SIGNBANK_VERSION_CODE + '-templates')", False, 'import os\n'), ((76, 17, 76, 78), 'os.path.join', 'os.path.join', ({(76, 30, 76, 41): 'PROJECT_DIR', (76, 43, 76, 77): '"""signbank/registration/templates/"""'}, {}), "(PROJECT_DIR, 'signbank/registration/templates/')", False, 'import os\n')]