Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
254 changes: 128 additions & 126 deletions fm_proj/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,156 +9,157 @@
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""

import os

import dj_database_url

# 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 = os.environ.get('secret_key')
SECRET_KEY = os.environ.get("secret_key")

# SECURITY WARNING: don't run with debug turned on in production!
if os.environ.get('debug') == 'True':
if os.environ.get("debug") == "True":
DEBUG = True
else:
DEBUG = False

ALLOWED_HOSTS = [
'fm-review-stage.herokuapp.com',
'fathen.co',
'www.fathen.co',
'127.0.0.1',
'127.0.0.1:8000',
'fathen.dhcrain.com'
"fm-review-stage.herokuapp.com",
"fathen.co",
"www.fathen.co",
"127.0.0.1",
"127.0.0.1:8000",
"fathen.dhcrain.com",
]

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': ('%(asctime)s [%(process)d] [%(levelname)s] ' +
'pathname=%(pathname)s lineno=%(lineno)s ' +
'funcname=%(funcName)s %(message)s'),
'datefmt': '%Y-%m-%d %H:%M:%S'
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"verbose": {
"format": ("%(asctime)s [%(process)d] [%(levelname)s] " +
"pathname=%(pathname)s lineno=%(lineno)s " +
"funcname=%(funcName)s %(message)s"),
"datefmt":
"%Y-%m-%d %H:%M:%S",
},
"simple": {
"format": "%(levelname)s %(message)s"
},
'simple': {
'format': '%(levelname)s %(message)s'
}
},
'handlers': {
'null': {
'level': 'DEBUG',
'class': 'logging.NullHandler',
"handlers": {
"null": {
"level": "DEBUG",
"class": "logging.NullHandler",
},
"console": {
"level": "DEBUG",
"class": "logging.StreamHandler",
"formatter": "verbose",
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose'
}
},
'loggers': {
'testlogger': {
'handlers': ['console'],
'level': 'INFO',
"loggers": {
"testlogger": {
"handlers": ["console"],
"level": "INFO",
}
}
},
}

# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'review_app',
'hvad',
'review',
'generic_positions',
'storages',
'rest_framework',
'rest_framework_docs',
'captcha',
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"review_app",
"hvad",
"review",
"generic_positions",
"storages",
"rest_framework",
"rest_framework_docs",
"captcha",
]

MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'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',
'whitenoise.middleware.WhiteNoiseMiddleware',
"django.middleware.security.SecurityMiddleware",
"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",
"whitenoise.middleware.WhiteNoiseMiddleware",
]

ROOT_URLCONF = 'fm_proj.urls'
ROOT_URLCONF = "fm_proj.urls"

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['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',
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": ["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",
],
},
},
]

WSGI_APPLICATION = 'fm_proj.wsgi.application'

WSGI_APPLICATION = "fm_proj.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'),
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
}
}


# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
"NAME":
"django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
"NAME":
"django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
"NAME":
"django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
"NAME":
"django.contrib.auth.password_validation.NumericPasswordValidator",
},
]


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

LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = "en-us"

TIME_ZONE = 'America/New_York'
TIME_ZONE = "America/New_York"

USE_I18N = True

Expand All @@ -170,44 +171,40 @@

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(PROJECT_ROOT, "staticfiles")
STATIC_URL = "/static/"

# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (
os.path.join(PROJECT_ROOT, 'static'),
)
STATICFILES_DIRS = (os.path.join(PROJECT_ROOT, "static"), )

# Simplified static file serving.
# https://warehouse.python.org/project/whitenoise/
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
STATICFILES_STORAGE = "whitenoise.django.GzipManifestStaticFilesStorage"

# STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage' # Error on user_media/css/img/progressbar.gif


db_from_env = dj_database_url.config()
DATABASES['default'].update(db_from_env)
DATABASES["default"].update(db_from_env)

MEDIA_ROOT = BASE_DIR
MEDIA_URL = '/media/'

MEDIA_URL = "/media/"

# Django-starages / AWS S3 / https://www.caktusgroup.com/blog/2014/11/10/Using-Amazon-S3-to-store-your-Django-sites-static-and-media-files/
AWS_HEADERS = { # see http://developer.yahoo.com/performance/rules.html#expires
'Expires': 'Thu, 31 Dec 2099 20:00:00 GMT',
'Cache-Control': 'max-age=94608000',
}
"Expires": "Thu, 31 Dec 2099 20:00:00 GMT",
"Cache-Control": "max-age=94608000",
}

