# Django settings for pbp_com project.
import os
import sys
import warnings

warnings.simplefilter("ignore")

## Directories
PROJECT_ROOT = os.path.dirname(os.path.realpath(os.path.dirname(__file__)))
SITE_ROOT = os.path.dirname(PROJECT_ROOT)
MEDIA_ROOT = os.path.join(PROJECT_ROOT, "media/")

BASE_DIR = os.path.dirname(os.path.dirname(__file__))
sys.path.insert(0, os.path.join(BASE_DIR, "pbp_com.apps"))

VIRTUALENV = "/var/lib/virtualenvs/pbp/lib/python2.7/site-packages"

sys.path.append(SITE_ROOT)

DEBUG = False
TEMPLATE_DEBUG = DEBUG

# Django settings for pbp project.
ADMINS = (("Colin Powell", "cpowell@penobscotbaypress.com"),)

LANGUAGE_CODE = "en-us"
MANAGERS = ADMINS
USE_I18N = True
APPEND_SLASH = False
SMART_APPEND_SLASH = True
SEND_BROKEN_LINK_EMAILS = False
IGNORABLE_404_STARTS = (
    "/vault/loginout.html",
    "/calendar/submitanevent.html",
    "robots.txt",
)

TIME_ZONE = "America/New_York"
LANGUAGE_CODE = "en-us"

# Our site ID numbers, set to constants for easy reference
PBP = 2
IA = 3
CP = 4
WP = 5

# We're going to try setting this in the manage.py script.
SITE_ID = PBP  # pbp.com

import logging

LOG_DATE_FORMAT = "%d %b %Y %H:%M:%S"
LOG_FORMATTER = logging.Formatter(
    "%(asctime)s %(name)-7s: %(levelname)-8s %(message)s", datefmt=LOG_DATE_FORMAT
)

FILE_HANDLER = logging.FileHandler("/var/log/django/" + "/pbp_com.log", "w")
CONSOLE_HANDLER = logging.StreamHandler()  # defaults to stderr
CONSOLE_HANDLER.setFormatter(LOG_FORMATTER)
CONSOLE_HANDLER.setLevel(logging.DEBUG)

AUTH_PROFILE_MODULE = "profiles.UserProfile"

LOGIN_REDIRECT_URL = "/"

AGENTS_EXCLUSION_FILE = MEDIA_ROOT + "allagents.xml"
SECRET_KEY = "l(4_rf+z#5oj7ik0j$ax9+zl)3yfkh8-ige$=!eoq=hydfbm7k"

TEMPLATE_CONTEXT_PROCESSORS = (
    "django.core.context_processors.auth",
    "django.core.context_processors.request",
    "django.core.context_processors.debug",
    "django.core.context_processors.media",
    "django.contrib.messages.context_processors.messages",
    "adzone.context_processors.get_source_ip",
)

MIDDLEWARE_CLASSES = (
    "django.middleware.common.CommonMiddleware",
    "django.contrib.sessions.middleware.SessionMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.middleware.csrf.CsrfViewMiddleware",
    "django.middleware.csrf.CsrfResponseMiddleware",
    "ipfilter.middleware.FilterIPs",
    "pbp_com.middleware.SmartAppendSlashMiddleware",
    "pbp_com.middleware.SetRemoteAddrMiddleware",
    "debug_toolbar.middleware.DebugToolbarMiddleware",
    "django.contrib.redirects.middleware.RedirectFallbackMiddleware",
    "django.contrib.flatpages.middleware.FlatpageFallbackMiddleware",
)

AUTHENTICATION_BACKENDS = ("django.contrib.auth.backends.ModelBackend",)

ROOT_URLCONF = "urls"

# if SITE_ID == PBP:
HAYSTACK_SITECONF = "pbp_com.search_sites"
HAYSTACK_SEARCH_ENGINE = "whoosh"
HAYSTACK_WHOOSH_PATH = os.path.join(PROJECT_ROOT, "search-index")
CLASSIFIED_LENGTH = 200
INSTALLED_APPS = (
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.sites",
    "django.contrib.admin",
    "django.contrib.markup",
    "django.contrib.redirects",
    "django.contrib.humanize",
    "django.contrib.comments",
    "django.contrib.admindocs",
    "django.contrib.sitemaps",
    "django.contrib.flatpages",
    "django_extensions",
    "registration",
    "profiles",
    "debug_toolbar",
    "typogrify",
    "taggit",
    "markitup",
    "django_inlines",
    "convert",
    "ipfilter",
    "documents",
    "newsroom",
    "darkroom",
    "adzone",
    "directory",
    "marketplace",
    "remember",
    "classifieds",
    "historical",
    "almanac",
    "haystack",
)
