From 431813c9b1eac3d174e2dd3586f862bff6c239ee Mon Sep 17 00:00:00 2001 From: kmooney Date: Thu, 30 Jun 2011 12:26:50 -0500 Subject: [PATCH 01/31] Change to skip template loaders whose load method is not implemented. This happens with the Django cached template loader, in particular. --- dbtemplates/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dbtemplates/utils.py b/dbtemplates/utils.py index 61e9f14..8ebeff9 100644 --- a/dbtemplates/utils.py +++ b/dbtemplates/utils.py @@ -79,6 +79,8 @@ def get_template_source(name): source, origin = load_template_source(name) if source: return source + except NotImplementedError: + pass except TemplateDoesNotExist: pass if source is None and VERSION[:2] < (1, 2): From 2fc79eda7abaf36831a185c57729a9986b41b99b Mon Sep 17 00:00:00 2001 From: Evan Culver Date: Wed, 5 Sep 2012 14:27:55 -0400 Subject: [PATCH 02/31] Support for using redactorjs for editing templates. --- README.rst | 2 +- dbtemplates/admin.py | 4 ++++ dbtemplates/conf.py | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index e0e9977..2554ecb 100644 --- a/README.rst +++ b/README.rst @@ -20,4 +20,4 @@ The source code and issue tracker can be found on Github: https://github.com/jezdez/django-dbtemplates -.. _template loader: http://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types \ No newline at end of file +.. _template loader: http://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types diff --git a/dbtemplates/admin.py b/dbtemplates/admin.py index 9505d26..de66f44 100644 --- a/dbtemplates/admin.py +++ b/dbtemplates/admin.py @@ -67,6 +67,10 @@ if settings.DBTEMPLATES_USE_CODEMIRROR and settings.DBTEMPLATES_USE_TINYMCE: if settings.DBTEMPLATES_USE_TINYMCE: from tinymce.widgets import AdminTinyMCE TemplateContentTextArea = AdminTinyMCE +elif settings.DBTEMPLATES_USE_REDACTOR: + from redactor.widgets import RedactorEditor + TemplateContentTextArea = RedactorEditor + class TemplateAdminForm(forms.ModelForm): diff --git a/dbtemplates/conf.py b/dbtemplates/conf.py index 0bcf4ec..62111a6 100644 --- a/dbtemplates/conf.py +++ b/dbtemplates/conf.py @@ -10,6 +10,7 @@ class DbTemplatesConf(AppConf): USE_CODEMIRROR = False USE_REVERSION = False USE_TINYMCE = False + USE_REDACTOR = False ADD_DEFAULT_SITE = True AUTO_POPULATE_CONTENT = True MEDIA_PREFIX = None @@ -47,3 +48,9 @@ class DbTemplatesConf(AppConf): raise ImproperlyConfigured("Please add 'tinymce' to your " "INSTALLED_APPS setting to make use of it in dbtemplates.") return value + + def configure_use_redactor(self, value): + if value and 'redactor' not in settings.INSTALLED_APPS: + raise ImproperlyConfigured("Please add 'redactor' to your " + "INSTALLED_APPS setting to make use of it in dbtemplates.") + return value From c2d49e1d71415d238ff299ec433d843de72e20e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Kut=C3=BD?= <6du1ro.n@gmail.com> Date: Mon, 27 Apr 2015 23:40:42 +0200 Subject: [PATCH 03/31] hot-fixed populating template djagno 1.8+ --- dbtemplates/utils/template.py | 58 ++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/dbtemplates/utils/template.py b/dbtemplates/utils/template.py index 93bc1fd..97db4ab 100644 --- a/dbtemplates/utils/template.py +++ b/dbtemplates/utils/template.py @@ -21,31 +21,39 @@ def get_loaders(): def get_template_source(name): source = None - for loader in get_loaders(): - if loader.__module__.startswith('dbtemplates.'): - # Don't give a damn about dbtemplates' own loader. - continue - module = import_module(loader.__module__) - load_template_source = getattr(module, 'load_template_source', None) - if load_template_source is None: - load_template_source = loader.load_template_source - try: - source, origin = load_template_source(name) - if source: - return source - except NotImplementedError: - pass - except TemplateDoesNotExist: - pass - if source is None and VERSION[:2] < (1, 2): - # Django supported template source extraction still :/ - try: - from django.template.loader import find_template_source - template, origin = find_template_source(name, None) - if not hasattr(template, 'render'): - return template - except (ImportError, TemplateDoesNotExist): - pass + if VERSION[:2] < (1, 8): + for loader in get_loaders(): + if loader.__module__.startswith('dbtemplates.'): + # Don't give a damn about dbtemplates' own loader. + continue + module = import_module(loader.__module__) + load_template_source = getattr( + module, 'load_template_source', None) + if load_template_source is None: + load_template_source = loader.load_template_source + try: + source, origin = load_template_source(name) + if source: + return source + except NotImplementedError: + pass + except TemplateDoesNotExist: + pass + if source is None and VERSION[:2] < (1, 2): + # Django supported template source extraction still :/ + try: + from django.template.loader import find_template_source + template, origin = find_template_source(name, None) + if not hasattr(template, 'render'): + return template + except (ImportError, TemplateDoesNotExist): + pass + else: + from django.template.loader import get_template + template = get_template('base/page/adminlte.html') + with open(str(template.origin)) as source_file: + source = source_file.read() + return source return None From 50a877a7d504ca8b7f11d4fab46bd50aa2c450bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Kut=C3=BD?= <6du1ro.n@gmail.com> Date: Tue, 28 Apr 2015 01:00:24 +0200 Subject: [PATCH 04/31] fix name --- dbtemplates/utils/template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbtemplates/utils/template.py b/dbtemplates/utils/template.py index 97db4ab..3132c84 100644 --- a/dbtemplates/utils/template.py +++ b/dbtemplates/utils/template.py @@ -50,7 +50,7 @@ def get_template_source(name): pass else: from django.template.loader import get_template - template = get_template('base/page/adminlte.html') + template = get_template(name) with open(str(template.origin)) as source_file: source = source_file.read() return source From 15c4a5930b099ff92aa4ea3eee338569f8631bf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Kut=C3=BD?= <6du1ro.n@gmail.com> Date: Tue, 28 Apr 2015 01:03:45 +0200 Subject: [PATCH 05/31] fix loader for django 1.8 --- dbtemplates/loader.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/dbtemplates/loader.py b/dbtemplates/loader.py index 118de33..80af168 100644 --- a/dbtemplates/loader.py +++ b/dbtemplates/loader.py @@ -1,3 +1,4 @@ +import django from django.contrib.sites.models import Site from django.db import router from django.template import TemplateDoesNotExist @@ -7,8 +8,14 @@ from dbtemplates.utils.cache import (cache, get_cache_key, set_and_return, get_cache_notfound_key) from django.template.loader import BaseLoader +if django.get_version() >= '1.8': + from django.template.engine import Engine + from django.template.loaders.base import Loader as tLoaderCls +else: + from django.template.loader import BaseLoader as tLoaderCls # noqa -class Loader(BaseLoader): + +class Loader(tLoaderCls): """ A custom template loader to load templates from the database. From 685c77e718b0ca05c55a67c7a70e8492b73efe73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Kut=C3=BD?= <6du1ro.n@gmail.com> Date: Tue, 28 Apr 2015 11:16:06 +0200 Subject: [PATCH 06/31] proper solution --- dbtemplates/utils/template.py | 88 +++++++++++++++++------------------ 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/dbtemplates/utils/template.py b/dbtemplates/utils/template.py index 3132c84..526fcb7 100644 --- a/dbtemplates/utils/template.py +++ b/dbtemplates/utils/template.py @@ -5,55 +5,55 @@ from django.utils.importlib import import_module def get_loaders(): - from django.template.loader import template_source_loaders - if template_source_loaders is None: - try: - from django.template.loader import find_template as finder - except ImportError: - from django.template.loader import find_template_source as finder # noqa - try: - source, name = finder('test') - except TemplateDoesNotExist: - pass + if VERSION[:2] < (1, 8): from django.template.loader import template_source_loaders - return template_source_loaders or [] + if template_source_loaders is None: + try: + from django.template.loader import find_template as finder + except ImportError: + from django.template.loader import find_template_source as finder # noqa + try: + source, name = finder('test') + except TemplateDoesNotExist: + pass + from django.template.loader import template_source_loaders + return template_source_loaders or [] + else: + from django.template.loader import _engine_list + loaders = [] + for engine in _engine_list(): + loaders.extend(engine.engine.template_loaders) + return loaders def get_template_source(name): source = None - if VERSION[:2] < (1, 8): - for loader in get_loaders(): - if loader.__module__.startswith('dbtemplates.'): - # Don't give a damn about dbtemplates' own loader. - continue - module = import_module(loader.__module__) - load_template_source = getattr( - module, 'load_template_source', None) - if load_template_source is None: - load_template_source = loader.load_template_source - try: - source, origin = load_template_source(name) - if source: - return source - except NotImplementedError: - pass - except TemplateDoesNotExist: - pass - if source is None and VERSION[:2] < (1, 2): - # Django supported template source extraction still :/ - try: - from django.template.loader import find_template_source - template, origin = find_template_source(name, None) - if not hasattr(template, 'render'): - return template - except (ImportError, TemplateDoesNotExist): - pass - else: - from django.template.loader import get_template - template = get_template(name) - with open(str(template.origin)) as source_file: - source = source_file.read() - return source + for loader in get_loaders(): + if loader.__module__.startswith('dbtemplates.'): + # Don't give a damn about dbtemplates' own loader. + continue + module = import_module(loader.__module__) + load_template_source = getattr( + module, 'load_template_source', None) + if load_template_source is None: + load_template_source = loader.load_template_source + try: + source, origin = load_template_source(name) + if source: + return source + except NotImplementedError: + pass + except TemplateDoesNotExist: + pass + if source is None and VERSION[:2] < (1, 2): + # Django supported template source extraction still :/ + try: + from django.template.loader import find_template_source + template, origin = find_template_source(name, None) + if not hasattr(template, 'render'): + return template + except (ImportError, TemplateDoesNotExist): + pass return None From 984f83c0a84df2b8d66546cab414835bfc40fa80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Kut=C3=BD?= <6du1ro.n@gmail.com> Date: Tue, 28 Apr 2015 11:19:19 +0200 Subject: [PATCH 07/31] update dj versions --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 71163ca..544dbd4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,8 @@ env: - DJANGO=1.3.7 - DJANGO=1.4.5 - DJANGO=1.5.1 + - DJANGO=1.7.7 + - DJANGO=1.8 branches: only: - develop From 658aca88dc800aaf58798eb5c49b32b52c9b8cce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Kut=C3=BD?= <6du1ro.n@gmail.com> Date: Mon, 15 Jun 2015 16:35:15 +0200 Subject: [PATCH 08/31] bump version --- dbtemplates/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbtemplates/__init__.py b/dbtemplates/__init__.py index 6524f6c..437285b 100644 --- a/dbtemplates/__init__.py +++ b/dbtemplates/__init__.py @@ -1,2 +1,2 @@ # following PEP 386 -__version__ = "1.3" +__version__ = "1.3.1" From 078d5563904ad1fd35af80438d68660e54e81536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Kut=C3=BD?= <6du1ro.n@gmail.com> Date: Mon, 15 Jun 2015 16:44:34 +0200 Subject: [PATCH 09/31] fix flake8 --- dbtemplates/loader.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/dbtemplates/loader.py b/dbtemplates/loader.py index 80af168..4355772 100644 --- a/dbtemplates/loader.py +++ b/dbtemplates/loader.py @@ -6,10 +6,8 @@ from django.template import TemplateDoesNotExist from dbtemplates.models import Template from dbtemplates.utils.cache import (cache, get_cache_key, set_and_return, get_cache_notfound_key) -from django.template.loader import BaseLoader if django.get_version() >= '1.8': - from django.template.engine import Engine from django.template.loaders.base import Loader as tLoaderCls else: from django.template.loader import BaseLoader as tLoaderCls # noqa From 0e97716488690392f95e60efb2a83ebcaf49cc13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Kut=C3=BD?= <6du1ro.n@gmail.com> Date: Mon, 15 Jun 2015 16:54:21 +0200 Subject: [PATCH 10/31] ModelForm now requires either fields or exclude - mentoined in #52 thanks @volksman --- dbtemplates/admin.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dbtemplates/admin.py b/dbtemplates/admin.py index b6063d8..14b35f9 100644 --- a/dbtemplates/admin.py +++ b/dbtemplates/admin.py @@ -19,6 +19,7 @@ else: class CodeMirrorTextArea(forms.Textarea): + """ A custom widget for the CodeMirror browser editor to be used with the content field of the Template model. @@ -73,8 +74,8 @@ elif settings.DBTEMPLATES_USE_REDACTOR: TemplateContentTextArea = RedactorEditor - class TemplateAdminForm(forms.ModelForm): + """ Custom AdminForm to make the content textarea wider. """ @@ -85,6 +86,7 @@ class TemplateAdminForm(forms.ModelForm): class Meta: model = Template fields = ('name', 'content', 'sites', 'creation_date', 'last_changed') + fields = "__all__" class TemplateAdmin(TemplateModelAdmin): From 16fe97575cf18c11fb508aa08578c8eb3082bb1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Kut=C3=BD?= <6du1ro.n@gmail.com> Date: Mon, 15 Jun 2015 20:19:36 +0200 Subject: [PATCH 11/31] pep8 cleanup and fix test runner for new django --- dbtemplates/conf.py | 3 ++- dbtemplates/test_settings.py | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/dbtemplates/conf.py b/dbtemplates/conf.py index 7ae23a6..2a420a3 100644 --- a/dbtemplates/conf.py +++ b/dbtemplates/conf.py @@ -54,5 +54,6 @@ class DbTemplatesConf(AppConf): def configure_use_redactor(self, value): if value and 'redactor' not in settings.INSTALLED_APPS: raise ImproperlyConfigured("Please add 'redactor' to your " - "INSTALLED_APPS setting to make use of it in dbtemplates.") + "INSTALLED_APPS setting to make " + "use of it in dbtemplates.") return value diff --git a/dbtemplates/test_settings.py b/dbtemplates/test_settings.py index a948cba..ac71738 100644 --- a/dbtemplates/test_settings.py +++ b/dbtemplates/test_settings.py @@ -1,3 +1,6 @@ + +import django + DBTEMPLATES_CACHE_BACKEND = 'dummy://' DATABASE_ENGINE = 'sqlite3' @@ -29,4 +32,5 @@ TEMPLATE_LOADERS = ( 'dbtemplates.loader.Loader', ) -TEST_RUNNER = 'discover_runner.DiscoverRunner' +if django.get_version() <= '1.6': + TEST_RUNNER = 'discover_runner.DiscoverRunner' From b47af2e1ff1c6b04718faeb746d58f1f328614ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Kut=C3=BD?= <6du1ro.n@gmail.com> Date: Mon, 15 Jun 2015 20:36:24 +0200 Subject: [PATCH 12/31] added middleware classes --- dbtemplates/test_settings.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dbtemplates/test_settings.py b/dbtemplates/test_settings.py index ac71738..bed0b91 100644 --- a/dbtemplates/test_settings.py +++ b/dbtemplates/test_settings.py @@ -26,6 +26,11 @@ INSTALLED_APPS = [ 'dbtemplates', ] +MIDDLEWARE_CLASSES = ( + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + ) + TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', From c9569a81db6e2f8c01fa45ac54a4327cbbf4e00e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Kut=C3=BD?= <6du1ro.n@gmail.com> Date: Mon, 15 Jun 2015 21:03:09 +0200 Subject: [PATCH 13/31] update readme and added notice about compatibility, bump version and changelog --- README.rst | 6 ++++++ dbtemplates/__init__.py | 2 +- docs/changelog.txt | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 2554ecb..495f067 100644 --- a/README.rst +++ b/README.rst @@ -20,4 +20,10 @@ The source code and issue tracker can be found on Github: https://github.com/jezdez/django-dbtemplates +Compatibility Roadmap +--------------------- + +Since 1.3.2 ``dbtemplates`` dropped support for Django < 1.4 +Since 1.4 will be supported only Django >= 1.7, please freeze your requirements on specific version of dbtemplates ! + .. _template loader: http://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types diff --git a/dbtemplates/__init__.py b/dbtemplates/__init__.py index 437285b..974a8ff 100644 --- a/dbtemplates/__init__.py +++ b/dbtemplates/__init__.py @@ -1,2 +1,2 @@ # following PEP 386 -__version__ = "1.3.1" +__version__ = "1.3.2" diff --git a/docs/changelog.txt b/docs/changelog.txt index 43a9f28..545c9dc 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -1,6 +1,14 @@ Changelog ========= +v1.3.2 (2015-06-15) +------------------- + +* support for Django 1.8 (not full, but usable) +* support for RedactorJS + +thanks for contrib - @eculver, @kmooney, @volksman + v1.3.1 (2012-05-23) ------------------- From 51b62d9a6265bd962be29118364a0fe60d28da86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Kut=C3=BD?= <6du1ro.n@gmail.com> Date: Mon, 15 Jun 2015 21:17:18 +0200 Subject: [PATCH 14/31] omg fix pep8 passing --- dbtemplates/test_settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbtemplates/test_settings.py b/dbtemplates/test_settings.py index bed0b91..2a358cf 100644 --- a/dbtemplates/test_settings.py +++ b/dbtemplates/test_settings.py @@ -29,7 +29,7 @@ INSTALLED_APPS = [ MIDDLEWARE_CLASSES = ( 'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', - ) +) TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.Loader', From edbb5e1ef0e139af635f850c32c10ae43e03c767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Kut=C3=BD?= <6du1ro.n@gmail.com> Date: Mon, 15 Jun 2015 22:39:17 +0200 Subject: [PATCH 15/31] exclude python 2.6 from Dj 1.7 and 1.8 where was dropped support for this version --- .travis.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 544dbd4..043941a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,8 +16,14 @@ env: - DJANGO=1.3.7 - DJANGO=1.4.5 - DJANGO=1.5.1 - - DJANGO=1.7.7 + - DJANGO=1.7.8 - DJANGO=1.8 +matrix: + exclude: + - python: "2.6" + env: DJANGO="Django>=1.7,<1.8" + - python: "2.6" + env: DJANGO="Django>=1.8,<1.9" branches: only: - develop From 99ed8b2ce321bb6ba786824bdb5691ef36b0d478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Kut=C3=BD?= <6du1ro.n@gmail.com> Date: Mon, 15 Jun 2015 22:44:44 +0200 Subject: [PATCH 16/31] fix app dirs on django 1.8 --- dbtemplates/management/commands/sync_templates.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/dbtemplates/management/commands/sync_templates.py b/dbtemplates/management/commands/sync_templates.py index 33feb52..1d6e428 100644 --- a/dbtemplates/management/commands/sync_templates.py +++ b/dbtemplates/management/commands/sync_templates.py @@ -1,10 +1,9 @@ import os import codecs from optparse import make_option - +from django import VERSION from django.contrib.sites.models import Site from django.core.management.base import CommandError, NoArgsCommand -from django.template.loaders.app_directories import app_template_dirs from dbtemplates.conf import settings from dbtemplates.models import Template @@ -12,6 +11,14 @@ from dbtemplates.models import Template ALWAYS_ASK, FILES_TO_DATABASE, DATABASE_TO_FILES = ('0', '1', '2') +if VERSION[:2] < (1, 8): + from django.template.loaders.app_directories import app_template_dirs + DIRS = settings.TEMPLATE_DIRS +else: + from django.template.utils import get_app_template_dirs + app_template_dirs = get_app_template_dirs('templates') + + class Command(NoArgsCommand): help = "Syncs file system templates with the database bidirectionally." option_list = NoArgsCommand.option_list + ( @@ -103,7 +110,8 @@ class Command(NoArgsCommand): try: os.remove(path) except OSError: - raise CommandError(u"Couldn't delete %s" % path) + raise CommandError( + u"Couldn't delete %s" % path) elif confirm == DATABASE_TO_FILES: f = codecs.open(path, 'w', 'utf-8') try: From 201077e11bd7364280dcb6e689a21d25735e4f93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Kut=C3=BD?= <6du1ro.n@gmail.com> Date: Mon, 15 Jun 2015 23:09:51 +0200 Subject: [PATCH 17/31] properly collect template dirs for all available template engines in dj 1.8 and prettify readme --- README.rst | 4 ++-- dbtemplates/management/commands/sync_templates.py | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 495f067..a6638ac 100644 --- a/README.rst +++ b/README.rst @@ -23,7 +23,7 @@ https://github.com/jezdez/django-dbtemplates Compatibility Roadmap --------------------- -Since 1.3.2 ``dbtemplates`` dropped support for Django < 1.4 -Since 1.4 will be supported only Django >= 1.7, please freeze your requirements on specific version of dbtemplates ! +- 1.3.2 ``dbtemplates`` dropped support for Django < 1.4 +- 1.4 will be supported only Django >= 1.7, please freeze your requirements on specific version of ``dbtemplates`` ! .. _template loader: http://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types diff --git a/dbtemplates/management/commands/sync_templates.py b/dbtemplates/management/commands/sync_templates.py index 1d6e428..a25b4b0 100644 --- a/dbtemplates/management/commands/sync_templates.py +++ b/dbtemplates/management/commands/sync_templates.py @@ -10,12 +10,16 @@ from dbtemplates.models import Template ALWAYS_ASK, FILES_TO_DATABASE, DATABASE_TO_FILES = ('0', '1', '2') +DIRS = [] if VERSION[:2] < (1, 8): from django.template.loaders.app_directories import app_template_dirs DIRS = settings.TEMPLATE_DIRS else: from django.template.utils import get_app_template_dirs + from django.template.loader import _engine_list + for engine in _engine_list(): + DIRS.extend(engine.dirs) app_template_dirs = get_app_template_dirs('templates') @@ -63,9 +67,9 @@ class Command(NoArgsCommand): "list or tuple.") if app_first: - tpl_dirs = app_template_dirs + settings.TEMPLATE_DIRS + tpl_dirs = app_template_dirs + DIRS else: - tpl_dirs = settings.TEMPLATE_DIRS + app_template_dirs + tpl_dirs = DIRS + app_template_dirs templatedirs = [d for d in tpl_dirs if os.path.isdir(d)] for templatedir in templatedirs: From acdf9dc8e5b43f026914920050c318651183d60d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Kut=C3=BD?= <6du1ro.n@gmail.com> Date: Mon, 15 Jun 2015 23:15:27 +0200 Subject: [PATCH 18/31] properly exclude python 2.6 from new djangos --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 043941a..ced970e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,9 +21,9 @@ env: matrix: exclude: - python: "2.6" - env: DJANGO="Django>=1.7,<1.8" + env: DJANGO="1.7.8" - python: "2.6" - env: DJANGO="Django>=1.8,<1.9" + env: DJANGO="1.8" branches: only: - develop From 926a3215eb6735f25ce3bca8f644c546a0b9ae86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Kut=C3=BD?= <6du1ro.n@gmail.com> Date: Mon, 15 Jun 2015 23:19:22 +0200 Subject: [PATCH 19/31] cleanup yaml --- .travis.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index ced970e..25eb0f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: python python: - - "2.6" - - "2.7" + - 2.6 + - 2.7 before_install: - export DJANGO_SETTINGS_MODULE=dbtemplates.test_settings install: @@ -20,10 +20,10 @@ env: - DJANGO=1.8 matrix: exclude: - - python: "2.6" - env: DJANGO="1.7.8" - - python: "2.6" - env: DJANGO="1.8" + - python: 2.6 + env: DJANGO=1.7.8 + - python: 2.6 + env: DJANGO=1.8 branches: only: - develop From 464425b236969ddc77cd7a297231b9c7a747f61c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Kut=C3=BD?= <6du1ro.n@gmail.com> Date: Tue, 16 Jun 2015 00:07:27 +0200 Subject: [PATCH 20/31] fix settings runtime patching which cause fails because if we set correct template dirs is not there test dirs --- dbtemplates/test_cases.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dbtemplates/test_cases.py b/dbtemplates/test_cases.py index 1878b29..be9578e 100644 --- a/dbtemplates/test_cases.py +++ b/dbtemplates/test_cases.py @@ -106,6 +106,11 @@ class DbTemplatesTestCase(TestCase): try: temp_template.write('temp test') settings.TEMPLATE_DIRS = (temp_template_dir,) + # these works well if is not settings patched at runtime + # for supporting django < 1.7 tests we must patch dirs in runtime + from dbtemplates.management.commands import sync_templates + sync_templates.DIRS = settings.TEMPLATE_DIRS + self.assertFalse( Template.objects.filter(name='temp_test.html').exists()) call_command('sync_templates', force=True, From 42590af74434c2dcd2ec1a1d27415386bdcad8f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Kut=C3=BD?= <6du1ro.n@gmail.com> Date: Mon, 6 Jul 2015 22:16:43 +0200 Subject: [PATCH 21/31] fixed (fields.W340) null has no effect on ManyToManyField and import sorting --- dbtemplates/models.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/dbtemplates/models.py b/dbtemplates/models.py index 02e8081..b8e668c 100644 --- a/dbtemplates/models.py +++ b/dbtemplates/models.py @@ -1,16 +1,15 @@ # -*- coding: utf-8 -*- +from dbtemplates.conf import settings +from dbtemplates.utils.cache import (add_template_to_cache, + remove_cached_template) +from dbtemplates.utils.template import get_template_source +from django.contrib.sites.managers import CurrentSiteManager +from django.contrib.sites.models import Site from django.db import models from django.db.models import signals from django.template import TemplateDoesNotExist from django.utils.translation import ugettext_lazy as _ -from django.contrib.sites.models import Site -from django.contrib.sites.managers import CurrentSiteManager - -from dbtemplates.conf import settings -from dbtemplates.utils.cache import add_template_to_cache, remove_cached_template -from dbtemplates.utils.template import get_template_source - try: from django.utils.timezone import now except ImportError: @@ -27,7 +26,7 @@ class Template(models.Model): help_text=_("Example: 'flatpages/default.html'")) content = models.TextField(_('content'), blank=True) sites = models.ManyToManyField(Site, verbose_name=_(u'sites'), - blank=True, null=True) + blank=True) creation_date = models.DateTimeField(_('creation date'), default=now) last_changed = models.DateTimeField(_('last changed'), From 04c2d12dbda62df277f8e845d3fafdf64dbeb465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Kut=C3=BD?= <6du1ro.n@gmail.com> Date: Tue, 14 Jul 2015 23:30:53 +0200 Subject: [PATCH 22/31] added django migrations and south moved to own directory --- dbtemplates/migrations/0001_initial.py | 85 ++++++++----------- dbtemplates/south_migrations/0001_initial.py | 55 ++++++++++++ .../0002_auto__del_unique_template_name.py | 0 dbtemplates/south_migrations/__init__.py | 0 4 files changed, 89 insertions(+), 51 deletions(-) create mode 100644 dbtemplates/south_migrations/0001_initial.py rename dbtemplates/{migrations => south_migrations}/0002_auto__del_unique_template_name.py (100%) create mode 100644 dbtemplates/south_migrations/__init__.py diff --git a/dbtemplates/migrations/0001_initial.py b/dbtemplates/migrations/0001_initial.py index 0e08603..13a5ba0 100644 --- a/dbtemplates/migrations/0001_initial.py +++ b/dbtemplates/migrations/0001_initial.py @@ -1,55 +1,38 @@ -# encoding: utf-8 -import datetime -from south.db import db -from south.v2 import SchemaMigration -from django.db import models +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations +import django.utils.timezone +import django.db.models.manager +import django.contrib.sites.managers -class Migration(SchemaMigration): +class Migration(migrations.Migration): - def forwards(self, orm): + dependencies = [ + ('sites', '0001_initial'), + ] - # Adding model 'Template' - db.create_table('django_template', ( - ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), - ('name', self.gf('django.db.models.fields.CharField')(unique=True, max_length=100)), - ('content', self.gf('django.db.models.fields.TextField')(blank=True)), - ('creation_date', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now)), - ('last_changed', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now)), - )) - db.send_create_signal('dbtemplates', ['Template']) - - # Adding M2M table for field sites on 'Template' - db.create_table('django_template_sites', ( - ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)), - ('template', models.ForeignKey(orm['dbtemplates.template'], null=False)), - ('site', models.ForeignKey(orm['sites.site'], null=False)) - )) - db.create_unique('django_template_sites', ['template_id', 'site_id']) - - def backwards(self, orm): - # Deleting model 'Template' - db.delete_table('django_template') - - # Removing M2M table for field sites on 'Template' - db.delete_table('django_template_sites') - - models = { - 'dbtemplates.template': { - 'Meta': {'ordering': "('name',)", 'object_name': 'Template', 'db_table': "'django_template'"}, - 'content': ('django.db.models.fields.TextField', [], {'blank': 'True'}), - 'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'last_changed': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), - 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}), - 'sites': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['sites.Site']", 'symmetrical': 'False'}) - }, - 'sites.site': { - 'Meta': {'ordering': "('domain',)", 'object_name': 'Site', 'db_table': "'django_site'"}, - 'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) - } - } - - complete_apps = ['dbtemplates'] + operations = [ + migrations.CreateModel( + name='Template', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('name', models.CharField(help_text="Example: 'flatpages/default.html'", max_length=100, verbose_name='name')), + ('content', models.TextField(verbose_name='content', blank=True)), + ('creation_date', models.DateTimeField(default=django.utils.timezone.now, verbose_name='creation date')), + ('last_changed', models.DateTimeField(default=django.utils.timezone.now, verbose_name='last changed')), + ('sites', models.ManyToManyField(to='sites.Site', verbose_name='sites', blank=True)), + ], + options={ + 'ordering': ('name',), + 'db_table': 'django_template', + 'verbose_name': 'template', + 'verbose_name_plural': 'templates', + }, + managers=[ + ('objects', django.db.models.manager.Manager()), + ('on_site', django.contrib.sites.managers.CurrentSiteManager(b'sites')), + ], + ), + ] diff --git a/dbtemplates/south_migrations/0001_initial.py b/dbtemplates/south_migrations/0001_initial.py new file mode 100644 index 0000000..0e08603 --- /dev/null +++ b/dbtemplates/south_migrations/0001_initial.py @@ -0,0 +1,55 @@ +# encoding: utf-8 +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + + +class Migration(SchemaMigration): + + def forwards(self, orm): + + # Adding model 'Template' + db.create_table('django_template', ( + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('name', self.gf('django.db.models.fields.CharField')(unique=True, max_length=100)), + ('content', self.gf('django.db.models.fields.TextField')(blank=True)), + ('creation_date', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now)), + ('last_changed', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now)), + )) + db.send_create_signal('dbtemplates', ['Template']) + + # Adding M2M table for field sites on 'Template' + db.create_table('django_template_sites', ( + ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)), + ('template', models.ForeignKey(orm['dbtemplates.template'], null=False)), + ('site', models.ForeignKey(orm['sites.site'], null=False)) + )) + db.create_unique('django_template_sites', ['template_id', 'site_id']) + + def backwards(self, orm): + # Deleting model 'Template' + db.delete_table('django_template') + + # Removing M2M table for field sites on 'Template' + db.delete_table('django_template_sites') + + models = { + 'dbtemplates.template': { + 'Meta': {'ordering': "('name',)", 'object_name': 'Template', 'db_table': "'django_template'"}, + 'content': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'last_changed': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}), + 'sites': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['sites.Site']", 'symmetrical': 'False'}) + }, + 'sites.site': { + 'Meta': {'ordering': "('domain',)", 'object_name': 'Site', 'db_table': "'django_site'"}, + 'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + } + } + + complete_apps = ['dbtemplates'] diff --git a/dbtemplates/migrations/0002_auto__del_unique_template_name.py b/dbtemplates/south_migrations/0002_auto__del_unique_template_name.py similarity index 100% rename from dbtemplates/migrations/0002_auto__del_unique_template_name.py rename to dbtemplates/south_migrations/0002_auto__del_unique_template_name.py diff --git a/dbtemplates/south_migrations/__init__.py b/dbtemplates/south_migrations/__init__.py new file mode 100644 index 0000000..e69de29 From 70da2e6a48a99c5b28b200a9755c7dcc52a1bceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Kut=C3=BD?= <6du1ro.n@gmail.com> Date: Wed, 15 Jul 2015 00:08:45 +0200 Subject: [PATCH 23/31] use migrations generated from django 1.7 --- dbtemplates/migrations/0001_initial.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/dbtemplates/migrations/0001_initial.py b/dbtemplates/migrations/0001_initial.py index 13a5ba0..fd51839 100644 --- a/dbtemplates/migrations/0001_initial.py +++ b/dbtemplates/migrations/0001_initial.py @@ -3,8 +3,6 @@ from __future__ import unicode_literals from django.db import models, migrations import django.utils.timezone -import django.db.models.manager -import django.contrib.sites.managers class Migration(migrations.Migration): @@ -30,9 +28,6 @@ class Migration(migrations.Migration): 'verbose_name': 'template', 'verbose_name_plural': 'templates', }, - managers=[ - ('objects', django.db.models.manager.Manager()), - ('on_site', django.contrib.sites.managers.CurrentSiteManager(b'sites')), - ], + bases=(models.Model,), ), ] From c55e2220b346b5a3e147122096e1b5e5daf7735e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Kut=C3=BD?= <6du1ro.n@gmail.com> Date: Thu, 23 Jul 2015 15:42:07 +0200 Subject: [PATCH 24/31] use managers for django 1.8+ --- dbtemplates/migrations/0001_initial.py | 78 +++++++++++++++++++------- 1 file changed, 58 insertions(+), 20 deletions(-) diff --git a/dbtemplates/migrations/0001_initial.py b/dbtemplates/migrations/0001_initial.py index fd51839..c307d7e 100644 --- a/dbtemplates/migrations/0001_initial.py +++ b/dbtemplates/migrations/0001_initial.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals +import django from django.db import models, migrations import django.utils.timezone @@ -11,23 +12,60 @@ class Migration(migrations.Migration): ('sites', '0001_initial'), ] - operations = [ - migrations.CreateModel( - name='Template', - fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), - ('name', models.CharField(help_text="Example: 'flatpages/default.html'", max_length=100, verbose_name='name')), - ('content', models.TextField(verbose_name='content', blank=True)), - ('creation_date', models.DateTimeField(default=django.utils.timezone.now, verbose_name='creation date')), - ('last_changed', models.DateTimeField(default=django.utils.timezone.now, verbose_name='last changed')), - ('sites', models.ManyToManyField(to='sites.Site', verbose_name='sites', blank=True)), - ], - options={ - 'ordering': ('name',), - 'db_table': 'django_template', - 'verbose_name': 'template', - 'verbose_name_plural': 'templates', - }, - bases=(models.Model,), - ), - ] + if django.get_version() >= '1.8': + operations = [ + migrations.CreateModel( + name='Template', + fields=[ + ('id', models.AutoField( + verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('name', models.CharField( + help_text="Example: 'flatpages/default.html'", max_length=100, verbose_name='name')), + ('content', models.TextField(verbose_name='content', blank=True)), + ('creation_date', models.DateTimeField( + default=django.utils.timezone.now, verbose_name='creation date')), + ('last_changed', models.DateTimeField( + default=django.utils.timezone.now, verbose_name='last changed')), + ('sites', models.ManyToManyField( + to='sites.Site', verbose_name='sites', blank=True)), + ], + options={ + 'ordering': ('name',), + 'db_table': 'django_template', + 'verbose_name': 'template', + 'verbose_name_plural': 'templates', + }, + bases=(models.Model,), + managers = [ + ('objects', django.db.models.manager.Manager()), + ('on_site', django.contrib.sites.managers.CurrentSiteManager( + b'sites')), + ], + ), + ] + else: + operations = [ + migrations.CreateModel( + name='Template', + fields=[ + ('id', models.AutoField( + verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('name', models.CharField( + help_text="Example: 'flatpages/default.html'", max_length=100, verbose_name='name')), + ('content', models.TextField(verbose_name='content', blank=True)), + ('creation_date', models.DateTimeField( + default=django.utils.timezone.now, verbose_name='creation date')), + ('last_changed', models.DateTimeField( + default=django.utils.timezone.now, verbose_name='last changed')), + ('sites', models.ManyToManyField( + to='sites.Site', verbose_name='sites', blank=True)), + ], + options={ + 'ordering': ('name',), + 'db_table': 'django_template', + 'verbose_name': 'template', + 'verbose_name_plural': 'templates', + }, + bases=(models.Model,), + ), + ] From 59c65c56ab0dc5ad9e6b79e28fcd67e85e12cf52 Mon Sep 17 00:00:00 2001 From: Artur Barseghyan Date: Tue, 18 Aug 2015 14:15:26 +0200 Subject: [PATCH 25/31] fix setup for python 3 --- setup.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 778878f..fdd5aa3 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,9 @@ from setuptools import setup, find_packages def read(*parts): - return codecs.open(os.path.join(os.path.dirname(__file__), *parts)).read() + filename = os.path.join(os.path.dirname(__file__), *parts) + with codecs.open(filename, encoding='utf-8') as fp: + return fp.read() def find_version(*file_paths): From bb9199b0be91c507a63d88c5788911398a939dee Mon Sep 17 00:00:00 2001 From: Artur Barseghyan Date: Tue, 18 Aug 2015 16:29:14 +0200 Subject: [PATCH 26/31] python 3 fix --- dbtemplates/utils/template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbtemplates/utils/template.py b/dbtemplates/utils/template.py index 93bc1fd..ef4579e 100644 --- a/dbtemplates/utils/template.py +++ b/dbtemplates/utils/template.py @@ -52,6 +52,6 @@ def get_template_source(name): def check_template_syntax(template): try: Template(template.content) - except TemplateSyntaxError, e: + except TemplateSyntaxError as e: return (False, e) return (True, None) From c8a048352ec3ac2939e0b3a30005319b0b67d494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Kut=C3=BD?= <6du1ro.n@gmail.com> Date: Wed, 19 Aug 2015 11:42:39 +0200 Subject: [PATCH 27/31] Fix some Python 3 issues - thanks @vikingco --- dbtemplates/conf.py | 3 ++- dbtemplates/management/commands/sync_templates.py | 4 ++++ dbtemplates/utils/template.py | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/dbtemplates/conf.py b/dbtemplates/conf.py index 2a420a3..4abb258 100644 --- a/dbtemplates/conf.py +++ b/dbtemplates/conf.py @@ -2,6 +2,7 @@ import posixpath from django.core.exceptions import ImproperlyConfigured from django.conf import settings +from django.utils.six import string_types from appconf import AppConf @@ -31,7 +32,7 @@ class DbTemplatesConf(AppConf): return "dbtemplates" else: return "default" - if isinstance(value, basestring) and value.startswith("dbtemplates."): + if isinstance(value, string_types) and value.startswith("dbtemplates."): raise ImproperlyConfigured("Please upgrade to one of the " "supported backends as defined " "in the Django docs.") diff --git a/dbtemplates/management/commands/sync_templates.py b/dbtemplates/management/commands/sync_templates.py index a25b4b0..3529e82 100644 --- a/dbtemplates/management/commands/sync_templates.py +++ b/dbtemplates/management/commands/sync_templates.py @@ -4,6 +4,10 @@ from optparse import make_option from django import VERSION from django.contrib.sites.models import Site from django.core.management.base import CommandError, NoArgsCommand +try: + from django.utils.six import input as raw_input +except ImportError: + pass from dbtemplates.conf import settings from dbtemplates.models import Template diff --git a/dbtemplates/utils/template.py b/dbtemplates/utils/template.py index 526fcb7..c7b224a 100644 --- a/dbtemplates/utils/template.py +++ b/dbtemplates/utils/template.py @@ -60,6 +60,6 @@ def get_template_source(name): def check_template_syntax(template): try: Template(template.content) - except TemplateSyntaxError, e: + except TemplateSyntaxError as e: return (False, e) return (True, None) From 35a57bbcb15e4a139a995990694eb967ba5949ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Kut=C3=BD?= <6du1ro.n@gmail.com> Date: Wed, 19 Aug 2015 14:56:00 +0200 Subject: [PATCH 28/31] drop support for django < 1.3.7 --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 25eb0f4..bdca644 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,6 @@ script: - coverage run --branch --source=dbtemplates `which django-admin.py` test dbtemplates - coverage report --omit="dbtemplates/test*,dbtemplates/migrations*" env: - - DJANGO=1.3.7 - DJANGO=1.4.5 - DJANGO=1.5.1 - DJANGO=1.7.8 From 308d03ba98111ab0a693b9bfe833806307427f7f Mon Sep 17 00:00:00 2001 From: "Philippe O. Wagner" Date: Thu, 17 Sep 2015 12:12:20 +0200 Subject: [PATCH 29/31] Docs update for ``TEMPLATES.OPTIONS.loaders`` config. Works for Django 1.8+ --- docs/overview.txt | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/docs/overview.txt b/docs/overview.txt index 8d67121..8c6c69d 100644 --- a/docs/overview.txt +++ b/docs/overview.txt @@ -24,21 +24,41 @@ Setup 'dbtemplates', ) - * Add ``dbtemplates.loader.Loader`` to the ``TEMPLATE_LOADERS`` list + * Add ``dbtemplates.loader.Loader`` to the ``TEMPLATES.OPTIONS.loaders`` list in the settings.py of your Django project. It should look something like this:: - TEMPLATE_LOADERS = ( - 'django.template.loaders.filesystem.Loader', - 'django.template.loaders.app_directories.Loader', - 'dbtemplates.loader.Loader', - ) + TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [ # your template dirs here + ], + 'APP_DIRS': False, + 'OPTIONS': { + 'context_processors': [ + 'django.contrib.auth.context_processors.auth', + '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.contrib.messages.context_processors.messages', + 'django.template.context_processors.request', + ], + 'loaders': [ + 'django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader', + 'dbtemplates.loader.Loader', + ], + }, + }, + ] - Order of TEMPLATE_LOADERS is important. In the former example, templates from database + Order of ``TEMPLATES.OPTIONS.loaders`` is important. In the former example, templates from database will be used as a fallback (ie. when template does not exists in other locations). If you want template from database to be used to override templates in other locations, - put ``dbtemplates.loader.Loader`` at beginning of ``TEMPLATE_LOADERS`` settting. + put ``dbtemplates.loader.Loader`` at beginning of ``loaders``. 4. Sync your database ``python manage.py syncdb`` 5. Restart your Django server From 9648555473aced8e58fe0b83c68d0655945b8eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Kut=C3=BD?= <6du1ro.n@gmail.com> Date: Thu, 17 Sep 2015 21:15:10 +0200 Subject: [PATCH 30/31] fix RemovedInDjango19Warning: 'get_cache' is deprecated in favor of 'caches'. --- dbtemplates/utils/cache.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/dbtemplates/utils/cache.py b/dbtemplates/utils/cache.py index 13a48d7..077c597 100644 --- a/dbtemplates/utils/cache.py +++ b/dbtemplates/utils/cache.py @@ -1,5 +1,4 @@ -from django.core.cache import get_cache - +from django.core import signals from django.contrib.sites.models import Site from django.template.defaultfilters import slugify @@ -7,7 +6,22 @@ from dbtemplates.conf import settings def get_cache_backend(): - return get_cache(settings.DBTEMPLATES_CACHE_BACKEND) + """ + Compatibilty wrapper for getting Django's cache backend instance + """ + try: + from django.core.cache import _create_cache + except ImportError: + # Django < 1.7 + from django.core.cache import get_cache as _get_cache + return _get_cache(settings.DBTEMPLATES_CACHE_BACKEND) + + cache = _create_cache(settings.DBTEMPLATES_CACHE_BACKEND) + # Some caches -- python-memcached in particular -- need to do a cleanup at the + # end of a request cycle. If not implemented in a particular backend + # cache.close is a no-op + signals.request_finished.connect(cache.close) + return cache cache = get_cache_backend() From 2c7afb6a1a21caa188ebaaa3ed86a2e79063e87e Mon Sep 17 00:00:00 2001 From: Mikhail Polykovskij Date: Fri, 16 Oct 2015 17:05:42 +0500 Subject: [PATCH 31/31] Fix localization --- dbtemplates/locale/ru/LC_MESSAGES/django.mo | Bin 2837 -> 2847 bytes dbtemplates/locale/ru/LC_MESSAGES/django.po | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/dbtemplates/locale/ru/LC_MESSAGES/django.mo b/dbtemplates/locale/ru/LC_MESSAGES/django.mo index 82f769ef15b93418388f55c33a214a3b365c95ec..8081c189f18d756c34da54420f3f121fc98eb60f 100644 GIT binary patch delta 353 zcmX}n&kF%j5Ww+SyVj2!wAiAhD3Y5}l!KI<{0)wjI67z#{szg##npY!@+bKhe79-m z)qC^VnR&h0NB9b_zwamTID}PWM{NCUqm9GCB7=&io#}waIgy5DP|4Ia4NPa0cSVN8 z*p)yQS|W8+-7eE~DldCg-AeoYY&LS{PC;a%S5f*8RME(^LOq5jkM?LyoHOW2dyv*R gaeb!gvPjd^H&snEq!$SlRkC#6-aYcSN$fwpKU?ElMF0Q* delta 286 zcmbO)HdQS0o)F7a1|SdyVi_Rb0>rXF?868ofZza-<^a+Mfpi*>J_V$+fV3eK1A{1# zo&%&gf%GOItq7#|0BJQKeQ#o}IOh^(28J9U=gGv0=B^zq3=A)Tx+ei?DWG6A8v{c- zke&vl`+>9^I|G9WkX{F*L9TfWq_u$bcOdNoq?LfqxI9^rQP{ExXyJ6A$Oj-T0;D^* z7#Jjh^jsjV3Z%CKX#pU87f1sU!#g0s1Eha$u4i1qBJJrH;_B`iWUWw;Q(BamW9u3b Y5ab#h?CI}kJ(-`ajFDk;E88p<0IiiSmjD0& diff --git a/dbtemplates/locale/ru/LC_MESSAGES/django.po b/dbtemplates/locale/ru/LC_MESSAGES/django.po index 37479a7..58fb967 100644 --- a/dbtemplates/locale/ru/LC_MESSAGES/django.po +++ b/dbtemplates/locale/ru/LC_MESSAGES/django.po @@ -16,7 +16,7 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" +#"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" "%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"