From fcca3742e0af15b78eb0db72a46575cf739c5f46 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sun, 8 Jan 2012 23:59:34 +0100 Subject: [PATCH 01/45] Minor cleanup in docs. --- docs/settings.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/settings.txt b/docs/settings.txt index 3494c14..c541d2c 100644 --- a/docs/settings.txt +++ b/docs/settings.txt @@ -4,8 +4,8 @@ Settings ``DBTEMPLATES_ADD_DEFAULT_SITE`` -------------------------------- -``dbtemplates`` adds the current site (``settings.SITE_ID``) to the database -template when it is created by default. You can disable this feature by +``dbtemplates`` adds the current site (``settings.SITE_ID``) to the database +template when it is created by default. You can disable this feature by setting ``DBTEMPLATES_ADD_DEFAULT_SITE`` to ``False``. ``DBTEMPLATES_AUTO_POPULATE_CONTENT`` From 65684c1243282b80debcb87ab6a7f71de08854ba Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sun, 8 Jan 2012 23:59:52 +0100 Subject: [PATCH 02/45] Use latest versiontools. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index be12e1f..34f9e8d 100644 --- a/setup.py +++ b/setup.py @@ -35,5 +35,5 @@ setup( 'Framework :: Django', ], install_requires=['django-appconf >= 0.4'], - setup_requires=['versiontools >= 1.5'], + setup_requires=['versiontools >= 1.8.2'], ) From 9cc07437ee9f06f2d663c916d2aa21af3881c418 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 9 Jan 2012 00:00:10 +0100 Subject: [PATCH 03/45] Updated year. --- LICENSE | 2 +- docs/conf.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index 0d17aff..00c83fd 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2007-2011, Jannis Leidel and contributors +Copyright (c) 2007-2012, Jannis Leidel and contributors All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/docs/conf.py b/docs/conf.py index 98092ec..3c8990a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -38,7 +38,7 @@ master_doc = 'index' # General information about the project. project = u'django-dbtemplates' -copyright = u'2007-2011, Jannis Leidel and contributors' +copyright = u'2007-2012, Jannis Leidel and contributors' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the From 4ae9392e087b984a90471183a46680ad5989d084 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 9 Jan 2012 00:01:17 +0100 Subject: [PATCH 04/45] Use django-jenkins for tests and prepare it for ci.enn.io. --- dbtemplates/test_settings.py | 8 ++++++ dbtemplates/tests.py | 26 +++++++++++++----- tox.ini | 53 ++++++++++++++++++++++-------------- 3 files changed, 60 insertions(+), 27 deletions(-) diff --git a/dbtemplates/test_settings.py b/dbtemplates/test_settings.py index 4b46789..8fbdf1d 100644 --- a/dbtemplates/test_settings.py +++ b/dbtemplates/test_settings.py @@ -9,6 +9,7 @@ INSTALLED_APPS = [ 'django.contrib.sites', 'django.contrib.admin', 'dbtemplates', + 'django_jenkins', ] TEMPLATE_LOADERS = ( @@ -16,3 +17,10 @@ TEMPLATE_LOADERS = ( 'django.template.loaders.app_directories.Loader', 'dbtemplates.loader.Loader', ) + +JENKINS_TASKS = ( + 'django_jenkins.tasks.run_pyflakes', + 'django_jenkins.tasks.run_pep8', + 'django_jenkins.tasks.with_coverage', + 'django_jenkins.tasks.django_tests', +) diff --git a/dbtemplates/tests.py b/dbtemplates/tests.py index 2e52587..2d2eb6b 100644 --- a/dbtemplates/tests.py +++ b/dbtemplates/tests.py @@ -19,8 +19,14 @@ from dbtemplates.utils.template import (get_template_source, from dbtemplates.management.commands.sync_templates import (FILES_TO_DATABASE, DATABASE_TO_FILES) + class DbTemplatesTestCase(TestCase): def setUp(self): + self.old_template_loaders = settings.TEMPLATE_LOADERS + if 'dbtemplates.loader.Loader' not in settings.TEMPLATE_LOADERS: + settings.TEMPLATE_LOADERS = (list(settings.TEMPLATE_LOADERS) + + ['dbtemplates.loader.Loader']) + self.site1, created1 = Site.objects.get_or_create( domain="example.com", name="example.com") self.site2, created2 = Site.objects.get_or_create( @@ -31,6 +37,9 @@ class DbTemplatesTestCase(TestCase): name='sub.html', content='sub') self.t2.sites.add(self.site2) + def tearDown(self): + settings.TEMPLATE_LOADERS = self.old_template_loaders + def test_basiscs(self): self.assertEqual(list(self.t1.sites.all()), [self.site1]) self.assertTrue("base" in self.t1.content) @@ -68,28 +77,31 @@ class DbTemplatesTestCase(TestCase): def test_sync_templates(self): old_template_dirs = settings.TEMPLATE_DIRS temp_template_dir = tempfile.mkdtemp('dbtemplates') - last_path_part = temp_template_dir.split('/')[-1] temp_template_path = os.path.join(temp_template_dir, 'temp_test.html') temp_template = codecs.open(temp_template_path, 'w') try: temp_template.write('temp test') settings.TEMPLATE_DIRS = (temp_template_dir,) - self.assertFalse(Template.objects.filter(name='temp_test.html').exists()) + self.assertFalse( + Template.objects.filter(name='temp_test.html').exists()) call_command('sync_templates', force=True, verbosity=0, overwrite=FILES_TO_DATABASE) - self.assertTrue(Template.objects.filter(name='temp_test.html').exists()) + self.assertTrue( + Template.objects.filter(name='temp_test.html').exists()) t = Template.objects.get(name='temp_test.html') t.content = 'temp test modified' t.save() call_command('sync_templates', force=True, verbosity=0, overwrite=DATABASE_TO_FILES) - self.assertTrue('modified' in codecs.open(temp_template_path).read()) + self.assertTrue( + 'modified' in codecs.open(temp_template_path).read()) - call_command('sync_templates', - force=True, verbosity=0, delete=True, overwrite=DATABASE_TO_FILES) + call_command('sync_templates', force=True, verbosity=0, + delete=True, overwrite=DATABASE_TO_FILES) self.assertTrue(os.path.exists(temp_template_path)) - self.assertFalse(Template.objects.filter(name='temp_test.html').exists()) + self.assertFalse( + Template.objects.filter(name='temp_test.html').exists()) finally: temp_template.close() settings.TEMPLATE_DIRS = old_template_dirs diff --git a/tox.ini b/tox.ini index 66f3dc6..570b4f1 100644 --- a/tox.ini +++ b/tox.ini @@ -1,51 +1,64 @@ -[tox] -distribute = false -envlist = - py25-1.2.X, py26-1.2.X, py27-1.2.X, - py25-1.3.X, py26-1.3.X, py27-1.3.X - [testenv] downloadcache = {toxworkdir}/_download/ +setenv = + DJANGO_SETTINGS_MODULE = dbtemplates.test_settings commands = - {envbindir}/coverage erase - {envbindir}/coverage run --branch --source=dbtemplates {envbindir}/django-admin.py test {posargs:dbtemplates} --settings=dbtemplates.test_settings - {envbindir}/coverage report --omit=*test* - {envbindir}/coverage html --omit=*test* -d {envtmpdir} - echo "Type the following to open the coverage report: python -m webbrowser -t file://{envtmpdir}/index.html" + {envbindir}/python {envbindir}/django-admin.py jenkins {posargs:dbtemplates} + +[testenv:docs] +basepython = python2.7 +deps = + Sphinx==1.0.7 + Django==1.3.1 +commands = + rm -rf docs/_build + {envbindir}/sphinx-build -b html -d docs/_build/doctrees docs docs/_build/html [testenv:py25-1.2.X] basepython = python2.5 deps = - coverage django==1.2.5 + pep8 + pyflakes + django-jenkins [testenv:py26-1.2.X] basepython = python2.6 deps = - coverage django==1.2.5 + pep8 + pyflakes + django-jenkins [testenv:py27-1.2.X] basepython = python2.7 deps = - coverage django==1.2.5 + pep8 + pyflakes + django-jenkins -[testenv:py25-1.3.X] +[testenv:py25] basepython = python2.5 deps = - coverage django==1.3 + pep8 + pyflakes + django-jenkins -[testenv:py26-1.3.X] +[testenv:py26] basepython = python2.6 deps = - coverage django==1.3 + pep8 + pyflakes + django-jenkins -[testenv:py27-1.3.X] +[testenv:py27] basepython = python2.7 deps = - coverage django==1.3 + pep8 + pyflakes + django-jenkins From 1c1046852993ab2e2a7105c3157dba94c56bd5cb Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 9 Jan 2012 00:01:31 +0100 Subject: [PATCH 05/45] Fixed ignore files. --- .gitignore | 2 +- .hgignore | 9 --------- 2 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 .hgignore diff --git a/.gitignore b/.gitignore index cb3f83e..993468d 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,4 @@ docs/_build *.egg/ pep8.txt coverage.xml -.coverage \ No newline at end of file +reports/ \ No newline at end of file diff --git a/.hgignore b/.hgignore deleted file mode 100644 index 508637e..0000000 --- a/.hgignore +++ /dev/null @@ -1,9 +0,0 @@ -syntax: glob -*.pyc -.*.swp -MANIFEST -build -dist -django_dbtemplates.egg-info/ -example/example.db -docs/_build \ No newline at end of file From 5a6053fef05f60e39a64f6fc61c8be74a2b98872 Mon Sep 17 00:00:00 2001 From: bmihelac Date: Mon, 9 Jan 2012 12:37:26 +0100 Subject: [PATCH 06/45] Fix typo in docs. --- docs/overview.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/overview.txt b/docs/overview.txt index c1229f4..a6fde1d 100644 --- a/docs/overview.txt +++ b/docs/overview.txt @@ -2,7 +2,7 @@ Setup ===== 1. Get the source from the `Git repository`_ or install it from the - Python Package Index by running ``pip django-dbtemplates``. + Python Package Index by running ``pip install django-dbtemplates``. 2. Follow the instructions in the INSTALL file 3. Edit the settings.py of your Django site: From cb3fe58a6e80a2be926c5aedce26bb4585600c53 Mon Sep 17 00:00:00 2001 From: bmihelac Date: Mon, 9 Jan 2012 12:56:09 +0100 Subject: [PATCH 07/45] Fix typo in docs - ``dbtemplates.loader.Loader`` should be first in ``TEMPLATE_LOADERS``. --- docs/overview.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/overview.txt b/docs/overview.txt index a6fde1d..2d1f623 100644 --- a/docs/overview.txt +++ b/docs/overview.txt @@ -30,9 +30,9 @@ Setup It should look something like this:: TEMPLATE_LOADERS = ( + 'dbtemplates.loader.Loader', 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', - 'dbtemplates.loader.Loader', ) 4. Sync your database ``python manage.py syncdb`` From 3e18bc9784cd5e1a5a9defc41225f682a2f0cf79 Mon Sep 17 00:00:00 2001 From: bmihelac Date: Mon, 9 Jan 2012 13:12:19 +0100 Subject: [PATCH 08/45] Update docs/overview.txt --- docs/overview.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/overview.txt b/docs/overview.txt index 2d1f623..8d67121 100644 --- a/docs/overview.txt +++ b/docs/overview.txt @@ -30,11 +30,16 @@ Setup It should look something like this:: TEMPLATE_LOADERS = ( - 'dbtemplates.loader.Loader', '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 + 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. + 4. Sync your database ``python manage.py syncdb`` 5. Restart your Django server From 02aaad635a6e86e4301c78a88c8535f520cecd5b Mon Sep 17 00:00:00 2001 From: Mark Stahler Date: Tue, 17 Jan 2012 21:22:22 -0500 Subject: [PATCH 09/45] Added TinyMCE support via django-tinymce --- dbtemplates/admin.py | 9 +++++++++ dbtemplates/conf.py | 7 +++++++ dbtemplates/urls.py | 4 ++++ 3 files changed, 20 insertions(+) create mode 100644 dbtemplates/urls.py diff --git a/dbtemplates/admin.py b/dbtemplates/admin.py index efdfbcb..3089747 100644 --- a/dbtemplates/admin.py +++ b/dbtemplates/admin.py @@ -1,6 +1,7 @@ import posixpath from django import forms from django.contrib import admin +from django.core.exceptions import ImproperlyConfigured from django.utils.translation import ungettext, ugettext_lazy as _ from django.utils.safestring import mark_safe @@ -59,6 +60,14 @@ if settings.DBTEMPLATES_AUTO_POPULATE_CONTENT: else: content_help_text = "" +if settings.DBTEMPLATES_USE_CODEMIRROR and settings.DBTEMPLATES_USE_TINYMCE: + raise ImproperlyConfigured("You may use either CodeMirror or TinyMCE with dbtemplates, not both. Please disable one of them.") + +if settings.DBTEMPLATES_USE_TINYMCE: + TemplateContentTextArea = TinyMce +else: + TemplateContentTextArea = forms.Textarea + class TemplateAdminForm(forms.ModelForm): """ diff --git a/dbtemplates/conf.py b/dbtemplates/conf.py index e1075a2..0bcf4ec 100644 --- a/dbtemplates/conf.py +++ b/dbtemplates/conf.py @@ -9,6 +9,7 @@ from appconf import AppConf class DbTemplatesConf(AppConf): USE_CODEMIRROR = False USE_REVERSION = False + USE_TINYMCE = False ADD_DEFAULT_SITE = True AUTO_POPULATE_CONTENT = True MEDIA_PREFIX = None @@ -40,3 +41,9 @@ class DbTemplatesConf(AppConf): raise ImproperlyConfigured("Please add 'reversion' to your " "INSTALLED_APPS setting to make use of it in dbtemplates.") return value + + def configure_use_tinymce(self, value): + if value and 'tinymce' not in settings.INSTALLED_APPS: + raise ImproperlyConfigured("Please add 'tinymce' to your " + "INSTALLED_APPS setting to make use of it in dbtemplates.") + return value diff --git a/dbtemplates/urls.py b/dbtemplates/urls.py new file mode 100644 index 0000000..62d9494 --- /dev/null +++ b/dbtemplates/urls.py @@ -0,0 +1,4 @@ +from django.conf.urls.defaults import * + +if 'tinymce' in settings.INSTALLED_APPS: + urlpatterns += patterns('', url(r'^tinymce/', include('tinymce.urls'))) From e866e52074f0dee8ab92dd4f3e4beafffb648c11 Mon Sep 17 00:00:00 2001 From: Mark Stahler Date: Tue, 17 Jan 2012 21:58:47 -0500 Subject: [PATCH 10/45] fixed tinyMce not appearing in admin area --- dbtemplates/admin.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dbtemplates/admin.py b/dbtemplates/admin.py index 3089747..67ac90b 100644 --- a/dbtemplates/admin.py +++ b/dbtemplates/admin.py @@ -63,8 +63,9 @@ else: if settings.DBTEMPLATES_USE_CODEMIRROR and settings.DBTEMPLATES_USE_TINYMCE: raise ImproperlyConfigured("You may use either CodeMirror or TinyMCE with dbtemplates, not both. Please disable one of them.") -if settings.DBTEMPLATES_USE_TINYMCE: - TemplateContentTextArea = TinyMce +if settings.DBTEMPLATES_USE_TINYMCE and'tinymce' in settings.INSTALLED_APPS: + from tinymce.widgets import AdminTinyMCE + TemplateContentTextArea = AdminTinyMCE else: TemplateContentTextArea = forms.Textarea From edaf6ea2585b1936a870d7c7aed3a06a063f2115 Mon Sep 17 00:00:00 2001 From: Mark Stahler Date: Tue, 17 Jan 2012 22:11:08 -0500 Subject: [PATCH 11/45] respect column widths --- dbtemplates/admin.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dbtemplates/admin.py b/dbtemplates/admin.py index 67ac90b..3f966fc 100644 --- a/dbtemplates/admin.py +++ b/dbtemplates/admin.py @@ -61,9 +61,10 @@ else: content_help_text = "" if settings.DBTEMPLATES_USE_CODEMIRROR and settings.DBTEMPLATES_USE_TINYMCE: - raise ImproperlyConfigured("You may use either CodeMirror or TinyMCE with dbtemplates, not both. Please disable one of them.") + raise ImproperlyConfigured("You may use either CodeMirror or TinyMCE " + "with dbtemplates, not both. Please disable one of them.") -if settings.DBTEMPLATES_USE_TINYMCE and'tinymce' in settings.INSTALLED_APPS: +if settings.DBTEMPLATES_USE_TINYMCE: from tinymce.widgets import AdminTinyMCE TemplateContentTextArea = AdminTinyMCE else: From 68d4342df403eeb23509bca4d2eef4d0d8e1d574 Mon Sep 17 00:00:00 2001 From: Mark Stahler Date: Wed, 18 Jan 2012 08:33:13 -0500 Subject: [PATCH 12/45] removed urls.py which is not required if django-tinymce is installed properly. fixed new bug relating to codemirror introduced by tinymce --- dbtemplates/admin.py | 2 -- dbtemplates/urls.py | 4 ---- 2 files changed, 6 deletions(-) delete mode 100644 dbtemplates/urls.py diff --git a/dbtemplates/admin.py b/dbtemplates/admin.py index 3f966fc..7e4dae8 100644 --- a/dbtemplates/admin.py +++ b/dbtemplates/admin.py @@ -67,8 +67,6 @@ if settings.DBTEMPLATES_USE_CODEMIRROR and settings.DBTEMPLATES_USE_TINYMCE: if settings.DBTEMPLATES_USE_TINYMCE: from tinymce.widgets import AdminTinyMCE TemplateContentTextArea = AdminTinyMCE -else: - TemplateContentTextArea = forms.Textarea class TemplateAdminForm(forms.ModelForm): diff --git a/dbtemplates/urls.py b/dbtemplates/urls.py deleted file mode 100644 index 62d9494..0000000 --- a/dbtemplates/urls.py +++ /dev/null @@ -1,4 +0,0 @@ -from django.conf.urls.defaults import * - -if 'tinymce' in settings.INSTALLED_APPS: - urlpatterns += patterns('', url(r'^tinymce/', include('tinymce.urls'))) From ad7b258308e2fe977a05fd03f772503e0fede137 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Fri, 24 Feb 2012 23:35:51 +0100 Subject: [PATCH 13/45] Force an encoding when writing the content to the file. --- dbtemplates/management/commands/sync_templates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbtemplates/management/commands/sync_templates.py b/dbtemplates/management/commands/sync_templates.py index ca73d7f..8c1be09 100644 --- a/dbtemplates/management/commands/sync_templates.py +++ b/dbtemplates/management/commands/sync_templates.py @@ -101,8 +101,8 @@ class Command(NoArgsCommand): raise CommandError( u"Couldn't delete %s" % path) elif confirm == DATABASE_TO_FILES: + f = codecs.open(path, 'w', 'utf-8') try: - f = codecs.open(path, 'w') f.write(t.content) finally: f.close() From 0cfd927938c36bab4276a2f1cfff057ce333fa7f Mon Sep 17 00:00:00 2001 From: Jure Cuhalev Date: Sat, 25 Feb 2012 22:47:05 +0100 Subject: [PATCH 14/45] fix for tests when dbtemplates template loader is not in main settings.py --- dbtemplates/tests.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dbtemplates/tests.py b/dbtemplates/tests.py index 2d2eb6b..9f68021 100644 --- a/dbtemplates/tests.py +++ b/dbtemplates/tests.py @@ -24,6 +24,7 @@ class DbTemplatesTestCase(TestCase): def setUp(self): self.old_template_loaders = settings.TEMPLATE_LOADERS if 'dbtemplates.loader.Loader' not in settings.TEMPLATE_LOADERS: + loader.template_source_loaders = None settings.TEMPLATE_LOADERS = (list(settings.TEMPLATE_LOADERS) + ['dbtemplates.loader.Loader']) @@ -38,6 +39,7 @@ class DbTemplatesTestCase(TestCase): self.t2.sites.add(self.site2) def tearDown(self): + loader.template_source_loaders = None settings.TEMPLATE_LOADERS = self.old_template_loaders def test_basiscs(self): From f503013b0f4c14bd7b5b8f95b6c0a167b62da1bf Mon Sep 17 00:00:00 2001 From: Bojan Mihelac Date: Fri, 30 Mar 2012 15:11:57 +0200 Subject: [PATCH 15/45] Add failing tests for #27. Raises MultipleObjectsReturned with sites --- dbtemplates/tests.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/dbtemplates/tests.py b/dbtemplates/tests.py index 9f68021..f5741d7 100644 --- a/dbtemplates/tests.py +++ b/dbtemplates/tests.py @@ -4,9 +4,10 @@ import os import shutil import tempfile +from django.conf import settings as django_settings from django.core.cache.backends.base import BaseCache from django.core.management import call_command -from django.template import loader, Context +from django.template import loader, Context, TemplateDoesNotExist from django.test import TestCase from django.contrib.sites.models import Site @@ -59,6 +60,28 @@ class DbTemplatesTestCase(TestCase): finally: settings.DBTEMPLATES_ADD_DEFAULT_SITE = old_add_default_site + def test_load_templates_sites(self): + old_add_default_site = settings.DBTEMPLATES_ADD_DEFAULT_SITE + old_site_id = django_settings.SITE_ID + try: + settings.DBTEMPLATES_ADD_DEFAULT_SITE = False + t_site1 = Template.objects.create( + name='copyright.html', content='(c) example.com') + t_site1.sites.add(self.site1) + t_site2 = Template.objects.create( + name='copyright.html', content='(c) example.org') + t_site2.sites.add(self.site2) + + django_settings.SITE_ID = Site.objects.create( + domain="example.net", name="example.net").id + Site.objects.clear_cache() + + with self.assertRaises(TemplateDoesNotExist): + loader.get_template("copyright.html") + finally: + django_settings.SITE_ID = old_site_id + settings.DBTEMPLATES_ADD_DEFAULT_SITE = old_add_default_site + def test_load_templates(self): result = loader.get_template("base.html").render(Context({})) self.assertEqual(result, 'base') From 29f08281d7b1e67b3696c40d64e988f9f54906ad Mon Sep 17 00:00:00 2001 From: Bojan Mihelac Date: Fri, 30 Mar 2012 15:14:21 +0200 Subject: [PATCH 16/45] Fix #27. dbtemplates tries to find template from database which is associated with current site, and if that fails then template from database which is not associated with any site. --- dbtemplates/loader.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dbtemplates/loader.py b/dbtemplates/loader.py index 24e5010..a2c744d 100644 --- a/dbtemplates/loader.py +++ b/dbtemplates/loader.py @@ -62,7 +62,8 @@ class Loader(BaseLoader): return set_and_return(cache_key, template.content, display_name) except (Template.MultipleObjectsReturned, Template.DoesNotExist): try: - template = Template.objects.get(name__exact=template_name) + template = Template.objects.get(name__exact=template_name, + sites__in=[]) return set_and_return(cache_key, template.content, display_name) except Template.DoesNotExist: pass From 3aa313225572465f5a837d1632063e99c2d4f3f0 Mon Sep 17 00:00:00 2001 From: Bojan Mihelac Date: Fri, 30 Mar 2012 15:25:45 +0200 Subject: [PATCH 17/45] Fix for #28 --- dbtemplates/test_settings.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dbtemplates/test_settings.py b/dbtemplates/test_settings.py index 8fbdf1d..55c5e87 100644 --- a/dbtemplates/test_settings.py +++ b/dbtemplates/test_settings.py @@ -1,9 +1,12 @@ DBTEMPLATES_CACHE_BACKEND = 'dummy://' DATABASE_ENGINE = 'sqlite3' +# SQLite does not support removing unique constraints (see #28) +SOUTH_TESTS_MIGRATE = False SITE_ID = 1 + INSTALLED_APPS = [ 'django.contrib.contenttypes', 'django.contrib.sites', From bb4e7ce36fd2f32105cc957c884447a67ddfc73a Mon Sep 17 00:00:00 2001 From: Selwin Ong Date: Sun, 6 May 2012 20:52:17 +0700 Subject: [PATCH 18/45] Fixed an issue where ``get_cache_key`` may produce invalid memcached keys. --- dbtemplates/tests.py | 6 +++++- dbtemplates/utils/cache.py | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/dbtemplates/tests.py b/dbtemplates/tests.py index f5741d7..fc44a84 100644 --- a/dbtemplates/tests.py +++ b/dbtemplates/tests.py @@ -14,7 +14,7 @@ from django.contrib.sites.models import Site from dbtemplates.conf import settings from dbtemplates.models import Template -from dbtemplates.utils.cache import get_cache_backend +from dbtemplates.utils.cache import get_cache_backend, get_cache_key from dbtemplates.utils.template import (get_template_source, check_template_syntax) from dbtemplates.management.commands.sync_templates import (FILES_TO_DATABASE, @@ -142,3 +142,7 @@ class DbTemplatesTestCase(TestCase): name='good.html', content='{% if foo %}Bar{% endif %}') self.assertFalse(check_template_syntax(bad_template)[0]) self.assertTrue(check_template_syntax(good_template)[0]) + + def test_get_cache_name(self): + name = 'name with spaces' + self.assertEqual(get_cache_key(name), 'dbtemplates::name-with-spaces::1') \ No newline at end of file diff --git a/dbtemplates/utils/cache.py b/dbtemplates/utils/cache.py index 299647c..13a48d7 100644 --- a/dbtemplates/utils/cache.py +++ b/dbtemplates/utils/cache.py @@ -1,6 +1,7 @@ from django.core.cache import get_cache from django.contrib.sites.models import Site +from django.template.defaultfilters import slugify from dbtemplates.conf import settings @@ -13,7 +14,7 @@ cache = get_cache_backend() def get_cache_key(name): current_site = Site.objects.get_current() - return 'dbtemplates::%s::%s' % (name, current_site.pk) + return 'dbtemplates::%s::%s' % (slugify(name), current_site.pk) def get_cache_notfound_key(name): From 45700c7e1ceb764de80435b0981a8bf4f484a135 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 08:35:36 +0200 Subject: [PATCH 19/45] Moved CI to Travis. --- .travis.yml | 16 ++++++++++ README.rst | 2 ++ requirements/default.txt | 3 ++ tox.ini | 64 ---------------------------------------- 4 files changed, 21 insertions(+), 64 deletions(-) create mode 100644 .travis.yml create mode 100644 requirements/default.txt delete mode 100644 tox.ini diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..cb99b0f --- /dev/null +++ b/.travis.yml @@ -0,0 +1,16 @@ +language: python +python: +# - "2.5" + - "2.6" + - "2.7" +install: + - pip install -q -r requirements/default.txt Django==$DJANGO --use-mirrors +script: + - django-admin.py jenkins +branches: + only: + - develop +env: + - DJANGO=1.2.7 + - DJANGO=1.3.1 + - DJANGO=1.4 diff --git a/README.rst b/README.rst index 3dd74ec..806c678 100644 --- a/README.rst +++ b/README.rst @@ -1,6 +1,8 @@ django-dbtemplates ================== +.. image:: https://secure.travis-ci.org/jezdez/django-dbtemplates.png?branch=develop + ``dbtemplates`` is a Django app that consists of two parts: 1. It allows you to store templates in your database diff --git a/requirements/default.txt b/requirements/default.txt new file mode 100644 index 0000000..bb4b708 --- /dev/null +++ b/requirements/default.txt @@ -0,0 +1,3 @@ +pep8 +pyflakes +django-jenkins diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 570b4f1..0000000 --- a/tox.ini +++ /dev/null @@ -1,64 +0,0 @@ -[testenv] -downloadcache = {toxworkdir}/_download/ -setenv = - DJANGO_SETTINGS_MODULE = dbtemplates.test_settings -commands = - {envbindir}/python {envbindir}/django-admin.py jenkins {posargs:dbtemplates} - -[testenv:docs] -basepython = python2.7 -deps = - Sphinx==1.0.7 - Django==1.3.1 -commands = - rm -rf docs/_build - {envbindir}/sphinx-build -b html -d docs/_build/doctrees docs docs/_build/html - -[testenv:py25-1.2.X] -basepython = python2.5 -deps = - django==1.2.5 - pep8 - pyflakes - django-jenkins - -[testenv:py26-1.2.X] -basepython = python2.6 -deps = - django==1.2.5 - pep8 - pyflakes - django-jenkins - -[testenv:py27-1.2.X] -basepython = python2.7 -deps = - django==1.2.5 - pep8 - pyflakes - django-jenkins - - -[testenv:py25] -basepython = python2.5 -deps = - django==1.3 - pep8 - pyflakes - django-jenkins - -[testenv:py26] -basepython = python2.6 -deps = - django==1.3 - pep8 - pyflakes - django-jenkins - -[testenv:py27] -basepython = python2.7 -deps = - django==1.3 - pep8 - pyflakes - django-jenkins From 3c67628a63411ae7acf6966a9c2a3263dc44909e Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 08:36:01 +0200 Subject: [PATCH 20/45] Removed dependency on versiontools. --- dbtemplates/__init__.py | 4 ++-- setup.py | 24 ++++++++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/dbtemplates/__init__.py b/dbtemplates/__init__.py index e16f115..66b4ea1 100644 --- a/dbtemplates/__init__.py +++ b/dbtemplates/__init__.py @@ -1,2 +1,2 @@ -# following PEP 386, versiontools will pick it up -__version__ = (1, 2, 1, "final", 0) +# following PEP 386 +__version__ = "1.2a1" diff --git a/setup.py b/setup.py index 34f9e8d..778878f 100644 --- a/setup.py +++ b/setup.py @@ -1,20 +1,33 @@ +import os +import re import codecs -from os import path from setuptools import setup, find_packages -read = lambda filepath: codecs.open(filepath, 'r', 'utf-8').read() + +def read(*parts): + return codecs.open(os.path.join(os.path.dirname(__file__), *parts)).read() + + +def find_version(*file_paths): + version_file = read(*file_paths) + version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", + version_file, re.M) + if version_match: + return version_match.group(1) + raise RuntimeError("Unable to find version string.") + setup( name='django-dbtemplates', - version=':versiontools:dbtemplates:', + version=find_version('dbtemplates', '__init__.py'), description='Template loader for templates stored in the database', - long_description=read(path.join(path.dirname(__file__), 'README.rst')), + long_description=read('README.rst'), author='Jannis Leidel', author_email='jannis@leidel.info', url='http://django-dbtemplates.readthedocs.org/', packages=find_packages(exclude=['example']), zip_safe=False, - package_data = { + package_data={ 'dbtemplates': [ 'locale/*/LC_MESSAGES/*', 'static/dbtemplates/css/*.css', @@ -35,5 +48,4 @@ setup( 'Framework :: Django', ], install_requires=['django-appconf >= 0.4'], - setup_requires=['versiontools >= 1.8.2'], ) From 20a5d9fc662d69e81d232aba57195291e05c7f9a Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 08:41:02 +0200 Subject: [PATCH 21/45] Forgot to set the DJANGO_SETTINGS_MODULE var. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index cb99b0f..2d27f97 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ python: install: - pip install -q -r requirements/default.txt Django==$DJANGO --use-mirrors script: - - django-admin.py jenkins + - DJANGO_SETTINGS_MODULE=dbtemplates.test_settings django-admin.py jenkins branches: only: - develop From 0ff18227f98c9b4f5deba4f0e9d50bfad788f7b8 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 08:43:48 +0200 Subject: [PATCH 22/45] Hrm, setting the variable in the env block? --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2d27f97..ac95dec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,11 +6,11 @@ python: install: - pip install -q -r requirements/default.txt Django==$DJANGO --use-mirrors script: - - DJANGO_SETTINGS_MODULE=dbtemplates.test_settings django-admin.py jenkins + - django-admin.py jenkins branches: only: - develop env: - - DJANGO=1.2.7 - - DJANGO=1.3.1 - - DJANGO=1.4 + - DJANGO_SETTINGS_MODULE=dbtemplates.test_settings DJANGO=1.2.7 + - DJANGO_SETTINGS_MODULE=dbtemplates.test_settings DJANGO=1.3.1 + - DJANGO_SETTINGS_MODULE=dbtemplates.test_settings DJANGO=1.4 From 87c5c469995fe85fbd8b2945ef96badb8ba10eb9 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 08:55:27 +0200 Subject: [PATCH 23/45] Further fiddling with the travis config. --- .travis.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index ac95dec..dde2d32 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,13 +4,17 @@ python: - "2.6" - "2.7" install: - - pip install -q -r requirements/default.txt Django==$DJANGO --use-mirrors + - pip install . + - pip install -r requirements/default.txt Django==$DJANGO +before_script: + - export PIP_USE_MIRRORS=true + - export DJANGO_SETTINGS_MODULE=dbtemplates.test_settings script: - django-admin.py jenkins +env: + - DJANGO=1.2.7 + - DJANGO=1.3.1 + - DJANGO=1.4 branches: only: - develop -env: - - DJANGO_SETTINGS_MODULE=dbtemplates.test_settings DJANGO=1.2.7 - - DJANGO_SETTINGS_MODULE=dbtemplates.test_settings DJANGO=1.3.1 - - DJANGO_SETTINGS_MODULE=dbtemplates.test_settings DJANGO=1.4 From abc2fe5cd28a9a7467e60550509a24e05e1c0bc9 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 08:57:45 +0200 Subject: [PATCH 24/45] Added a few more test requirements. --- requirements/default.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/requirements/default.txt b/requirements/default.txt index bb4b708..1a70548 100644 --- a/requirements/default.txt +++ b/requirements/default.txt @@ -1,3 +1,5 @@ pep8 pyflakes django-jenkins +coverage +pylint \ No newline at end of file From bea453548febc09b9b6435d697c09159b1018793 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 08:58:36 +0200 Subject: [PATCH 25/45] Renamed test requirements file to correct name. --- .travis.yml | 2 +- requirements/{default.txt => tests.txt} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename requirements/{default.txt => tests.txt} (100%) diff --git a/.travis.yml b/.travis.yml index dde2d32..13cddb0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ python: - "2.7" install: - pip install . - - pip install -r requirements/default.txt Django==$DJANGO + - pip install -r requirements/tests.txt Django==$DJANGO before_script: - export PIP_USE_MIRRORS=true - export DJANGO_SETTINGS_MODULE=dbtemplates.test_settings diff --git a/requirements/default.txt b/requirements/tests.txt similarity index 100% rename from requirements/default.txt rename to requirements/tests.txt From 222c7947d2f086df8c21167ae6c82729d64ff13a Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 09:04:05 +0200 Subject: [PATCH 26/45] Added auth app to list of installed apps during tests. --- dbtemplates/test_settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/dbtemplates/test_settings.py b/dbtemplates/test_settings.py index 55c5e87..9fb2096 100644 --- a/dbtemplates/test_settings.py +++ b/dbtemplates/test_settings.py @@ -11,6 +11,7 @@ INSTALLED_APPS = [ 'django.contrib.contenttypes', 'django.contrib.sites', 'django.contrib.admin', + 'django.contrib.auth', 'dbtemplates', 'django_jenkins', ] From d3ccb0c42a85f2541b311b826b6c100bb28979ca Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 09:04:31 +0200 Subject: [PATCH 27/45] Stop using a context manager when we don't need it really. --- dbtemplates/tests.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dbtemplates/tests.py b/dbtemplates/tests.py index f5741d7..05ac2db 100644 --- a/dbtemplates/tests.py +++ b/dbtemplates/tests.py @@ -1,4 +1,3 @@ -from __future__ import with_statement import codecs import os import shutil @@ -76,8 +75,8 @@ class DbTemplatesTestCase(TestCase): domain="example.net", name="example.net").id Site.objects.clear_cache() - with self.assertRaises(TemplateDoesNotExist): - loader.get_template("copyright.html") + self.assertRaises(TemplateDoesNotExist, + loader.get_template, "copyright.html") finally: django_settings.SITE_ID = old_site_id settings.DBTEMPLATES_ADD_DEFAULT_SITE = old_add_default_site From 20aebf894dc2fff4c89f2043fa41752fb642a5b8 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 09:48:01 +0200 Subject: [PATCH 28/45] Limit the tests to dbtemplates. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 13cddb0..30333f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ before_script: - export PIP_USE_MIRRORS=true - export DJANGO_SETTINGS_MODULE=dbtemplates.test_settings script: - - django-admin.py jenkins + - django-admin.py jenkins dbtemplates env: - DJANGO=1.2.7 - DJANGO=1.3.1 From f3fc408385491563e1d92003be5e088b1969707b Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 10:31:24 +0200 Subject: [PATCH 29/45] Get the database name from the routers and dropped support for 1.2.X. --- .travis.yml | 1 - dbtemplates/loader.py | 22 ++++++++++++---------- dbtemplates/test_settings.py | 1 + 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 30333f5..1803e05 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,6 @@ before_script: script: - django-admin.py jenkins dbtemplates env: - - DJANGO=1.2.7 - DJANGO=1.3.1 - DJANGO=1.4 branches: diff --git a/dbtemplates/loader.py b/dbtemplates/loader.py index a2c744d..a467305 100644 --- a/dbtemplates/loader.py +++ b/dbtemplates/loader.py @@ -1,7 +1,7 @@ from django.contrib.sites.models import Site +from django.db import router from django.template import TemplateDoesNotExist -from dbtemplates.conf import settings from dbtemplates.models import Template from dbtemplates.utils.cache import (cache, get_cache_key, set_and_return, get_cache_notfound_key) @@ -19,6 +19,12 @@ class Loader(BaseLoader): """ is_usable = True + def load_and_store_template(self, template_name, cache_key, site, **params): + template = Template.objects.get(name__exact=template_name, **params) + db = router.db_for_read(Template, instance=template) + display_name = 'dbtemplates:%s:%s:%s' % (db, template_name, site.domain) + return set_and_return(cache_key, template.content, display_name) + def load_template_source(self, template_name, template_dirs=None): # The logic should work like this: # * Try to find the template in the cache. If found, return it. @@ -33,8 +39,6 @@ class Loader(BaseLoader): # in the cache indicating that queries failed, with the current # timestamp. site = Site.objects.get_current() - display_name = 'dbtemplates:%s:%s:%s' % (settings.DATABASE_ENGINE, - template_name, site.domain) cache_key = get_cache_key(template_name) if cache: try: @@ -57,15 +61,13 @@ class Loader(BaseLoader): # Not marked as not-found, move on... try: - template = Template.objects.get(name__exact=template_name, - sites__in=[site.id]) - return set_and_return(cache_key, template.content, display_name) + return self.load_and_store_template(template_name, cache_key, + site, sites__in=[site.id]) except (Template.MultipleObjectsReturned, Template.DoesNotExist): try: - template = Template.objects.get(name__exact=template_name, - sites__in=[]) - return set_and_return(cache_key, template.content, display_name) - except Template.DoesNotExist: + return self.load_and_store_template(template_name, cache_key, + site, sites__in=[]) + except (Template.MultipleObjectsReturned, Template.DoesNotExist): pass # Mark as not-found in cache. diff --git a/dbtemplates/test_settings.py b/dbtemplates/test_settings.py index 9fb2096..587ebb2 100644 --- a/dbtemplates/test_settings.py +++ b/dbtemplates/test_settings.py @@ -6,6 +6,7 @@ SOUTH_TESTS_MIGRATE = False SITE_ID = 1 +SECRET_KEY = 'something-something' INSTALLED_APPS = [ 'django.contrib.contenttypes', From 0e43258b5b5a20e88a69dbc21019b9c1ac2e7259 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 10:35:23 +0200 Subject: [PATCH 30/45] Added DATABASES setting to please Django 1.4. --- dbtemplates/test_settings.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dbtemplates/test_settings.py b/dbtemplates/test_settings.py index 587ebb2..b382f07 100644 --- a/dbtemplates/test_settings.py +++ b/dbtemplates/test_settings.py @@ -8,6 +8,13 @@ SITE_ID = 1 SECRET_KEY = 'something-something' +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': ':memory:', + } +} + INSTALLED_APPS = [ 'django.contrib.contenttypes', 'django.contrib.sites', From f1e680aa3148ff127d5ba14279cd50135ddccd15 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 10:54:26 +0200 Subject: [PATCH 31/45] Added link to Travic build. --- README.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.rst b/README.rst index 806c678..e0e9977 100644 --- a/README.rst +++ b/README.rst @@ -2,6 +2,8 @@ django-dbtemplates ================== .. image:: https://secure.travis-ci.org/jezdez/django-dbtemplates.png?branch=develop + :alt: Build Status + :target: http://travis-ci.org/jezdez/django-dbtemplates ``dbtemplates`` is a Django app that consists of two parts: From 2f27327bebe7f2e7b33e5cfb0db517f53a1b9701 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 10:57:23 +0200 Subject: [PATCH 32/45] Handle timezone on 1.4 correctly. --- dbtemplates/models.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/dbtemplates/models.py b/dbtemplates/models.py index c8bb3d6..02e8081 100644 --- a/dbtemplates/models.py +++ b/dbtemplates/models.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -from datetime import datetime - from django.db import models from django.db.models import signals from django.template import TemplateDoesNotExist @@ -13,6 +11,12 @@ 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: + from datetime import datetime + now = datetime.now + class Template(models.Model): """ @@ -25,9 +29,9 @@ class Template(models.Model): sites = models.ManyToManyField(Site, verbose_name=_(u'sites'), blank=True, null=True) creation_date = models.DateTimeField(_('creation date'), - default=datetime.now) + default=now) last_changed = models.DateTimeField(_('last changed'), - default=datetime.now) + default=now) objects = models.Manager() on_site = CurrentSiteManager('sites') @@ -56,7 +60,7 @@ class Template(models.Model): pass def save(self, *args, **kwargs): - self.last_changed = datetime.now() + self.last_changed = now() # If content is empty look for a template with the given name and # populate the template instance with its content. if settings.DBTEMPLATES_AUTO_POPULATE_CONTENT and not self.content: From 2e430d53709feaa0e0ebd7f5074e4a5e8af09b83 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 10:57:36 +0200 Subject: [PATCH 33/45] Minor code cleanup of the migrations. --- dbtemplates/migrations/0001_initial.py | 6 ++---- .../migrations/0002_auto__del_unique_template_name.py | 7 +------ 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/dbtemplates/migrations/0001_initial.py b/dbtemplates/migrations/0001_initial.py index a5192af..0e08603 100644 --- a/dbtemplates/migrations/0001_initial.py +++ b/dbtemplates/migrations/0001_initial.py @@ -4,10 +4,11 @@ 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)), @@ -26,16 +27,13 @@ class Migration(SchemaMigration): )) 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'"}, diff --git a/dbtemplates/migrations/0002_auto__del_unique_template_name.py b/dbtemplates/migrations/0002_auto__del_unique_template_name.py index 17a8a6e..418a3ab 100644 --- a/dbtemplates/migrations/0002_auto__del_unique_template_name.py +++ b/dbtemplates/migrations/0002_auto__del_unique_template_name.py @@ -1,23 +1,18 @@ # 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): - # Removing unique constraint on 'Template', fields ['name'] db.delete_unique('django_template', ['name']) - def backwards(self, orm): - # Adding unique constraint on 'Template', fields ['name'] db.create_unique('django_template', ['name']) - models = { 'dbtemplates.template': { 'Meta': {'ordering': "('name',)", 'object_name': 'Template', 'db_table': "'django_template'"}, From 842e08cf2e89b66180892ce38b24fa72ffda39c2 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 14:06:54 +0200 Subject: [PATCH 34/45] Switched to using nose and django-nose for easy test running. --- .gitignore | 4 +--- .travis.yml | 3 ++- INSTALL | 17 ----------------- dbtemplates/admin.py | 2 +- .../commands/check_template_syntax.py | 1 + .../management/commands/sync_templates.py | 4 +++- dbtemplates/{tests.py => test_cases.py} | 4 ++-- dbtemplates/test_settings.py | 9 ++------- dbtemplates/utils/template.py | 8 +++----- requirements/tests.txt | 6 ++---- setup.cfg | 4 ++++ 11 files changed, 21 insertions(+), 41 deletions(-) delete mode 100644 INSTALL rename dbtemplates/{tests.py => test_cases.py} (98%) diff --git a/.gitignore b/.gitignore index 993468d..9d5809f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,4 @@ example/example.db docs/_build .tox/ *.egg/ -pep8.txt -coverage.xml -reports/ \ No newline at end of file +.coverage diff --git a/.travis.yml b/.travis.yml index 1803e05..6ffd9af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,8 +9,9 @@ install: before_script: - export PIP_USE_MIRRORS=true - export DJANGO_SETTINGS_MODULE=dbtemplates.test_settings + - flake8 script: - - django-admin.py jenkins dbtemplates + - django-admin.py test dbtemplates env: - DJANGO=1.3.1 - DJANGO=1.4 diff --git a/INSTALL b/INSTALL deleted file mode 100644 index 2e5bc7d..0000000 --- a/INSTALL +++ /dev/null @@ -1,17 +0,0 @@ -To install it, run the following command inside this directory: - - python setup.py install - -Or if you'd prefer you can simply place the included ``dbtemplates`` -directory somewhere on your Python path, or symlink to it from -somewhere on your Python path; this is useful if you're working from a -Subversion checkout. Since ``dbtemplates`` is registered in the -Python Package Index you can also run ``easy_install django-dbtemplates`` -or ``pip install django-dbtemplates`` optionally. - -Note that this application requires Python 2.3 or later, and a recent -Subversion checkout of Django. You can obtain Python from -http://www.python.org/ and Django from http://www.djangoproject.com/. - -This install notice was bluntly stolen from James Bennett's registration -package, http://www.bitbucket.org/ubernostrum/django-registration/ \ No newline at end of file diff --git a/dbtemplates/admin.py b/dbtemplates/admin.py index 7e4dae8..9505d26 100644 --- a/dbtemplates/admin.py +++ b/dbtemplates/admin.py @@ -15,7 +15,7 @@ from dbtemplates.utils.template import check_template_syntax if settings.DBTEMPLATES_USE_REVERSION: from reversion.admin import VersionAdmin as TemplateModelAdmin else: - from django.contrib.admin import ModelAdmin as TemplateModelAdmin + from django.contrib.admin import ModelAdmin as TemplateModelAdmin # noqa class CodeMirrorTextArea(forms.Textarea): diff --git a/dbtemplates/management/commands/check_template_syntax.py b/dbtemplates/management/commands/check_template_syntax.py index 16d4ca2..214f531 100644 --- a/dbtemplates/management/commands/check_template_syntax.py +++ b/dbtemplates/management/commands/check_template_syntax.py @@ -3,6 +3,7 @@ from django.core.management.base import CommandError, NoArgsCommand from dbtemplates.models import Template from dbtemplates.utils.template import check_template_syntax + class Command(NoArgsCommand): help = "Ensures templates stored in the database don't have syntax errors." diff --git a/dbtemplates/management/commands/sync_templates.py b/dbtemplates/management/commands/sync_templates.py index 8c1be09..cffa7db 100644 --- a/dbtemplates/management/commands/sync_templates.py +++ b/dbtemplates/management/commands/sync_templates.py @@ -11,6 +11,7 @@ from dbtemplates.models import Template ALWAYS_ASK, FILES_TO_DATABASE, DATABASE_TO_FILES = ('0', '1', '2') + class Command(NoArgsCommand): help = "Syncs file system templates with the database bidirectionally." option_list = NoArgsCommand.option_list + ( @@ -89,7 +90,8 @@ class Command(NoArgsCommand): path, t.__repr__())) else: confirm = overwrite - if confirm in ('', FILES_TO_DATABASE, DATABASE_TO_FILES): + if confirm in ('', FILES_TO_DATABASE, + DATABASE_TO_FILES): if confirm == FILES_TO_DATABASE: t.content = codecs.open(path, 'r').read() t.save() diff --git a/dbtemplates/tests.py b/dbtemplates/test_cases.py similarity index 98% rename from dbtemplates/tests.py rename to dbtemplates/test_cases.py index 7747291..42b2a31 100644 --- a/dbtemplates/tests.py +++ b/dbtemplates/test_cases.py @@ -143,5 +143,5 @@ class DbTemplatesTestCase(TestCase): self.assertTrue(check_template_syntax(good_template)[0]) def test_get_cache_name(self): - name = 'name with spaces' - self.assertEqual(get_cache_key(name), 'dbtemplates::name-with-spaces::1') + self.assertEqual(get_cache_key('name with spaces'), + 'dbtemplates::name-with-spaces::1') diff --git a/dbtemplates/test_settings.py b/dbtemplates/test_settings.py index b382f07..6ce4617 100644 --- a/dbtemplates/test_settings.py +++ b/dbtemplates/test_settings.py @@ -21,7 +21,7 @@ INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'dbtemplates', - 'django_jenkins', + 'django_nose', ] TEMPLATE_LOADERS = ( @@ -30,9 +30,4 @@ TEMPLATE_LOADERS = ( 'dbtemplates.loader.Loader', ) -JENKINS_TASKS = ( - 'django_jenkins.tasks.run_pyflakes', - 'django_jenkins.tasks.run_pep8', - 'django_jenkins.tasks.with_coverage', - 'django_jenkins.tasks.django_tests', -) +TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' diff --git a/dbtemplates/utils/template.py b/dbtemplates/utils/template.py index 2113237..679a7d9 100644 --- a/dbtemplates/utils/template.py +++ b/dbtemplates/utils/template.py @@ -8,13 +8,11 @@ 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_func) + from django.template.loader import find_template as finder except ImportError: - from django.template.loader import ( - find_template_source as finder_func) + from django.template.loader import find_template_source as finder # noqa try: - source, name = finder_func('test') + source, name = finder('test') except TemplateDoesNotExist: pass from django.template.loader import template_source_loaders diff --git a/requirements/tests.txt b/requirements/tests.txt index 1a70548..06f0477 100644 --- a/requirements/tests.txt +++ b/requirements/tests.txt @@ -1,5 +1,3 @@ -pep8 -pyflakes -django-jenkins +flake8 +dajngo-nose coverage -pylint \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index cf6fb59..78ce9b8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -11,3 +11,7 @@ upload-dir = docs/_build/html [upload_sphinx] upload-dir = docs/_build/html + +[nosetests] +with-coverage=1 +cover-package=dbtemplates From 07fe3cc7eedb6bddfc06930ae69db8e346500145 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 14:08:08 +0200 Subject: [PATCH 35/45] Fixed typo. --- requirements/tests.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/tests.txt b/requirements/tests.txt index 06f0477..68eba17 100644 --- a/requirements/tests.txt +++ b/requirements/tests.txt @@ -1,3 +1,3 @@ flake8 -dajngo-nose +django-nose coverage From d018f826da4b414723258645aa0ffe7c18b25264 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 14:10:12 +0200 Subject: [PATCH 36/45] Forgotten dirname for flake8. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6ffd9af..59589b5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ install: before_script: - export PIP_USE_MIRRORS=true - export DJANGO_SETTINGS_MODULE=dbtemplates.test_settings - - flake8 + - flake8 dbtemplates script: - django-admin.py test dbtemplates env: From e7b6b8ce00167d6dddf1f5e9c633c047ed6ef3c0 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 14:12:07 +0200 Subject: [PATCH 37/45] Ignore long lines, stupid. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 59589b5..29545e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ install: before_script: - export PIP_USE_MIRRORS=true - export DJANGO_SETTINGS_MODULE=dbtemplates.test_settings - - flake8 dbtemplates + - flake8 dbtemplates --ignore=E501 script: - django-admin.py test dbtemplates env: From a1cec65e293cb8fd0f36d65825156a386a9d399c Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 14:15:52 +0200 Subject: [PATCH 38/45] Removed INSTALL file from manifest template. --- MANIFEST.in | 1 - 1 file changed, 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index 8d620eb..9852006 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,3 @@ -include INSTALL include LICENSE include AUTHORS include README.rst From 60215fe947cc0a5a0d7f694c3e6d987e610632cd Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 23:47:15 +0200 Subject: [PATCH 39/45] Updated AUTHORS file. --- AUTHORS | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/AUTHORS b/AUTHORS index 612aac1..9dd4105 100644 --- a/AUTHORS +++ b/AUTHORS @@ -5,10 +5,14 @@ Alexander Artemenko Arne Brodowski David Paccoud Diego Búrigo Zacarão +Dmitry Falk Jannis Leidel +Jure Cuhalev Jason Mayfield Kevin Mooney +Mark Stahler Matt Dorn Oliver George +Selwin Ong Stephan Peijnik , ANEXIA Internetdienstleistungs GmbH, http://www.anexia.at/ Zhang Kun From 4c3c459e82a5d93bc41f2b98482bd6c283fa565e Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 23:47:30 +0200 Subject: [PATCH 40/45] Updated changelog. --- docs/changelog.txt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index 9271c6e..b324766 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -1,6 +1,28 @@ Changelog ========= +v1.3 (2012-05-07) +----------------- + +* Dropped support for Django < 1.3 **backwards incompatible** + +* Dropped using versiontools in favor of home made solution. + +* Added optional support for TinyMCE editor instead of the CodeMirror + editor (just enable ``DBTEMPLATES_USE_TINYMCE``). + +* Fixed compatibility to Django 1.4's handling of the ``DATABASES`` + setting. Should also respect database routers now. + +* Fixed an issue of the cache key generation in combination with + memcache's inability to stomach spaces. + +* Moved test runner to use nose_ and a hosted CI project at Travis_: + http://travis-ci.org/jezdez/django-dbtemplates + +.. _nose: http://nose.rtfd.org/ +.. _Travis: http://travis-ci.org + v1.2.1 (2011-09-07) ------------------- From ee29bbe46ee2529a233e2c570c44b6a77d6f198e Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 23:48:07 +0200 Subject: [PATCH 41/45] Updated settings docs. --- docs/settings.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/settings.txt b/docs/settings.txt index c541d2c..45b5bbe 100644 --- a/docs/settings.txt +++ b/docs/settings.txt @@ -28,6 +28,14 @@ The dotted Python path to the cache backend class. See A boolean, if enabled triggers the use of the CodeMirror based editor. Set to ``False`` by default. +``DBTEMPLATES_USE_TINYMCE`` +--------------------------- + +.. versionadded:: 1.3 + +A boolean, if enabled triggers the use of the TinyMCE based editor. +Set to ``False`` by default. + ``DBTEMPLATES_USE_REVERSION`` ----------------------------- From c59de762f96b6cc108bd591a9754459b3bb62818 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 23:48:21 +0200 Subject: [PATCH 42/45] Correct version. --- dbtemplates/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbtemplates/__init__.py b/dbtemplates/__init__.py index 66b4ea1..622f112 100644 --- a/dbtemplates/__init__.py +++ b/dbtemplates/__init__.py @@ -1,2 +1,2 @@ # following PEP 386 -__version__ = "1.2a1" +__version__ = "1.3a1" From ca9d2fc468f1a43c3a771a3fba0441b4a6529820 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 23:50:01 +0200 Subject: [PATCH 43/45] Removed old hg tags. --- .hgtags | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 .hgtags diff --git a/.hgtags b/.hgtags deleted file mode 100644 index c9e6f4c..0000000 --- a/.hgtags +++ /dev/null @@ -1,24 +0,0 @@ -bd537cd8beba30f1a26328e02126d3d1b14ebf8f 0.2.5 -1b426859f05b8a003411964883ed5d42ec6c1b01 0.3.0 -97da228cc698bfae05f60a68ec978030722b0777 0.3.1 -50c69325d3758d2e82541b13be2794ebbe9ee449 0.4.0 -d35a41ea96d3604a3c2654590c5c76b8865c4251 0.4.1 -a4bd56a7c2ea4c6f16a726e47bb185101934fe08 0.4.2 -447247c1ce1fbc77ac79c5855630af306f4f8c42 0.4.3 -5b2e4f7fc267daf71325991e913f98e6f96259bb 0.4.4 -ea4d636f3459ddbb51d87e921cf23f87e41d658d 0.4.5 -9a30f34bc5b07376ed6752eed94d9d58e791fbac 0.4.6 -9dc2a0e48494d6a354f5ca25db31638cede4bae4 0.4.7 -a3be97628ed8633e2fe232e6680474e7fd3e9fea 0.5.0 -bf3db2fe192d4a02bf531e61e23df342c36d6b1b 0.5.1 -67a86cf9f7c8ac8d9da855c13abbef2547033cce 0.5.2 -6967bbbee378f470e4b1df02b57112dd050d424b 0.5.3 -5965315c03c1a8c1cfb34752cca3802d68156e27 0.5.4 -4109e0db4340042cb85ea8a7d2b6ce37245738c6 0.5.5 -ade167225d06cb6888ea8bfa84e7d020590171c6 0.5.6 -dff01be9c8af328f8fcbc2fc97edcbe8d97840e2 0.5.7 -f8f7eaf275c5e8ac52174642265af55691abef7c 0.5.8 -4b36382cdfd756f45f81b0d042aaf331c3eabe30 0.6.0 -0ac352fec2c2a03ac801ff0c40f0649ef16e1f64 0.6.1 -34a0511928629872ce8cc5f94c6bed65f82ac343 0.7.0 -74c22fa8c4a64ea37f9b6b2515a4162b8b8b1a2a 0.7.1 From 25d92837580500c00d08c14a27e8dec74a12c31f Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 23:52:50 +0200 Subject: [PATCH 44/45] Use version from __version__. --- docs/conf.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 3c8990a..0bccac6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -16,7 +16,7 @@ import sys, os # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -#sys.path.append(os.path.abspath('.')) +sys.path.append(os.path.abspath('.')) # -- General configuration ----------------------------------------------------- @@ -45,9 +45,14 @@ copyright = u'2007-2012, Jannis Leidel and contributors' # built documents. # # The short X.Y version. -version = '1.2' -# The full version, including alpha/beta/rc tags. -release = '1.2.1' +try: + from dbtemplates import __version__ + # The short X.Y version. + version = '.'.join(__version__.split('.')[:2]) + # The full version, including alpha/beta/rc tags. + release = __version__ +except ImportError: + version = release = 'dev' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. From 8844180d6caadef560242d6ecffb9c994b93daff Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 7 May 2012 23:52:59 +0200 Subject: [PATCH 45/45] Bumped version to 1.3. --- dbtemplates/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbtemplates/__init__.py b/dbtemplates/__init__.py index 622f112..6524f6c 100644 --- a/dbtemplates/__init__.py +++ b/dbtemplates/__init__.py @@ -1,2 +1,2 @@ # following PEP 386 -__version__ = "1.3a1" +__version__ = "1.3"