diff --git a/.gitignore b/.gitignore index 3c936f1..2ee6455 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ yandex_money.log /static/ /src/dokumentor/media/ /tmp/ +/conf/env diff --git a/conf/env b/conf/env index e69de29..c66e387 100644 --- a/conf/env +++ b/conf/env @@ -0,0 +1,16 @@ +DJANGO_SETTINGS_MODULE=dokumentor.settings.local + +DJANGO_SECRET='CHANGE_ME_IN_PRODUCTION' + +DJANGO_DB='postgres://dokumentor:dokumentor@localhost:5432/dokumentor' + +DJANGO_FROM_EMAIL='root@localhost' +DJANGO_EMAIL_HOST='' +DJANGO_EMAIL_PORT='' +DJANGO_EMAIL_USER='' +DJANGO_EMAIL_PASSWORD='' +DJANGO_EMAIL_USE_TLS=False +DJANGO_EMAIL_USE_SSL=False + +CELERY_BROKER_URL = 'amqp://guest:guest@localhost:5672//' +CELERY_RESULT_BACKEND = 'amqp://guest:guest@localhost:5672//' \ No newline at end of file diff --git a/conf/env.template b/conf/env.template new file mode 100644 index 0000000..d221873 --- /dev/null +++ b/conf/env.template @@ -0,0 +1,16 @@ +DJANGO_SETTINGS_MODULE=dokumentor.settings.{{env}} + +DJANGO_SECRET='CHANGE_ME_IN_PRODUCTION' + +DJANGO_DB='postgres://USER:PASSWORD@HOST:PORT/NAME' + +DJANGO_FROM_EMAIL='root@localhost' +DJANGO_EMAIL_HOST='' +DJANGO_EMAIL_PORT='' +DJANGO_EMAIL_USER='' +DJANGO_EMAIL_PASSWORD='' +DJANGO_EMAIL_USE_TLS=False +DJANGO_EMAIL_USE_SSL=False + +CELERY_BROKER_URL = 'amqp://guest:guest@localhost:5672//' +CELERY_RESULT_BACKEND = 'amqp://guest:guest@localhost:5672//' diff --git a/requirements/base.txt b/requirements/base.txt index 7f5079d..8d65574 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -50,7 +50,6 @@ Pillow==4.1.0 pisa==3.0.33 pylint==1.6.5 pyparsing==2.2.0 -pyPdf==1.13 PyPDF2==1.26.0 python-dateutil==2.6.0 python-memcached==1.58 @@ -69,4 +68,6 @@ wrapt==1.10.10 xhtml2pdf==0.2b1 xlrd==1.0.0 xlutils==2.0.0 -xlwt==1.2.0 \ No newline at end of file +xlwt==1.2.0 +dj-database-url==0.4.2 +envvars==0.3.0 \ No newline at end of file diff --git a/requirements/local.txt b/requirements/local.txt index 6c1b882..ec47464 100644 --- a/requirements/local.txt +++ b/requirements/local.txt @@ -1,3 +1,3 @@ -- r base.txt +-r base.txt django-debug-toolbar==1.4 django-eml-email-backend==0.1 \ No newline at end of file diff --git a/requirements/prodaction.txt b/requirements/prodaction.txt index cf61098..5902b98 100644 --- a/requirements/prodaction.txt +++ b/requirements/prodaction.txt @@ -1,3 +1,3 @@ -- r base.txt +-r base.txt psycopg2==2.6 gunicorn==19.4.5 \ No newline at end of file diff --git a/requirements/staging.txt b/requirements/staging.txt index cf61098..5902b98 100644 --- a/requirements/staging.txt +++ b/requirements/staging.txt @@ -1,3 +1,3 @@ -- r base.txt +-r base.txt psycopg2==2.6 gunicorn==19.4.5 \ No newline at end of file diff --git a/src/dokumentor/__init__.py b/src/dokumentor/__init__.py index ddbfadf..05aea32 100644 --- a/src/dokumentor/__init__.py +++ b/src/dokumentor/__init__.py @@ -1,18 +1,17 @@ # coding: utf-8 -from __future__ import absolute_import, unicode_literals -import os -from celery import Celery -# set the default Django settings module for the 'celery' program. -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dokumentor.settings.local') +import warnings -app = Celery('dokumentor') +from os import path as p -# Using a string here means the worker don't have to serialize -# the configuration object to child processes. -# - namespace='CELERY' means all celery-related configuration keys -# should have a `CELERY_` prefix. -app.config_from_object('django.conf:settings', namespace='CELERY') +import envvars as env -# Load task modules from all registered Django app configs. -app.autodiscover_tasks() +env_file = p.normpath(p.join(p.abspath(p.dirname(__file__)), "../../conf/env")) +env.load(env_file) + +# This will make sure the app is always imported when +# Django starts so that shared_task will use this app. +try: + from .celery import app as celery_app +except ImportError as e: + warnings.warn('Celery import error, is it installed?') diff --git a/src/dokumentor/settings/base.py b/src/dokumentor/settings/base.py index 03380e2..a75ca90 100644 --- a/src/dokumentor/settings/base.py +++ b/src/dokumentor/settings/base.py @@ -6,6 +6,8 @@ import os import sys from datetime import timedelta +import envvars as e + PROJECT_DIR = os.path.normpath(os.path.join(os.path.dirname(__file__), '..')) MANAGE_DIR = os.path.normpath(os.path.join(PROJECT_DIR, '..')) ROOT_DIR = os.path.normpath(os.path.join(MANAGE_DIR, '..')) @@ -14,6 +16,10 @@ sys.path.append(PROJECT_DIR) sys.path.append(MANAGE_DIR) sys.path.append(ROOT_DIR) +e.load(os.path.join(ROOT_DIR, 'conf/env')) + +SECRET_KEY = e.get('DJANGO_SECRET') + DEBUG = False ADMINS = ( @@ -75,10 +81,6 @@ STATICFILES_DIRS = ( os.path.join(PROJECT_DIR, 'static'), ) - -# Make this unique, and don't share it with anybody. -SECRET_KEY = 'uqrv8bpqt-#up^ay-)^@bcjjgq1^jy8qc!fkr!1wd*u%)1dg#y' - # List of callables that know how to import templates from various sources. TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.Loader', @@ -253,13 +255,8 @@ CMS_PLACEHOLDER_CONF = { CMS_PERMISSION = True -BROKER_HOST = "localhost" -BROKER_PORT = 5672 -BROKER_USER = "dokumentor" -BROKER_PASSWORD = "dokumentor" -BROKER_VHOST = "dokumentor" - -# CELERY_BROKER_URL = 'amqp://guest:guest@localhost:5672//' +BROKER_URL = e.get('CELERY_BROKER_URL') +CELERY_RESULT_BACKEND = e.get('CELERY_RESULT_BACKEND') CELERY_TIMEZONE = 'Europe/Moscow' @@ -323,11 +320,5 @@ YANDEX_MONEY_PAYMENT_URL = 'https://money.yandex.ru/eshop.xml' # информировать о случаях, когда модуль вернул Яндекс.Кассе ошибку YANDEX_MONEY_MAIL_ADMINS_ON_PAYMENT_ERROR = True -try: - from dokumentor.settings.local import * -except ImportError: - pass - - DADATA_API_KEY = 'e4232c46f82c0b2e8c5f9bd583d6224ce9c934e0' DADATA_SECRET_KEY = '9c5c3fdfba74af122730db650346b3e91586abc7' diff --git a/src/dokumentor/settings/local.py b/src/dokumentor/settings/local.py index 5be3441..8dcd243 100644 --- a/src/dokumentor/settings/local.py +++ b/src/dokumentor/settings/local.py @@ -1,43 +1,27 @@ # -*- coding: utf-8 -*- -from dokumentor.settings.base import * - -DEBUG = True -ADMINS = () +import dj_database_url -MANAGERS = ADMINS +from dokumentor.settings.base import * -SERVER_EMAIL = 'dokumentor@localhost' +DEBUG = True -ALLOWED_HOSTS = ['*'] +if DEBUG: + INSTALLED_APPS.append('debug_toolbar') + MIDDLEWARE_CLASSES.append('debug_toolbar.middleware.DebugToolbarMiddleware') DATABASES = { + 'default': dj_database_url.parse(e.get('DJANGO_DB')), +} + +CACHES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(ROOT_DIR, 'db.sqlite3'), + 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', + 'LOCATION': '/tmp/django_cache_garpun', } } -# Postgres -# DATABASES = { -# 'default': { -# 'ENGINE': 'django.db.backends.postgresql_psycopg2', -# 'NAME': 'dok', -# 'USER': 'dokumentor', -# 'PASSWORD': 'dokumentor', -# 'HOST': '127.0.0.1', -# 'PORT': '5432', -# } -# } - EMAIL_BACKEND = 'eml_email_backend.EmailBackend' EMAIL_FILE_PATH = os.path.join(ROOT_DIR, 'tmp_emails') -# debug toolbar -DEBUG_TOOLBAR_PATCH_SETTINGS = False - - -if DEBUG: - INSTALLED_APPS.append('debug_toolbar') - MIDDLEWARE_CLASSES.append('debug_toolbar.middleware.DebugToolbarMiddleware') - INTERNAL_IPS = ('127.0.0.1',) +INTERNAL_IPS = ['127.0.0.1'] diff --git a/src/dokumentor/settings/production.py b/src/dokumentor/settings/production.py new file mode 100644 index 0000000..b5babb1 --- /dev/null +++ b/src/dokumentor/settings/production.py @@ -0,0 +1,41 @@ +# coding: utf-8 + +import dj_database_url + +from dokumentor.settings.base import * + +DEBUG = False + +ADMINS = () + +MANAGERS = ADMINS + +ALLOWED_HOSTS = ['dokumentor.ru'] + +DATABASES = { + 'default': dj_database_url.parse(e.get('DJANGO_DB')), +} + + +# Wrap loaders in cached loader +TEMPLATES[0]['OPTIONS']['loaders'] = [ + ('django.template.loaders.cached.Loader', TEMPLATES[0]['OPTIONS']['loaders']), +] + +CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', + 'LOCATION': '/tmp/django_cache_dokumentor', + } +} + + +DEFAULT_FROM_EMAIL = e.get('DJANGO_FROM_EMAIL') +SERVER_EMAIL = DEFAULT_FROM_EMAIL +EMAIL_HOST = e.get('DJANGO_EMAIL_HOST') +EMAIL_PORT = e.get('DJANGO_EMAIL_PORT') +EMAIL_HOST_USER = e.get('DJANGO_EMAIL_USER') +EMAIL_HOST_PASSWORD = e.get('DJANGO_EMAIL_PASSWORD') +EMAIL_USE_TLS = e.get('DJANGO_EMAIL_USE_TLS') +EMAIL_USE_SSL = e.get('DJANGO_EMAIL_USE_SSL') +EMAIL_SUBJECT_PREFIX = 'dokumentor ' \ No newline at end of file diff --git a/src/manage.py b/src/manage.py index cb4c2f2..3d0b9d4 100755 --- a/src/manage.py +++ b/src/manage.py @@ -1,9 +1,14 @@ #!/usr/bin/env python -import os + +from os import path as p import sys +import envvars as env + + if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dokumentor.settings.local") + env_file = p.normpath(p.join(p.abspath(p.dirname(__file__)), "../conf/env")) + env.load(env_file) from django.core.management import execute_from_command_line