# AWS_STORAGE_BUCKET_NAME = os.environ.get('aws_bucket_name')
AWS_STORAGE_BUCKET_NAME = os.environ.get('NOTHING_HERE')
AWS_ACCESS_KEY_ID = os.environ['aws_access_key_id']
AWS_SECRET_ACCESS_KEY = os.environ['aws_secret_access_key']
AWS_STORAGE_BUCKET_NAME = os.environ.get("NOTHING_HERE")
AWS_ACCESS_KEY_ID = os.environ["aws_access_key_id"]
AWS_SECRET_ACCESS_KEY = os.environ["aws_secret_access_key"]

# Tell django-storages that when coming up with the URL for an item in S3 storage, keep
# 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 = '{}.s3.amazonaws.com'.format(AWS_STORAGE_BUCKET_NAME)
AWS_S3_CUSTOM_DOMAIN = "{}.s3.amazonaws.com".format(AWS_STORAGE_BUCKET_NAME)

if AWS_STORAGE_BUCKET_NAME:
# This is used by the `static` template tag from `static`, if you're using that. Or if anything else
Expand All @@ -217,58 +214,63 @@
AWS_S3_FILE_OVERWRITE = False
# 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_STORAGE = "storages.backends.s3boto.S3BotoStorage"

# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html
# DEFAULT_FILE_STORAGE = 'libs.storages.S3Storage.S3Storage'
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'

STATICFILES_LOCATION = 'static'
DEFAULT_FILE_STORAGE = "storages.backends.s3boto.S3BotoStorage"

STATICFILES_LOCATION = "static"

# For django-review
# this would use a RadioSelect instead of the default Select
REVIEW_FORM_CHOICE_WIDGET = 'django.forms.widgets.RadioSelect'
REVIEW_FORM_CHOICE_WIDGET = "django.forms.widgets.RadioSelect"
# Limit to 1 review per user per item REVIEW_FORM_CHOICE_WIDGET
REVIEW_AVOID_MULTIPLE_REVIEWS = True
# new redirect after review
REVIEW_UPDATE_SUCCESS_URL = lambda review: review.reviewed_item.get_absolute_url()


def REVIEW_UPDATE_SUCCESS_URL(review):
return review.reviewed_item.get_absolute_url()


REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
],
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
'PAGE_SIZE': 25,
'DEFAULT_THROTTLE_CLASSES': (
'rest_framework.throttling.AnonRateThrottle',
'rest_framework.throttling.UserRateThrottle'
"DEFAULT_PERMISSION_CLASSES":
["rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly"],
"DEFAULT_PAGINATION_CLASS":
"rest_framework.pagination.LimitOffsetPagination",
"PAGE_SIZE":
25,
"DEFAULT_THROTTLE_CLASSES": (
"rest_framework.throttling.AnonRateThrottle",
"rest_framework.throttling.UserRateThrottle",
),
'DEFAULT_THROTTLE_RATES': {
'anon': '100/day',
'user': '1000/day'
}
"DEFAULT_THROTTLE_RATES": {
"anon": "100/day",
"user": "1000/day"
},
}

EMAIL_HOST_USER = 'fathen.co@gmail.com'
EMAIL_HOST_PASSWORD = os.environ['email_password']
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = "fathen.co@gmail.com"
EMAIL_HOST_PASSWORD = os.environ["email_password"]
EMAIL_HOST = "smtp.gmail.com"
EMAIL_USE_TLS = True
EMAIL_PORT = 587

# Celery settings from https://www.cloudamqp.com/docs/celery.html
BROKER_URL = os.environ.get('CLOUDAMQP_URL')
BROKER_URL = os.environ.get("CLOUDAMQP_URL")
BROKER_POOL_LIMIT = 1 # Will decrease connection usage
BROKER_HEARTBEAT = None # We're using TCP keep-alive instead
BROKER_CONNECTION_TIMEOUT = 30 # May require a long timeout due to Linux DNS timeouts etc
CELERY_RESULT_BACKEND = None # AMQP is not recommended as result backend as it creates thousands of queues
# May require a long timeout due to Linux DNS timeouts etc
BROKER_CONNECTION_TIMEOUT = 30
# AMQP is not recommended as result backend as it creates thousands of queues
CELERY_RESULT_BACKEND = None
CELERY_SEND_EVENTS = False # Will not create celeryev.* queues
CELERY_EVENT_QUEUE_EXPIRES = 60 # Will delete all celeryev. queues without consumers after 1 minute.

# Will delete all celeryev. queues without consumers after 1 minute.
CELERY_EVENT_QUEUE_EXPIRES = 60

RECAPTCHA_PUBLIC_KEY = os.environ['RECAPTCHA_PUBLIC_KEY']
RECAPTCHA_PRIVATE_KEY = os.environ['RECAPTCHA_PRIVATE_KEY']
RECAPTCHA_PUBLIC_KEY = os.environ["RECAPTCHA_PUBLIC_KEY"]
RECAPTCHA_PRIVATE_KEY = os.environ["RECAPTCHA_PRIVATE_KEY"]
NOCAPTCHA = True
Loading