mirror of
https://github.com/jazzband/django-dbtemplates.git
synced 2026-03-16 22:20:28 +00:00
Merge branch 'release/1.2.1'
This commit is contained in:
commit
357954a83c
11 changed files with 124 additions and 236 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -7,4 +7,7 @@ dist
|
|||
example/example.db
|
||||
docs/_build
|
||||
.tox/
|
||||
*.egg/
|
||||
*.egg/
|
||||
pep8.txt
|
||||
coverage.xml
|
||||
.coverage
|
||||
|
|
@ -1,16 +1,2 @@
|
|||
VERSION = (1, 2, 0, "f", 0) # following PEP 386
|
||||
DEV_N = None
|
||||
|
||||
|
||||
def get_version():
|
||||
version = "%s.%s" % (VERSION[0], VERSION[1])
|
||||
if VERSION[2]:
|
||||
version = "%s.%s" % (version, VERSION[2])
|
||||
if VERSION[3] != "f":
|
||||
version = "%s%s%s" % (version, VERSION[3], VERSION[4])
|
||||
if DEV_N:
|
||||
version = "%s.dev%s" % (version, DEV_N)
|
||||
return version
|
||||
|
||||
|
||||
__version__ = get_version()
|
||||
# following PEP 386, versiontools will pick it up
|
||||
__version__ = (1, 2, 1, "final", 0)
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
import posixpath
|
||||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.conf import settings
|
||||
|
||||
from dbtemplates.utils.settings import AppSettings
|
||||
from appconf import AppConf
|
||||
|
||||
|
||||
class DbTemplatesSettings(AppSettings):
|
||||
class DbTemplatesConf(AppConf):
|
||||
USE_CODEMIRROR = False
|
||||
USE_REVERSION = False
|
||||
ADD_DEFAULT_SITE = True
|
||||
|
|
@ -15,16 +16,16 @@ class DbTemplatesSettings(AppSettings):
|
|||
|
||||
def configure_media_prefix(self, value):
|
||||
if value is None:
|
||||
base_url = getattr(self, "STATIC_URL", None)
|
||||
base_url = getattr(settings, "STATIC_URL", None)
|
||||
if base_url is None:
|
||||
base_url = self.MEDIA_URL
|
||||
base_url = settings.MEDIA_URL
|
||||
value = posixpath.join(base_url, "dbtemplates/")
|
||||
return value
|
||||
|
||||
def configure_cache_backend(self, value):
|
||||
# If we are on Django 1.3 AND using the new CACHES setting..
|
||||
if hasattr(self, "CACHES"):
|
||||
if "dbtemplates" in self.CACHES:
|
||||
if hasattr(settings, "CACHES"):
|
||||
if "dbtemplates" in settings.CACHES:
|
||||
return "dbtemplates"
|
||||
else:
|
||||
return "default"
|
||||
|
|
@ -35,9 +36,7 @@ class DbTemplatesSettings(AppSettings):
|
|||
return value
|
||||
|
||||
def configure_use_reversion(self, value):
|
||||
if value and 'reversion' not in self.INSTALLED_APPS:
|
||||
if value and 'reversion' not in settings.INSTALLED_APPS:
|
||||
raise ImproperlyConfigured("Please add 'reversion' to your "
|
||||
"INSTALLED_APPS setting to make use of it in dbtemplates.")
|
||||
return value
|
||||
|
||||
settings = DbTemplatesSettings("DBTEMPLATES")
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from datetime import datetime
|
|||
from django.db import models
|
||||
from django.db.models import signals
|
||||
from django.template import TemplateDoesNotExist
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from django.contrib.sites.models import Site
|
||||
from django.contrib.sites.managers import CurrentSiteManager
|
||||
|
|
@ -22,7 +22,7 @@ class Template(models.Model):
|
|||
name = models.CharField(_('name'), max_length=100,
|
||||
help_text=_("Example: 'flatpages/default.html'"))
|
||||
content = models.TextField(_('content'), blank=True)
|
||||
sites = models.ManyToManyField(Site, verbose_name=_('sites'),
|
||||
sites = models.ManyToManyField(Site, verbose_name=_(u'sites'),
|
||||
blank=True, null=True)
|
||||
creation_date = models.DateTimeField(_('creation date'),
|
||||
default=datetime.now)
|
||||
|
|
|
|||
18
dbtemplates/test_settings.py
Normal file
18
dbtemplates/test_settings.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
DBTEMPLATES_CACHE_BACKEND = 'dummy://'
|
||||
|
||||
DATABASE_ENGINE = 'sqlite3'
|
||||
|
||||
SITE_ID = 1
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sites',
|
||||
'django.contrib.admin',
|
||||
'dbtemplates',
|
||||
]
|
||||
|
||||
TEMPLATE_LOADERS = (
|
||||
'django.template.loaders.filesystem.Loader',
|
||||
'django.template.loaders.app_directories.Loader',
|
||||
'dbtemplates.loader.Loader',
|
||||
)
|
||||
|
|
@ -1,106 +0,0 @@
|
|||
from inspect import getmembers
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class AppSettings(object):
|
||||
"""
|
||||
An app setting object to be used for handling app setting defaults
|
||||
gracefully and providing a nice API for them. Say you have an app
|
||||
called ``myapp`` and want to define a few defaults, and refer to the
|
||||
defaults easily in the apps code. Add a ``settings.py`` to your app::
|
||||
|
||||
from path.to.utils import AppSettings
|
||||
|
||||
class MyAppSettings(AppSettings):
|
||||
SETTING_1 = "one"
|
||||
SETTING_2 = (
|
||||
"two",
|
||||
)
|
||||
|
||||
Then initialize the setting with the correct prefix in the location of
|
||||
of your choice, e.g. ``conf.py`` of the app module::
|
||||
|
||||
settings = MyAppSettings(prefix="MYAPP")
|
||||
|
||||
The ``MyAppSettings`` instance will automatically look at Django's
|
||||
global setting to determine each of the settings and respect the
|
||||
provided ``prefix``. E.g. adding this to your site's ``settings.py``
|
||||
will set the ``SETTING_1`` setting accordingly::
|
||||
|
||||
MYAPP_SETTING_1 = "uno"
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
Instead of using ``from django.conf import settings`` as you would
|
||||
usually do, you can switch to using your apps own settings module
|
||||
to access the app settings::
|
||||
|
||||
from myapp.conf import settings
|
||||
|
||||
print myapp_settings.MYAPP_SETTING_1
|
||||
|
||||
``AppSettings`` instances also work as pass-throughs for other
|
||||
global settings that aren't related to the app. For example the
|
||||
following code is perfectly valid::
|
||||
|
||||
from myapp.conf import settings
|
||||
|
||||
if "myapp" in settings.INSTALLED_APPS:
|
||||
print "yay, myapp is installed!"
|
||||
|
||||
Custom handling
|
||||
---------------
|
||||
|
||||
Each of the settings can be individually configured with callbacks.
|
||||
For example, in case a value of a setting depends on other settings
|
||||
or other dependencies. The following example sets one setting to a
|
||||
different value depending on a global setting::
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
class MyCustomAppSettings(AppSettings):
|
||||
ENABLED = True
|
||||
|
||||
def configure_enabled(self, value):
|
||||
return value and not self.DEBUG
|
||||
|
||||
custom_settings = MyCustomAppSettings("MYAPP")
|
||||
|
||||
The value of ``custom_settings.MYAPP_ENABLED`` will vary depending on the
|
||||
value of the global ``DEBUG`` setting.
|
||||
|
||||
Each of the app settings can be customized by providing
|
||||
a method ``configure_<lower_setting_name>`` that takes the default
|
||||
value as defined in the class attributes as the only parameter.
|
||||
The method needs to return the value to be use for the setting in
|
||||
question.
|
||||
"""
|
||||
def __dir__(self):
|
||||
return sorted(list(set(self.__dict__.keys() + dir(settings))))
|
||||
|
||||
__members__ = lambda self: self.__dir__()
|
||||
|
||||
def __getattr__(self, name):
|
||||
if name.startswith(self._prefix):
|
||||
raise AttributeError("%r object has no attribute %r" %
|
||||
(self.__class__.__name__, name))
|
||||
return getattr(settings, name)
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
super(AppSettings, self).__setattr__(name, value)
|
||||
if name in dir(settings):
|
||||
setattr(settings, name, value)
|
||||
|
||||
def __init__(self, prefix):
|
||||
super(AppSettings, self).__setattr__('_prefix', prefix)
|
||||
for setting, class_value in getmembers(self.__class__):
|
||||
if setting == setting.upper():
|
||||
prefixed = "%s_%s" % (prefix.upper(), setting.upper())
|
||||
configured_value = getattr(settings, prefixed, class_value)
|
||||
callback_name = "configure_%s" % setting.lower()
|
||||
callback = getattr(self, callback_name, None)
|
||||
if callable(callback):
|
||||
configured_value = callback(configured_value)
|
||||
delattr(self.__class__, setting)
|
||||
setattr(self, prefixed, configured_value)
|
||||
|
|
@ -1,16 +1,25 @@
|
|||
Changelog
|
||||
=========
|
||||
|
||||
1.2 (08-15-11)
|
||||
--------------
|
||||
v1.2.1 (2011-09-07)
|
||||
-------------------
|
||||
|
||||
* Fixed a wrong use of the non-lazy localization tools.
|
||||
|
||||
* Fixed bugs in the documentation.
|
||||
|
||||
* Make use of django-appconf and versiontools.
|
||||
|
||||
v1.2 (2011-08-15)
|
||||
-----------------
|
||||
|
||||
* Refactored the template loader to be even more cache effective.
|
||||
|
||||
* Added ``check_template_syntax`` management command and admin action
|
||||
to make sure the saved templates are valid Django templates.
|
||||
|
||||
1.1.1 (07-08-11)
|
||||
----------------
|
||||
v1.1.1 (2011-07-08)
|
||||
-------------------
|
||||
|
||||
* Fixed bug in cache loading (again).
|
||||
|
||||
|
|
@ -23,8 +32,8 @@ Changelog
|
|||
(``'dbtemplates.loader.Loader'``) and **not** the previosly included
|
||||
function that ended with ``load_template_source``.
|
||||
|
||||
1.1 (07-06-11)
|
||||
--------------
|
||||
v1.1 (2011-07-06)
|
||||
-----------------
|
||||
|
||||
* **BACKWARDS-INCOMPATIBLE** Requires Django 1.2 or higher.
|
||||
For previous Django versions use an older versions of ``dbtemplates``,
|
||||
|
|
@ -65,13 +74,13 @@ Changelog
|
|||
|
||||
* Fixed issue with cache settings handling.
|
||||
|
||||
1.0.1 (04-14-11)
|
||||
----------------
|
||||
v1.0.1 (2011-04-14)
|
||||
-------------------
|
||||
|
||||
* Minor bugfixes with regard to the new cache handling.
|
||||
|
||||
1.0 (04-11-11)
|
||||
--------------
|
||||
v1.0 (2011-04-11)
|
||||
-----------------
|
||||
|
||||
.. warning::
|
||||
This is the first stable release of django-dbtemplates which comes with a
|
||||
|
|
@ -94,33 +103,33 @@ Changelog
|
|||
|
||||
* Use ReadTheDocs for documentation hosting.
|
||||
|
||||
0.8.0 (11-07-10)
|
||||
----------------
|
||||
v0.8.0 (2010-11-07)
|
||||
-------------------
|
||||
|
||||
* Added Finnish translation (by jholster)
|
||||
|
||||
* Added --overwrite and --app-first options to sync_templates command (by Alex Kamedov).
|
||||
|
||||
0.7.4 (09-23-10)
|
||||
----------------
|
||||
v0.7.4 (2010-09-23)
|
||||
-------------------
|
||||
|
||||
* Fixed tests.
|
||||
|
||||
0.7.3 (09-21-10)
|
||||
----------------
|
||||
v0.7.3 (2010-09-21)
|
||||
-------------------
|
||||
|
||||
* Added ``DBTEMPLATES_AUTO_POPULATE_CONTENT`` setting to be able to disable
|
||||
to auto-populating of template content.
|
||||
|
||||
* Fixed cosmetic issue in admin with collapsable fields.
|
||||
|
||||
0.7.2 (09-04-10)
|
||||
----------------
|
||||
v0.7.2 (2010-09-04)
|
||||
-------------------
|
||||
|
||||
* Moved to Github again. Sigh.
|
||||
|
||||
0.7.1 (07-07-10)
|
||||
----------------
|
||||
v0.7.1 (2010-07-07)
|
||||
-------------------
|
||||
|
||||
* Fixed problem with the CodeMirror textarea, which wasn't completely
|
||||
disabled before.
|
||||
|
|
@ -132,8 +141,8 @@ Changelog
|
|||
and have the CodeMirror textarea enabled, dbtemplates will look in a
|
||||
subdirectory of your site's ``MEDIA_ROOT`` for the CodeMirror media files.
|
||||
|
||||
0.7.0 (06-24-10)
|
||||
----------------
|
||||
v0.7.0 (2010-06-24)
|
||||
-------------------
|
||||
|
||||
* Added CodeMirror_-based syntax highlighting textarea, based on the amaxing
|
||||
work_ by `Nic Pottier`_. Set the ``DBTEMPLATES_USE_CODEMIRROR`` setting
|
||||
|
|
@ -154,14 +163,14 @@ Changelog
|
|||
.. _work: https://gist.github.com/368758/86bcafe53c438e2e2a0e3442c3b30f2c6011fbba
|
||||
.. _`Nic Pottier`: http://github.com/nicpottier
|
||||
|
||||
0.6.1 (10-19-09):
|
||||
-----------------
|
||||
v0.6.1 (2009-10-19)
|
||||
-------------------
|
||||
|
||||
* Fixed issue with default site of a template, added ability to disable
|
||||
default site (``DBTEMPLATES_ADD_DEFAULT_SITE``).
|
||||
|
||||
0.6.0 (10-09-09):
|
||||
-----------------
|
||||
v0.6.0 (2009-10-09)
|
||||
-------------------
|
||||
|
||||
* Updated and added locales (Danish, Brazilian Portuguese)
|
||||
|
||||
|
|
@ -171,8 +180,8 @@ Changelog
|
|||
|
||||
* Added Sphinx documentation
|
||||
|
||||
0.5.7
|
||||
-----
|
||||
v0.5.7
|
||||
------
|
||||
|
||||
* Updates to the docs
|
||||
|
||||
|
|
@ -186,8 +195,8 @@ Changelog
|
|||
|
||||
* fixed bug in ``create_error_template`` command.
|
||||
|
||||
0.5.4
|
||||
-----
|
||||
v0.5.4
|
||||
------
|
||||
|
||||
* Made loader and cache backends site-aware.
|
||||
|
||||
|
|
@ -199,16 +208,16 @@ Changelog
|
|||
* Template is now saved explicitly to backend if not existent in cache
|
||||
(e.g. if deleted manually or invalidated).
|
||||
|
||||
0.5.3
|
||||
-----
|
||||
v0.5.3
|
||||
------
|
||||
|
||||
* Removed automatic creation of 404.html and 500.html templates and added a
|
||||
* Removed automatic creation of 404.html and 50v0.html templates and added a
|
||||
new management command for those cases called ``create_error_templates``
|
||||
|
||||
* Also reverted move to Bitbucket
|
||||
|
||||
0.5.2
|
||||
-----
|
||||
v0.5.2
|
||||
------
|
||||
|
||||
* Fixed a problem with ``django.contrib.sites`` when its table hasn't been
|
||||
populated yet on initialization of dbtemplates. Thanks for the report,
|
||||
|
|
@ -216,8 +225,8 @@ Changelog
|
|||
|
||||
* Added an example Django project and docs for it
|
||||
|
||||
0.5.1
|
||||
-----
|
||||
v0.5.1
|
||||
------
|
||||
|
||||
* Removed unneeded code that registered the model with reversion.
|
||||
|
||||
|
|
@ -228,8 +237,8 @@ Changelog
|
|||
* Removed legacy ``sync_templates.py`` script, use ``django-admin.py
|
||||
sync_templates`` from now on.
|
||||
|
||||
0.5.0
|
||||
-----
|
||||
v0.5.0
|
||||
------
|
||||
|
||||
* Added support for `django-reversion`_
|
||||
|
||||
|
|
@ -246,60 +255,60 @@ Changelog
|
|||
.. _django-reversion: http://code.google.com/p/django-reversion/
|
||||
.. _blog post: http://jannisleidel.com/2008/11/updates-to-django-dbtemplates-and-half-assed-promise/
|
||||
|
||||
0.4.7
|
||||
-----
|
||||
v0.4.7
|
||||
------
|
||||
|
||||
* Minor bugfix
|
||||
|
||||
0.4.6
|
||||
-----
|
||||
v0.4.6
|
||||
------
|
||||
|
||||
* Minor doc change and PyPI support
|
||||
|
||||
0.4.5
|
||||
-----
|
||||
v0.4.5
|
||||
------
|
||||
|
||||
* fixed the --force option of the sync_templates command
|
||||
|
||||
0.4.4
|
||||
-----
|
||||
v0.4.4
|
||||
------
|
||||
|
||||
* fixed error in custom model save() after changes in Django `r8670`_.
|
||||
|
||||
.. _r8670: http://code.djangoproject.com/changeset/8670
|
||||
|
||||
0.4.3
|
||||
-----
|
||||
v0.4.3
|
||||
------
|
||||
|
||||
* removed oldforms code
|
||||
|
||||
0.4.2
|
||||
-----
|
||||
v0.4.2
|
||||
------
|
||||
|
||||
* added Hebrew translation (by mkriheli)
|
||||
|
||||
0.4.1
|
||||
-----
|
||||
v0.4.1
|
||||
------
|
||||
|
||||
* added French (by Roland Frederic) and German locale
|
||||
|
||||
0.4.0
|
||||
-----
|
||||
v0.4.0
|
||||
------
|
||||
|
||||
* adds better support for newforms-admin
|
||||
|
||||
* don't forget to load the dbtemplates.admin, e.g. by using
|
||||
django.contrib.admin.autodiscover() in you urls.py
|
||||
|
||||
0.3.1
|
||||
-----
|
||||
v0.3.1
|
||||
------
|
||||
|
||||
* adds a new management command *sync_templates* for bidirectional syncing
|
||||
between filesystem and database (backwards-compatible) and
|
||||
FilesystemCaching (thanks, Arne Brodowski!)
|
||||
|
||||
0.2.5
|
||||
-----
|
||||
v0.2.5
|
||||
------
|
||||
|
||||
* adds support for newforms-admin
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ copyright = u'2007-2011, Jannis Leidel and contributors'
|
|||
# The short X.Y version.
|
||||
version = '1.2'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = '1.2'
|
||||
release = '1.2.1'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
|
|
|
|||
37
runtests.py
37
runtests.py
|
|
@ -1,37 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
import os
|
||||
import sys
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
if not settings.configured:
|
||||
settings.configure(
|
||||
DBTEMPLATES_CACHE_BACKEND = 'dummy://',
|
||||
DATABASE_ENGINE='sqlite3',
|
||||
SITE_ID=1,
|
||||
INSTALLED_APPS=[
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sites',
|
||||
'django.contrib.admin',
|
||||
'dbtemplates',
|
||||
],
|
||||
TEMPLATE_LOADERS = (
|
||||
'django.template.loaders.filesystem.Loader',
|
||||
'django.template.loaders.app_directories.Loader',
|
||||
'dbtemplates.loader.Loader',
|
||||
)
|
||||
)
|
||||
|
||||
from django.test.simple import run_tests
|
||||
|
||||
|
||||
def runtests(*test_args):
|
||||
if not test_args:
|
||||
test_args = ['dbtemplates']
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'dbtemplates'))
|
||||
failures = run_tests(test_args, verbosity=1, interactive=True)
|
||||
sys.exit(failures)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
runtests(*sys.argv[1:])
|
||||
10
setup.py
10
setup.py
|
|
@ -1,10 +1,14 @@
|
|||
import codecs
|
||||
from os import path
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
read = lambda filepath: codecs.open(filepath, 'r', 'utf-8').read()
|
||||
|
||||
setup(
|
||||
name='django-dbtemplates',
|
||||
version=__import__('dbtemplates').__version__,
|
||||
version=':versiontools:dbtemplates:',
|
||||
description='Template loader for templates stored in the database',
|
||||
long_description=open('README.rst').read(),
|
||||
long_description=read(path.join(path.dirname(__file__), 'README.rst')),
|
||||
author='Jannis Leidel',
|
||||
author_email='jannis@leidel.info',
|
||||
url='http://django-dbtemplates.readthedocs.org/',
|
||||
|
|
@ -30,4 +34,6 @@ setup(
|
|||
'Programming Language :: Python :: 2.7',
|
||||
'Framework :: Django',
|
||||
],
|
||||
install_requires=['django-appconf >= 0.4'],
|
||||
setup_requires=['versiontools >= 1.5'],
|
||||
)
|
||||
|
|
|
|||
16
tox.ini
16
tox.ini
|
|
@ -1,41 +1,51 @@
|
|||
[tox]
|
||||
downloadcache = .tox/_download/
|
||||
distribute = False
|
||||
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/
|
||||
commands =
|
||||
python runtests.py
|
||||
{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"
|
||||
|
||||
[testenv:py25-1.2.X]
|
||||
basepython = python2.5
|
||||
deps =
|
||||
coverage
|
||||
django==1.2.5
|
||||
|
||||
[testenv:py26-1.2.X]
|
||||
basepython = python2.6
|
||||
deps =
|
||||
coverage
|
||||
django==1.2.5
|
||||
|
||||
[testenv:py27-1.2.X]
|
||||
basepython = python2.7
|
||||
deps =
|
||||
coverage
|
||||
django==1.2.5
|
||||
|
||||
|
||||
[testenv:py25-1.3.X]
|
||||
basepython = python2.5
|
||||
deps =
|
||||
coverage
|
||||
django==1.3
|
||||
|
||||
[testenv:py26-1.3.X]
|
||||
basepython = python2.6
|
||||
deps =
|
||||
coverage
|
||||
django==1.3
|
||||
|
||||
[testenv:py27-1.3.X]
|
||||
basepython = python2.7
|
||||
deps =
|
||||
coverage
|
||||
django==1.3
|
||||
|
|
|
|||
Loading…
Reference in a new issue