From: Radek Czajka Date: Wed, 6 Mar 2019 21:42:18 +0000 (+0100) Subject: Simplify settings loading a bit. Remove the things which haven't been working for... X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/15dec706694c3afc006713be0fabb4973a6c2946?ds=inline;hp=--cc Simplify settings loading a bit. Remove the things which haven't been working for a decade, ain't nobody complaining. --- 15dec706694c3afc006713be0fabb4973a6c2946 diff --git a/src/dvcs/tests/models.py b/src/dvcs/tests/models.py index 61174c17..b2dc93e5 100644 --- a/src/dvcs/tests/models.py +++ b/src/dvcs/tests/models.py @@ -1,5 +1,4 @@ from dvcs.models import Document - class ADocument(Document): pass diff --git a/src/dvcs/tests/tests.py b/src/dvcs/tests/tests.py index 5c7a4758..06160cae 100644 --- a/src/dvcs/tests/tests.py +++ b/src/dvcs/tests/tests.py @@ -2,7 +2,6 @@ from nose.tools import * from django.test import TestCase from .models import ADocument - class DocumentModelTests(TestCase): def assertTextEqual(self, given, expected): @@ -11,6 +10,7 @@ class DocumentModelTests(TestCase): ) def test_empty_file(self): + assert False doc = ADocument.objects.create() self.assertTextEqual(doc.materialize(), u"") diff --git a/src/redakcja/settings/__init__.py b/src/redakcja/settings/__init__.py index 4d4fe8fb..b9bdf5dd 100644 --- a/src/redakcja/settings/__init__.py +++ b/src/redakcja/settings/__init__.py @@ -1,37 +1,243 @@ +# -*- coding: utf-8 -*- from __future__ import absolute_import -from os import path -from redakcja.settings.common import * - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. - 'NAME': path.join(PROJECT_ROOT, 'dev.sqlite'), # Or path to database file if using sqlite3. - 'USER': '', # Not used with sqlite3. - 'PASSWORD': '', # Not used with sqlite3. - 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. - 'PORT': '', # Set to empty string for default. Not used with sqlite3. +import os.path +from redakcja.settings.defaults import * +from redakcja.localsettings import * + + +PROJECT_ROOT = os.path.realpath(os.path.dirname(os.path.dirname(__file__))) + +STATICFILES_DIRS = [ + PROJECT_ROOT + '/static/' +] + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'APP_DIRS': True, + 'DIRS': [ + PROJECT_ROOT + '/templates', + ], + 'OPTIONS': { + 'context_processors': [ + "django.contrib.auth.context_processors.auth", + "django.template.context_processors.debug", + "django.template.context_processors.i18n", + "redakcja.context_processors.settings", # this is instead of media + 'django.template.context_processors.csrf', + "django.template.context_processors.request", + ], + }, + }, +] + +MIDDLEWARE_CLASSES = ( + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django_cas.middleware.CASMiddleware', + + 'django.contrib.admindocs.middleware.XViewMiddleware', + 'fnp_django_pagination.middleware.PaginationMiddleware', + 'maintenancemode.middleware.MaintenanceModeMiddleware', +) + +if DEBUG: + MIDDLEWARE_CLASSES = ( + 'debug_toolbar.middleware.DebugToolbarMiddleware', + ) + MIDDLEWARE_CLASSES + +AUTHENTICATION_BACKENDS = ( + 'django.contrib.auth.backends.ModelBackend', + 'fnpdjango.auth_backends.AttrCASBackend', +) + +ROOT_URLCONF = 'redakcja.urls' + +INSTALLED_APPS = ( + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'django.contrib.sites', + 'django.contrib.admin', + 'django.contrib.admindocs', + 'raven.contrib.django.raven_compat', + + 'sorl.thumbnail', + 'fnp_django_pagination', + 'django_gravatar', + 'fileupload', + 'kombu.transport.django', + 'pipeline', + 'fnpdjango', + + 'catalogue', + 'cover', + 'dvcs', + 'wiki', + 'wiki_img', + 'toolbar', + 'apiclient', + 'email_mangler', +) + +if DEBUG: + INSTALLED_APPS += ('debug_toolbar',) + +LOGIN_REDIRECT_URL = '/documents/user' + +CELERY_EAGER_PROPAGATES_EXCEPTIONS = True +CELERY_SEND_TASK_ERROR_EMAILS = True +CELERY_ACCEPT_CONTENT = ['pickle'] # Remove when all tasks jsonable. + +MIN_COVER_SIZE = (915, 1270) + +STATICFILES_FINDERS = ( + 'django.contrib.staticfiles.finders.FileSystemFinder', + 'django.contrib.staticfiles.finders.AppDirectoriesFinder', + 'pipeline.finders.PipelineFinder', +) + +STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage' + +PIPELINE = { + 'CSS_COMPRESSOR': None, + 'JS_COMPRESSOR': None, + + # CSS and JS files to compress + 'STYLESHEETS': { + 'detail': { + 'source_filenames': ( + 'css/master.css', + 'css/toolbar.css', + 'css/gallery.css', + 'css/history.css', + 'css/summary.css', + 'css/html.css', + 'css/jquery.autocomplete.css', + 'css/imgareaselect-default.css', + 'css/dialogs.css', + ), + 'output_filename': 'compressed/detail_styles.css', + }, + 'catalogue': { + 'source_filenames': ( + 'css/filelist.css', + ), + 'output_filename': 'compressed/catalogue_styles.css', + }, + 'book': { + 'source_filenames': ( + 'css/book.css', + ), + 'output_filename': 'compressed/book.css', + }, + 'book_list': { + 'source_filenames': ( + 'contextmenu/jquery.contextMenu.css', + 'css/book_list.css', + ), + 'output_filename': 'compressed/book_list.css', + }, + }, + 'JAVASCRIPT': { + # everything except codemirror + 'detail': { + 'source_filenames': ( + # libraries + 'js/lib/jquery/jquery.autocomplete.js', + 'js/lib/jquery/jquery.blockui.js', + 'js/lib/jquery/jquery.elastic.js', + 'js/lib/jquery/jquery.xmlns.js', + 'js/button_scripts.js', + 'js/slugify.js', + + # wiki scripts + 'js/wiki/wikiapi.js', + 'js/wiki/xslt.js', + + # base UI + 'js/wiki/base.js', + 'js/wiki/toolbar.js', + + # dialogs + 'js/wiki/dialog_save.js', + 'js/wiki/dialog_revert.js', + 'js/wiki/dialog_pubmark.js', + + # views + 'js/wiki/view_history.js', + 'js/wiki/view_summary.js', + 'js/wiki/view_editor_source.js', + 'js/wiki/view_editor_wysiwyg.js', + 'js/wiki/view_gallery.js', + 'js/wiki/view_annotations.js', + 'js/wiki/view_search.js', + 'js/wiki/view_column_diff.js', + ), + 'output_filename': 'compressed/detail_scripts.js', + }, + 'wiki_img': { + 'source_filenames': ( + # libraries + 'js/lib/jquery-1.4.2.min.js', + 'js/lib/jquery/jquery.autocomplete.js', + 'js/lib/jquery/jquery.blockui.js', + 'js/lib/jquery/jquery.elastic.js', + 'js/lib/jquery/jquery.imgareaselect.js', + 'js/button_scripts.js', + 'js/slugify.js', + + # wiki scripts + 'js/wiki_img/wikiapi.js', + + # base UI + 'js/wiki_img/base.js', + 'js/wiki/toolbar.js', + + # dialogs + 'js/wiki/dialog_save.js', + 'js/wiki/dialog_revert.js', + 'js/wiki/dialog_pubmark.js', + + # views + 'js/wiki_img/view_editor_objects.js', + 'js/wiki_img/view_editor_motifs.js', + 'js/wiki/view_editor_source.js', + 'js/wiki/view_history.js', + 'js/wiki/view_column_diff.js', + ), + 'output_filename': 'compressed/detail_img_scripts.js', + }, + 'catalogue': { + 'source_filenames': ( + 'js/catalogue/catalogue.js', + 'js/slugify.js', + 'email_mangler/email_mangler.js', + ), + 'output_filename': 'compressed/catalogue_scripts.js', + }, + 'book': { + 'source_filenames': ( + 'js/book_text/jquery.eventdelegation.js', + 'js/book_text/jquery.scrollto.js', + 'js/book_text/jquery.highlightfade.js', + 'js/book_text/book.js', + ), + 'output_filename': 'compressed/book.js', + }, + 'book_list': { + 'source_filenames': ( + 'contextmenu/jquery.ui.position.js', + 'contextmenu/jquery.contextMenu.js', + 'js/catalogue/book_list.js', + ), + 'output_filename': 'compressed/book_list.js', + } } } - -try: - LOGGING_CONFIG_FILE -except NameError: - LOGGING_CONFIG_FILE = os.path.join(PROJECT_ROOT, 'config', - ('logging.cfg' if not DEBUG else 'logging.cfg.dev')) -try: - import logging - - if os.path.isfile(LOGGING_CONFIG_FILE): - import logging.config - logging.config.fileConfig(LOGGING_CONFIG_FILE) - else: - import sys - logging.basicConfig(stream=sys.stderr) -except (ImportError,), exc: - raise - - -try: - from redakcja.localsettings import * -except ImportError: - pass diff --git a/src/redakcja/settings/common.py b/src/redakcja/settings/common.py deleted file mode 100644 index fd870ab8..00000000 --- a/src/redakcja/settings/common.py +++ /dev/null @@ -1,149 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import -import os.path - -PROJECT_ROOT = os.path.realpath(os.path.dirname(os.path.dirname(__file__))) - -DEBUG = False - -MAINTENANCE_MODE = False - -ADMINS = ( - (u'Radek Czajka', 'radoslaw.czajka@nowoczesnapolska.org.pl'), -) - -MANAGERS = ADMINS - -# Local time zone for this installation. Choices can be found here: -# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name -# although not all choices may be available on all operating systems. -# If running in a Windows environment this must be set to the same as your -# system time zone. -TIME_ZONE = 'Europe/Warsaw' - -# Language code for this installation. All choices can be found here: -# http://www.i18nguy.com/unicode/language-identifiers.html -LANGUAGE_CODE = 'pl' - -#import locale -#locale.setlocale(locale.LC_ALL, '') - -SITE_ID = 1 - -# If you set this to False, Django will make some optimizations so as not -# to load the internationalization machinery. -USE_I18N = True -USE_L10N = True - - -# Absolute path to the directory that holds media. -# Example: "/home/media/media.lawrence.com/" -MEDIA_ROOT = PROJECT_ROOT + '/media/dynamic' -STATIC_ROOT = PROJECT_ROOT + '/../static/' - -STATICFILES_DIRS = [ - PROJECT_ROOT + '/static/' -] - -# URL that handles the media served from MEDIA_ROOT. Make sure to use a -# trailing slash if there is a path component (optional in other cases). -# Examples: "http://media.lawrence.com", "http://example.com/media/" -MEDIA_URL = '/media/dynamic/' -STATIC_URL = '/media/static/' - -SESSION_COOKIE_NAME = "redakcja_sessionid" - -TEMPLATES = [ - { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'APP_DIRS': True, - 'DIRS': [ - PROJECT_ROOT + '/templates', - ], - 'OPTIONS': { - 'context_processors': [ - "django.contrib.auth.context_processors.auth", - "django.template.context_processors.debug", - "django.template.context_processors.i18n", - "redakcja.context_processors.settings", # this is instead of media - 'django.template.context_processors.csrf', - "django.template.context_processors.request", - ], - }, - }, -] - -MIDDLEWARE_CLASSES = ( - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django_cas.middleware.CASMiddleware', - - 'django.contrib.admindocs.middleware.XViewMiddleware', - 'fnp_django_pagination.middleware.PaginationMiddleware', - 'maintenancemode.middleware.MaintenanceModeMiddleware', -) - -AUTHENTICATION_BACKENDS = ( - 'django.contrib.auth.backends.ModelBackend', - 'fnpdjango.auth_backends.AttrCASBackend', -) - -ROOT_URLCONF = 'redakcja.urls' - -FIREPYTHON_LOGGER_NAME = "fnp" - -INSTALLED_APPS = ( - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'django.contrib.sites', - 'django.contrib.admin', - 'django.contrib.admindocs', - 'raven.contrib.django.raven_compat', - - 'sorl.thumbnail', - 'fnp_django_pagination', - 'django_gravatar', - 'fileupload', - 'kombu.transport.django', - 'pipeline', - 'fnpdjango', - - 'catalogue', - 'cover', - 'dvcs', - 'wiki', - 'wiki_img', - 'toolbar', - 'apiclient', - 'email_mangler', -) - -LOGIN_REDIRECT_URL = '/documents/user' - -CAS_USER_ATTRS_MAP = { - 'email': 'email', 'firstname': 'first_name', 'lastname': 'last_name'} - -IMAGE_DIR = 'images/' - - -BROKER_URL = 'django://' -CELERY_EAGER_PROPAGATES_EXCEPTIONS = True -CELERY_SEND_TASK_ERROR_EMAILS = True -CELERY_ACCEPT_CONTENT = ['pickle'] # Remove when all tasks jsonable. - -SHOW_APP_VERSION = False - -MIN_COVER_SIZE = (915, 1270) - -try: - from redakcja.settings.compress import * -except ImportError: - pass - diff --git a/src/redakcja/settings/compress.py b/src/redakcja/settings/compress.py deleted file mode 100644 index 0406fdf8..00000000 --- a/src/redakcja/settings/compress.py +++ /dev/null @@ -1,147 +0,0 @@ -STATICFILES_FINDERS = ( - 'django.contrib.staticfiles.finders.FileSystemFinder', - 'django.contrib.staticfiles.finders.AppDirectoriesFinder', -# 'django.contrib.staticfiles.finders.DefaultStorageFinder', - 'pipeline.finders.PipelineFinder', -) - - -STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage' - -PIPELINE = { - 'CSS_COMPRESSOR': None, - 'JS_COMPRESSOR': None, - #'PIPELINE_STORAGE = 'pipeline.storage.PipelineFinderStorage' - - # CSS and JS files to compress - 'STYLESHEETS': { - 'detail': { - 'source_filenames': ( - 'css/master.css', - 'css/toolbar.css', - 'css/gallery.css', - 'css/history.css', - 'css/summary.css', - 'css/html.css', - 'css/jquery.autocomplete.css', - 'css/imgareaselect-default.css', #img! - 'css/dialogs.css', - ), - 'output_filename': 'compressed/detail_styles.css', - }, - 'catalogue': { - 'source_filenames': ( - 'css/filelist.css', - ), - 'output_filename': 'compressed/catalogue_styles.css', - }, - 'book': { - 'source_filenames': ( - 'css/book.css', - ), - 'output_filename': 'compressed/book.css', - }, - 'book_list': { - 'source_filenames': ( - 'contextmenu/jquery.contextMenu.css', - 'css/book_list.css', - ), - 'output_filename': 'compressed/book_list.css', - }, - }, - 'JAVASCRIPT': { - # everything except codemirror - 'detail': { - 'source_filenames': ( - # libraries - 'js/lib/jquery/jquery.autocomplete.js', - 'js/lib/jquery/jquery.blockui.js', - 'js/lib/jquery/jquery.elastic.js', - 'js/lib/jquery/jquery.xmlns.js', - 'js/button_scripts.js', - 'js/slugify.js', - - # wiki scripts - 'js/wiki/wikiapi.js', - 'js/wiki/xslt.js', - - # base UI - 'js/wiki/base.js', - 'js/wiki/toolbar.js', - - # dialogs - 'js/wiki/dialog_save.js', - 'js/wiki/dialog_revert.js', - 'js/wiki/dialog_pubmark.js', - - # views - 'js/wiki/view_history.js', - 'js/wiki/view_summary.js', - 'js/wiki/view_editor_source.js', - 'js/wiki/view_editor_wysiwyg.js', - 'js/wiki/view_gallery.js', - 'js/wiki/view_annotations.js', - 'js/wiki/view_search.js', - 'js/wiki/view_column_diff.js', - ), - 'output_filename': 'compressed/detail_scripts.js', - }, - 'wiki_img': { - 'source_filenames': ( - # libraries - 'js/lib/jquery-1.4.2.min.js', - 'js/lib/jquery/jquery.autocomplete.js', - 'js/lib/jquery/jquery.blockui.js', - 'js/lib/jquery/jquery.elastic.js', - 'js/lib/jquery/jquery.imgareaselect.js', - 'js/button_scripts.js', - 'js/slugify.js', - - # wiki scripts - 'js/wiki_img/wikiapi.js', - - # base UI - 'js/wiki_img/base.js', - 'js/wiki/toolbar.js', - - # dialogs - 'js/wiki/dialog_save.js', - 'js/wiki/dialog_revert.js', - 'js/wiki/dialog_pubmark.js', - - # views - 'js/wiki_img/view_editor_objects.js', - 'js/wiki_img/view_editor_motifs.js', - 'js/wiki/view_editor_source.js', - 'js/wiki/view_history.js', - 'js/wiki/view_column_diff.js', - ), - 'output_filename': 'compressed/detail_img_scripts.js', - }, - 'catalogue': { - 'source_filenames': ( - 'js/catalogue/catalogue.js', - 'js/slugify.js', - 'email_mangler/email_mangler.js', - ), - 'output_filename': 'compressed/catalogue_scripts.js', - }, - 'book': { - 'source_filenames': ( - 'js/book_text/jquery.eventdelegation.js', - 'js/book_text/jquery.scrollto.js', - 'js/book_text/jquery.highlightfade.js', - 'js/book_text/book.js', - ), - 'output_filename': 'compressed/book.js', - }, - 'book_list': { - 'source_filenames': ( - 'contextmenu/jquery.ui.position.js', - 'contextmenu/jquery.contextMenu.js', - 'js/catalogue/book_list.js', - ), - 'output_filename': 'compressed/book_list.js', - } - } -} diff --git a/src/redakcja/settings/defaults.py b/src/redakcja/settings/defaults.py new file mode 100644 index 00000000..688e2b6d --- /dev/null +++ b/src/redakcja/settings/defaults.py @@ -0,0 +1,67 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import +import os.path + +PROJECT_ROOT = os.path.realpath(os.path.dirname(os.path.dirname(__file__))) + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. + 'NAME': os.path.join(PROJECT_ROOT, 'dev.sqlite'), # Or path to database file if using sqlite3. + 'USER': '', # Not used with sqlite3. + 'PASSWORD': '', # Not used with sqlite3. + 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. + 'PORT': '', # Set to empty string for default. Not used with sqlite3. + } +} + +DEBUG = False + +MAINTENANCE_MODE = False + +ADMINS = ( + (u'Radek Czajka', 'radoslaw.czajka@nowoczesnapolska.org.pl'), +) + +MANAGERS = ADMINS + +# Local time zone for this installation. Choices can be found here: +# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name +# although not all choices may be available on all operating systems. +# If running in a Windows environment this must be set to the same as your +# system time zone. +TIME_ZONE = 'Europe/Warsaw' + +# Language code for this installation. All choices can be found here: +# http://www.i18nguy.com/unicode/language-identifiers.html +LANGUAGE_CODE = 'pl' + +SITE_ID = 1 + +# If you set this to False, Django will make some optimizations so as not +# to load the internationalization machinery. +USE_I18N = True +USE_L10N = True + + +# Absolute path to the directory that holds media. +# Example: "/home/media/media.lawrence.com/" +MEDIA_ROOT = PROJECT_ROOT + '/media/dynamic' +STATIC_ROOT = PROJECT_ROOT + '/../static/' + +# URL that handles the media served from MEDIA_ROOT. Make sure to use a +# trailing slash if there is a path component (optional in other cases). +# Examples: "http://media.lawrence.com", "http://example.com/media/" +MEDIA_URL = '/media/dynamic/' +STATIC_URL = '/media/static/' + +SESSION_COOKIE_NAME = "redakcja_sessionid" + +IMAGE_DIR = 'images/' + +BROKER_URL = 'django://' + +SHOW_APP_VERSION = False + +CAS_USER_ATTRS_MAP = { + 'email': 'email', 'firstname': 'first_name', 'lastname': 'last_name'} diff --git a/src/redakcja/settings/test.py b/src/redakcja/settings/test.py index 907fbc77..c026af0f 100644 --- a/src/redakcja/settings/test.py +++ b/src/redakcja/settings/test.py @@ -2,9 +2,7 @@ # Nose tests # -from redakcja.settings.common import * - -# ROOT_URLCONF = 'yourapp.settings.test.urls' +from redakcja.settings import * DATABASES = { 'default': { @@ -16,7 +14,6 @@ DATABASES = { 'PORT': '', # Set to empty string for default. Not used with sqlite3. } } - import tempfile CATALOGUE_REPO_PATH = tempfile.mkdtemp(prefix='redakcja-repo') diff --git a/src/redakcja/urls.py b/src/redakcja/urls.py index 2fb2d39d..1fe11d88 100644 --- a/src/redakcja/urls.py +++ b/src/redakcja/urls.py @@ -33,3 +33,6 @@ urlpatterns = [ if settings.DEBUG: urlpatterns += staticfiles_urlpatterns() urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + + import debug_toolbar + urlpatterns += (url(r'^__debug__/', include(debug_toolbar.urls))),