mirror of
https://github.com/jazzband/django-dbtemplates.git
synced 2026-03-16 22:20:28 +00:00
Compare commits
89 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
10e7de2eda | ||
|
|
930ce5c65c | ||
|
|
8e284b54d8 | ||
|
|
05f1ee1193 | ||
|
|
303bd0cabe | ||
|
|
64d112cc4f | ||
|
|
7f1c6701c1 | ||
|
|
873c90b777 | ||
|
|
e64a457281 | ||
|
|
a7f4e0bbe8 | ||
|
|
218b28b7aa | ||
|
|
602717af95 | ||
|
|
8769e29057 | ||
|
|
ac740e06f3 | ||
|
|
233a401e75 | ||
|
|
13bacacef8 | ||
|
|
fa72b2771b | ||
|
|
fac9f6a807 | ||
|
|
f53244ce54 | ||
|
|
6ca53981d3 | ||
|
|
45e216b8ac | ||
|
|
5a363dbe34 | ||
|
|
2c8dc82721 | ||
|
|
98bc9921b0 | ||
|
|
b6b0bf48ba | ||
|
|
36fbb80fc0 | ||
|
|
e08a8d3950 | ||
|
|
6dd23d2325 | ||
|
|
a68caedc2d | ||
|
|
2b5034951f | ||
|
|
b138cafcfa | ||
|
|
f98fb8ca24 | ||
|
|
2e3f009426 | ||
|
|
8e8b76fc0a | ||
|
|
49dd3be520 | ||
|
|
74ee8a2fe3 | ||
|
|
1a20742b71 | ||
|
|
9455b36281 | ||
|
|
165ffd0b15 | ||
|
|
a3054c7724 | ||
|
|
e5e4e55d22 | ||
|
|
9a27f4938c | ||
|
|
013057425f | ||
|
|
7ffc0fa33f | ||
|
|
de4babcad4 | ||
|
|
6b18f19ffd | ||
|
|
5281b74ea7 | ||
|
|
9dbdb95227 | ||
|
|
e1e11c42cb | ||
|
|
9f664ea43c | ||
|
|
e477561810 | ||
|
|
2d622ee28c | ||
|
|
8901551893 | ||
|
|
9e4a6f7c78 | ||
|
|
9486f0c78b | ||
|
|
376f33916f | ||
|
|
8cd8a17bc1 | ||
|
|
f45cd228f9 | ||
|
|
24b5f469a2 | ||
|
|
2b747bc4af | ||
|
|
ac86ca5ec9 | ||
|
|
012fe061a8 | ||
|
|
68ac54a72b | ||
|
|
7ea4655b57 | ||
|
|
1d53b25cc2 | ||
|
|
81ba1364f8 | ||
|
|
ae97ad7e24 | ||
|
|
5c6c35bf3d | ||
|
|
50f02a50bc | ||
|
|
230157640c | ||
|
|
f443f29047 | ||
|
|
79d1d3986f | ||
|
|
73a33361d3 | ||
|
|
a04933e5ce | ||
|
|
78ca3f48dd | ||
|
|
727746add1 | ||
|
|
07d62d8d26 | ||
|
|
4ece48c7b2 | ||
|
|
966b68ee5c | ||
|
|
039f6f419f | ||
|
|
24c8d2005a | ||
|
|
df358a53dd | ||
|
|
f5b9e36fc7 | ||
|
|
16afa49831 | ||
|
|
cef1ec49c0 | ||
|
|
745e64f3e0 | ||
|
|
28bde8c32d | ||
|
|
db5e4ec4b6 | ||
|
|
3ba01f425c |
34 changed files with 617 additions and 294 deletions
|
|
@ -3,4 +3,4 @@ source = dbtemplates
|
|||
branch = 1
|
||||
|
||||
[report]
|
||||
omit = *tests*,*migrations*
|
||||
omit = *tests*,*/migrations/*,test_*
|
||||
|
|
|
|||
40
.github/workflows/release.yml
vendored
Normal file
40
.github/workflows/release.yml
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
if: github.repository == 'jazzband/django-dbtemplates'
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: "3.10"
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install -U pip
|
||||
python -m pip install -U setuptools twine wheel
|
||||
|
||||
- name: Build package
|
||||
run: |
|
||||
python setup.py --version
|
||||
python setup.py sdist --format=gztar bdist_wheel
|
||||
twine check dist/*
|
||||
|
||||
- name: Upload packages to Jazzband
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
|
||||
uses: pypa/gh-action-pypi-publish@release/v1
|
||||
with:
|
||||
user: jazzband
|
||||
password: ${{ secrets.JAZZBAND_RELEASE_KEY }}
|
||||
repository_url: https://jazzband.co/projects/django-dbtemplates/upload
|
||||
48
.github/workflows/test.yml
vendored
Normal file
48
.github/workflows/test.yml
vendored
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
name: Test
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
max-parallel: 5
|
||||
matrix:
|
||||
python-version: ['3.8', '3.9', '3.10', '3.11', '3.13']
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
|
||||
- name: Get pip cache dir
|
||||
id: pip-cache
|
||||
run: |
|
||||
echo "::set-output name=dir::$(pip cache dir)"
|
||||
|
||||
- name: Cache
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ${{ steps.pip-cache.outputs.dir }}
|
||||
key:
|
||||
${{ matrix.python-version }}-v1-${{ hashFiles('**/setup.py') }}-${{ hashFiles('**/tox.ini') }}
|
||||
restore-keys: |
|
||||
${{ matrix.python-version }}-v1-
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
python -m pip install --upgrade tox tox-gh-actions
|
||||
|
||||
- name: Tox tests
|
||||
run: |
|
||||
tox -v
|
||||
|
||||
- name: Upload coverage
|
||||
uses: codecov/codecov-action@v2
|
||||
with:
|
||||
name: Python ${{ matrix.python-version }}
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -1,3 +1,6 @@
|
|||
.*
|
||||
!.gitignore
|
||||
!.coveragerc
|
||||
*.pyc
|
||||
.*.swp
|
||||
MANIFEST
|
||||
|
|
@ -8,3 +11,4 @@ docs/_build
|
|||
.tox/
|
||||
*.egg/
|
||||
.coverage
|
||||
coverage.xml
|
||||
|
|
|
|||
15
.pre-commit-config.yaml
Normal file
15
.pre-commit-config.yaml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
repos:
|
||||
- repo: https://github.com/asottile/pyupgrade
|
||||
rev: v2.34.0
|
||||
hooks:
|
||||
- id: pyupgrade
|
||||
args: [--py37-plus]
|
||||
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.3.0
|
||||
hooks:
|
||||
- id: check-merge-conflict
|
||||
- id: check-yaml
|
||||
|
||||
ci:
|
||||
autoupdate_schedule: quarterly
|
||||
25
.readthedocs.yaml
Normal file
25
.readthedocs.yaml
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# .readthedocs.yaml
|
||||
# Read the Docs configuration file
|
||||
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
|
||||
|
||||
# Required
|
||||
version: 2
|
||||
|
||||
# Set the version of Python and other tools you might need
|
||||
build:
|
||||
os: ubuntu-20.04
|
||||
tools:
|
||||
python: "3.9"
|
||||
|
||||
# Build documentation in the docs/ directory with Sphinx
|
||||
sphinx:
|
||||
configuration: docs/conf.py
|
||||
|
||||
# If using Sphinx, optionally build your docs in additional formats such as PDF
|
||||
formats:
|
||||
- pdf
|
||||
|
||||
# Optionally declare the Python requirements required to build your docs
|
||||
python:
|
||||
install:
|
||||
- requirements: requirements/docs.txt
|
||||
30
.travis.yml
30
.travis.yml
|
|
@ -1,30 +0,0 @@
|
|||
language: python
|
||||
python:
|
||||
- '2.7'
|
||||
- '3.4'
|
||||
- '3.5'
|
||||
- '3.6'
|
||||
# Enable 3.7 without globally enabling sudo and dist: xenial for other build jobs
|
||||
# See https://github.com/travis-ci/travis-ci/issues/9815
|
||||
matrix:
|
||||
include:
|
||||
- python: 3.7
|
||||
dist: xenial
|
||||
sudo: true
|
||||
sudo: false
|
||||
cache: pip
|
||||
install:
|
||||
- pip install tox-travis
|
||||
script: tox -v
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
deploy:
|
||||
provider: pypi
|
||||
user: jazzband
|
||||
distributions: "sdist bdist_wheel"
|
||||
password:
|
||||
secure: B7imNYNndd2HEr79+3/jXLjFo/MdzzHUkH1NJ7G+YFtYjEkRFEaVuPXhuX1LYO9/qzYDcqHVrnsg65ZUXCftAg0/zFZ7zhEn/WEYZA2nkPosoSrYNV+s3XH/DMmpXdG6mKRN4D0mLQXaCwGeuQ2wHFOg7HCsz+tojFwYnEyN9ag=
|
||||
on:
|
||||
tags: true
|
||||
repo: jazzband/django-dbtemplates
|
||||
python: 3.7
|
||||
46
CODE_OF_CONDUCT.md
Normal file
46
CODE_OF_CONDUCT.md
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
# Code of Conduct
|
||||
|
||||
As contributors and maintainers of the Jazzband projects, and in the interest of
|
||||
fostering an open and welcoming community, we pledge to respect all people who
|
||||
contribute through reporting issues, posting feature requests, updating documentation,
|
||||
submitting pull requests or patches, and other activities.
|
||||
|
||||
We are committed to making participation in the Jazzband a harassment-free experience
|
||||
for everyone, regardless of the level of experience, gender, gender identity and
|
||||
expression, sexual orientation, disability, personal appearance, body size, race,
|
||||
ethnicity, age, religion, or nationality.
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
- The use of sexualized language or imagery
|
||||
- Personal attacks
|
||||
- Trolling or insulting/derogatory comments
|
||||
- Public or private harassment
|
||||
- Publishing other's private information, such as physical or electronic addresses,
|
||||
without explicit permission
|
||||
- Other unethical or unprofessional conduct
|
||||
|
||||
The Jazzband roadies have the right and responsibility to remove, edit, or reject
|
||||
comments, commits, code, wiki edits, issues, and other contributions that are not
|
||||
aligned to this Code of Conduct, or to ban temporarily or permanently any contributor
|
||||
for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
By adopting this Code of Conduct, the roadies commit themselves to fairly and
|
||||
consistently applying these principles to every aspect of managing the jazzband
|
||||
projects. Roadies who do not follow or enforce the Code of Conduct may be permanently
|
||||
removed from the Jazzband roadies.
|
||||
|
||||
This code of conduct applies both within project spaces and in public spaces when an
|
||||
individual is representing the project or its community.
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by
|
||||
contacting the roadies at `roadies@jazzband.co`. All complaints will be reviewed and
|
||||
investigated and will result in a response that is deemed necessary and appropriate to
|
||||
the circumstances. Roadies are obligated to maintain confidentiality with regard to the
|
||||
reporter of an incident.
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version
|
||||
1.3.0, available at [https://contributor-covenant.org/version/1/3/0/][version]
|
||||
|
||||
[homepage]: https://contributor-covenant.org
|
||||
[version]: https://contributor-covenant.org/version/1/3/0/
|
||||
2
LICENSE
2
LICENSE
|
|
@ -1,4 +1,4 @@
|
|||
Copyright (c) 2007-2016, Jannis Leidel and contributors
|
||||
Copyright (c) 2007-2019, Jannis Leidel and contributors
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
|||
|
|
@ -5,9 +5,8 @@ django-dbtemplates
|
|||
:alt: Jazzband
|
||||
:target: https://jazzband.co/
|
||||
|
||||
.. image:: https://travis-ci.org/jazzband/django-dbtemplates.svg?branch=master
|
||||
:alt: Build Status
|
||||
:target: http://travis-ci.org/jazzband/django-dbtemplates
|
||||
.. image:: https://github.com/jazzband/django-dbtemplates/workflows/Test/badge.svg
|
||||
:target: https://github.com/jazzband/django-dbtemplates/actions
|
||||
|
||||
.. image:: https://codecov.io/github/jazzband/django-dbtemplates/coverage.svg?branch=master
|
||||
:alt: Codecov
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
__version__ = "2.0.1"
|
||||
import importlib.metadata
|
||||
|
||||
default_app_config = 'dbtemplates.apps.DBTemplatesConfig'
|
||||
__version__ = importlib.metadata.version("django-dbtemplates")
|
||||
|
|
|
|||
|
|
@ -2,17 +2,21 @@ 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.translation import gettext_lazy as _
|
||||
from django.utils.translation import ngettext
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from dbtemplates.conf import settings
|
||||
from dbtemplates.models import (Template, remove_cached_template,
|
||||
add_template_to_cache)
|
||||
from dbtemplates.models import Template, add_template_to_cache, remove_cached_template
|
||||
from dbtemplates.utils.template import check_template_syntax
|
||||
|
||||
# Check if django-reversion is installed and use reversions' VersionAdmin
|
||||
# as the base admin class if yes
|
||||
if settings.DBTEMPLATES_USE_REVERSION:
|
||||
# Check if either django-reversion-compare or django-reversion is installed and
|
||||
# use reversion_compare's CompareVersionAdmin or reversion's VersionAdmin as
|
||||
# the base admin class if yes
|
||||
if settings.DBTEMPLATES_USE_REVERSION_COMPARE:
|
||||
from reversion_compare.admin import CompareVersionAdmin \
|
||||
as TemplateModelAdmin
|
||||
elif settings.DBTEMPLATES_USE_REVERSION:
|
||||
from reversion.admin import VersionAdmin as TemplateModelAdmin
|
||||
else:
|
||||
from django.contrib.admin import ModelAdmin as TemplateModelAdmin # noqa
|
||||
|
|
@ -27,13 +31,14 @@ class CodeMirrorTextArea(forms.Textarea):
|
|||
class Media:
|
||||
css = dict(screen=[posixpath.join(
|
||||
settings.DBTEMPLATES_MEDIA_PREFIX, 'css/editor.css')])
|
||||
js = [posixpath.join(settings.DBTEMPLATES_MEDIA_PREFIX, 'js/codemirror.js')]
|
||||
js = [posixpath.join(settings.DBTEMPLATES_MEDIA_PREFIX,
|
||||
'js/codemirror.js')]
|
||||
|
||||
def render(self, name, value, attrs=None, renderer=None):
|
||||
result = []
|
||||
result.append(
|
||||
super(CodeMirrorTextArea, self).render(name, value, attrs))
|
||||
result.append(u"""
|
||||
super().render(name, value, attrs))
|
||||
result.append("""
|
||||
<script type="text/javascript">
|
||||
var editor = CodeMirror.fromTextArea('id_%(name)s', {
|
||||
path: "%(media_prefix)sjs/",
|
||||
|
|
@ -47,7 +52,7 @@ class CodeMirrorTextArea(forms.Textarea):
|
|||
});
|
||||
</script>
|
||||
""" % dict(media_prefix=settings.DBTEMPLATES_MEDIA_PREFIX, name=name))
|
||||
return mark_safe(u"".join(result))
|
||||
return mark_safe("".join(result))
|
||||
|
||||
|
||||
if settings.DBTEMPLATES_USE_CODEMIRROR:
|
||||
|
|
@ -92,6 +97,7 @@ class TemplateAdminForm(forms.ModelForm):
|
|||
|
||||
class TemplateAdmin(TemplateModelAdmin):
|
||||
form = TemplateAdminForm
|
||||
readonly_fields = ['creation_date', 'last_changed']
|
||||
fieldsets = (
|
||||
(None, {
|
||||
'fields': ('name', 'content'),
|
||||
|
|
@ -116,7 +122,7 @@ class TemplateAdmin(TemplateModelAdmin):
|
|||
for template in queryset:
|
||||
remove_cached_template(template)
|
||||
count = queryset.count()
|
||||
message = ungettext(
|
||||
message = ngettext(
|
||||
"Cache of one template successfully invalidated.",
|
||||
"Cache of %(count)d templates successfully invalidated.",
|
||||
count)
|
||||
|
|
@ -128,7 +134,7 @@ class TemplateAdmin(TemplateModelAdmin):
|
|||
for template in queryset:
|
||||
add_template_to_cache(template)
|
||||
count = queryset.count()
|
||||
message = ungettext(
|
||||
message = ngettext(
|
||||
"Cache successfully repopulated with one template.",
|
||||
"Cache successfully repopulated with %(count)d templates.",
|
||||
count)
|
||||
|
|
@ -141,18 +147,19 @@ class TemplateAdmin(TemplateModelAdmin):
|
|||
for template in queryset:
|
||||
valid, error = check_template_syntax(template)
|
||||
if not valid:
|
||||
errors.append('%s: %s' % (template.name, error))
|
||||
errors.append(f'{template.name}: {error}')
|
||||
if errors:
|
||||
count = len(errors)
|
||||
message = ungettext(
|
||||
message = ngettext(
|
||||
"Template syntax check FAILED for %(names)s.",
|
||||
"Template syntax check FAILED for %(count)d templates: %(names)s.",
|
||||
"Template syntax check FAILED for "
|
||||
"%(count)d templates: %(names)s.",
|
||||
count)
|
||||
self.message_user(request, message %
|
||||
{'count': count, 'names': ', '.join(errors)})
|
||||
else:
|
||||
count = queryset.count()
|
||||
message = ungettext(
|
||||
message = ngettext(
|
||||
"Template syntax OK.",
|
||||
"Template syntax OK for %(count)d templates.", count)
|
||||
self.message_user(request, message % {'count': count})
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
from django.apps import AppConfig
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
class DBTemplatesConfig(AppConfig):
|
||||
name = 'dbtemplates'
|
||||
verbose_name = _('Database templates')
|
||||
|
||||
default_auto_field = 'django.db.models.AutoField'
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import posixpath
|
|||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.conf import settings
|
||||
from django.utils.six import string_types
|
||||
|
||||
from appconf import AppConf
|
||||
|
||||
|
|
@ -10,6 +9,7 @@ from appconf import AppConf
|
|||
class DbTemplatesConf(AppConf):
|
||||
USE_CODEMIRROR = False
|
||||
USE_REVERSION = False
|
||||
USE_REVERSION_COMPARE = False
|
||||
USE_TINYMCE = False
|
||||
USE_REDACTOR = False
|
||||
ADD_DEFAULT_SITE = True
|
||||
|
|
@ -32,7 +32,7 @@ class DbTemplatesConf(AppConf):
|
|||
return "dbtemplates"
|
||||
else:
|
||||
return "default"
|
||||
if isinstance(value, string_types) and value.startswith("dbtemplates."):
|
||||
if isinstance(value, str) and value.startswith("dbtemplates."):
|
||||
raise ImproperlyConfigured("Please upgrade to one of the "
|
||||
"supported backends as defined "
|
||||
"in the Django docs.")
|
||||
|
|
@ -45,6 +45,13 @@ class DbTemplatesConf(AppConf):
|
|||
"use of it in dbtemplates.")
|
||||
return value
|
||||
|
||||
def configure_use_reversion_compare(self, value):
|
||||
if value and 'reversion_compare' not in settings.INSTALLED_APPS:
|
||||
raise ImproperlyConfigured("Please add 'reversion_compare' 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 "
|
||||
|
|
|
|||
|
|
@ -30,10 +30,11 @@ class Loader(BaseLoader):
|
|||
content, _ = self._load_template_source(origin.template_name)
|
||||
return content
|
||||
|
||||
def _load_and_store_template(self, template_name, cache_key, site, **params):
|
||||
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)
|
||||
display_name = f'dbtemplates:{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):
|
||||
|
|
@ -73,11 +74,11 @@ class Loader(BaseLoader):
|
|||
|
||||
try:
|
||||
return self._load_and_store_template(template_name, cache_key,
|
||||
site, sites__in=[site.id])
|
||||
site, sites__in=[site.id])
|
||||
except (Template.MultipleObjectsReturned, Template.DoesNotExist):
|
||||
try:
|
||||
return self._load_and_store_template(template_name, cache_key,
|
||||
site, sites__isnull=True)
|
||||
site, sites__isnull=True)
|
||||
except (Template.MultipleObjectsReturned, Template.DoesNotExist):
|
||||
pass
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class Command(BaseCommand):
|
|||
for template in Template.objects.all():
|
||||
valid, error = check_template_syntax(template)
|
||||
if not valid:
|
||||
errors.append('%s: %s' % (template.name, error))
|
||||
errors.append(f'{template.name}: {error}')
|
||||
if errors:
|
||||
raise CommandError(
|
||||
'Some templates contained errors\n%s' % '\n'.join(errors))
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class Command(BaseCommand):
|
|||
verbosity = int(options.get('verbosity', 1))
|
||||
for error_code in (404, 500):
|
||||
template, created = Template.objects.get_or_create(
|
||||
name="%s.html" % error_code)
|
||||
name=f"{error_code}.html")
|
||||
if created or (not created and force):
|
||||
template.content = TEMPLATES.get(error_code, '')
|
||||
template.save()
|
||||
|
|
|
|||
|
|
@ -1,22 +1,18 @@
|
|||
import io
|
||||
import os
|
||||
from django.contrib.sites.models import Site
|
||||
from django.core.management.base import CommandError, BaseCommand
|
||||
from django.template.utils import get_app_template_dirs
|
||||
from django.template.loader import _engine_list
|
||||
try:
|
||||
from django.utils.six import input as raw_input
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
from dbtemplates.models import Template
|
||||
from django.contrib.sites.models import Site
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.template.loader import _engine_list
|
||||
from django.template.utils import get_app_template_dirs
|
||||
|
||||
ALWAYS_ASK, FILES_TO_DATABASE, DATABASE_TO_FILES = ('0', '1', '2')
|
||||
ALWAYS_ASK, FILES_TO_DATABASE, DATABASE_TO_FILES = ("0", "1", "2")
|
||||
|
||||
DIRS = []
|
||||
for engine in _engine_list():
|
||||
DIRS.extend(engine.dirs)
|
||||
app_template_dirs = get_app_template_dirs('templates')
|
||||
DIRS = tuple(DIRS)
|
||||
app_template_dirs = get_app_template_dirs("templates")
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
|
@ -24,88 +20,121 @@ class Command(BaseCommand):
|
|||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument(
|
||||
"-e", "--ext",
|
||||
dest="ext", action="store", default="html",
|
||||
"-e",
|
||||
"--ext",
|
||||
dest="ext",
|
||||
action="store",
|
||||
default="html",
|
||||
help="extension of the files you want to "
|
||||
"sync with the database [default: %default]")
|
||||
"sync with the database [default: %(default)s]",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-f", "--force",
|
||||
action="store_true", dest="force", default=False,
|
||||
help="overwrite existing database templates")
|
||||
"-f",
|
||||
"--force",
|
||||
action="store_true",
|
||||
dest="force",
|
||||
default=False,
|
||||
help="overwrite existing database templates",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-o", "--overwrite",
|
||||
action="store", dest="overwrite", default='0',
|
||||
"-o",
|
||||
"--overwrite",
|
||||
action="store",
|
||||
dest="overwrite",
|
||||
default="0",
|
||||
help="'0' - ask always, '1' - overwrite database "
|
||||
"templates from template files, '2' - overwrite "
|
||||
"template files from database templates")
|
||||
"templates from template files, '2' - overwrite "
|
||||
"template files from database templates",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-a", "--app-first",
|
||||
action="store_true", dest="app_first", default=False,
|
||||
"-a",
|
||||
"--app-first",
|
||||
action="store_true",
|
||||
dest="app_first",
|
||||
default=False,
|
||||
help="look for templates in applications "
|
||||
"directories before project templates")
|
||||
"directories before project templates",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-d", "--delete",
|
||||
action="store_true", dest="delete", default=False,
|
||||
help="Delete templates after syncing")
|
||||
"-d",
|
||||
"--delete",
|
||||
action="store_true",
|
||||
dest="delete",
|
||||
default=False,
|
||||
help="Delete templates after syncing",
|
||||
)
|
||||
|
||||
def handle(self, **options):
|
||||
extension = options.get('ext')
|
||||
force = options.get('force')
|
||||
overwrite = options.get('overwrite')
|
||||
app_first = options.get('app_first')
|
||||
delete = options.get('delete')
|
||||
extension = options.get("ext")
|
||||
force = options.get("force")
|
||||
overwrite = options.get("overwrite")
|
||||
app_first = options.get("app_first")
|
||||
delete = options.get("delete")
|
||||
|
||||
if not extension.startswith("."):
|
||||
extension = ".%s" % extension
|
||||
extension = f".{extension}"
|
||||
|
||||
try:
|
||||
site = Site.objects.get_current()
|
||||
except Exception:
|
||||
raise CommandError("Please make sure to have the sites contrib "
|
||||
"app installed and setup with a site object")
|
||||
raise CommandError(
|
||||
"Please make sure to have the sites contrib "
|
||||
"app installed and setup with a site object"
|
||||
)
|
||||
|
||||
if app_first:
|
||||
tpl_dirs = app_template_dirs + DIRS
|
||||
else:
|
||||
tpl_dirs = DIRS + app_template_dirs
|
||||
templatedirs = [d for d in tpl_dirs if os.path.isdir(d)]
|
||||
templatedirs = [str(d) for d in tpl_dirs if os.path.isdir(d)]
|
||||
|
||||
for templatedir in templatedirs:
|
||||
for dirpath, subdirs, filenames in os.walk(templatedir):
|
||||
for f in [f for f in filenames
|
||||
if f.endswith(extension) and not f.startswith(".")]:
|
||||
for f in [
|
||||
f
|
||||
for f in filenames
|
||||
if f.endswith(extension) and not f.startswith(".")
|
||||
]:
|
||||
path = os.path.join(dirpath, f)
|
||||
name = path.split(templatedir)[1]
|
||||
if name.startswith('/'):
|
||||
name = path.split(str(templatedir))[1]
|
||||
if name.startswith("/"):
|
||||
name = name[1:]
|
||||
try:
|
||||
t = Template.on_site.get(name__exact=name)
|
||||
except Template.DoesNotExist:
|
||||
if not force:
|
||||
confirm = raw_input(
|
||||
confirm = input(
|
||||
"\nA '%s' template doesn't exist in the "
|
||||
"database.\nCreate it with '%s'?"
|
||||
" (y/[n]): """ % (name, path))
|
||||
if force or confirm.lower().startswith('y'):
|
||||
with io.open(path, encoding='utf-8') as f:
|
||||
" (y/[n]): "
|
||||
"" % (name, path)
|
||||
)
|
||||
if force or confirm.lower().startswith("y"):
|
||||
with open(path, encoding="utf-8") as f:
|
||||
t = Template(name=name, content=f.read())
|
||||
t.save()
|
||||
t.sites.add(site)
|
||||
else:
|
||||
while 1:
|
||||
while True:
|
||||
if overwrite == ALWAYS_ASK:
|
||||
confirm = raw_input(
|
||||
_i = (
|
||||
"\n%(template)s exists in the database.\n"
|
||||
"(1) Overwrite %(template)s with '%(path)s'\n"
|
||||
"(2) Overwrite '%(path)s' with %(template)s\n"
|
||||
"Type 1 or 2 or press <Enter> to skip: " %
|
||||
{'template': t.__repr__(), 'path': path})
|
||||
"(1) Overwrite %(template)s with '%(path)s'\n" # noqa
|
||||
"(2) Overwrite '%(path)s' with %(template)s\n" # noqa
|
||||
"Type 1 or 2 or press <Enter> to skip: "
|
||||
% {"template": t.__repr__(), "path": path}
|
||||
)
|
||||
|
||||
confirm = input(_i)
|
||||
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:
|
||||
with io.open(path, encoding='utf-8') as f:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
t.content = f.read()
|
||||
t.save()
|
||||
t.sites.add(site)
|
||||
|
|
@ -114,9 +143,10 @@ class Command(BaseCommand):
|
|||
os.remove(path)
|
||||
except OSError:
|
||||
raise CommandError(
|
||||
u"Couldn't delete %s" % path)
|
||||
f"Couldn't delete {path}"
|
||||
)
|
||||
elif confirm == DATABASE_TO_FILES:
|
||||
with io.open(path, 'w', encoding='utf-8') as f:
|
||||
with open(path, "w", encoding="utf-8") as f: # noqa
|
||||
f.write(t.content)
|
||||
if delete:
|
||||
t.delete()
|
||||
|
|
|
|||
|
|
@ -1,44 +1,73 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import django
|
||||
from django.db import models, migrations
|
||||
import django.utils.timezone
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('sites', '0001_initial'),
|
||||
("sites", "0001_initial"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Template',
|
||||
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)),
|
||||
(
|
||||
"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),
|
||||
), # noqa
|
||||
(
|
||||
"creation_date",
|
||||
models.DateTimeField(
|
||||
default=django.utils.timezone.now,
|
||||
verbose_name="creation date", # noqa
|
||||
),
|
||||
),
|
||||
(
|
||||
"last_changed",
|
||||
models.DateTimeField(
|
||||
default=django.utils.timezone.now,
|
||||
verbose_name="last changed", # noqa
|
||||
),
|
||||
),
|
||||
(
|
||||
"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',
|
||||
"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')),
|
||||
("objects", django.db.models.manager.Manager()),
|
||||
(
|
||||
"on_site",
|
||||
django.contrib.sites.managers.CurrentSiteManager("sites"),
|
||||
), # noqa
|
||||
],
|
||||
),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 5.1 on 2025-05-26 19:59
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('dbtemplates', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='template',
|
||||
name='creation_date',
|
||||
field=models.DateTimeField(auto_now_add=True, verbose_name='creation date'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='template',
|
||||
name='last_changed',
|
||||
field=models.DateTimeField(auto_now=True, verbose_name='last changed'),
|
||||
),
|
||||
]
|
||||
|
|
@ -1,15 +1,16 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from dbtemplates.conf import settings
|
||||
from dbtemplates.utils.cache import (add_template_to_cache,
|
||||
remove_cached_template)
|
||||
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.utils.timezone import now
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
class Template(models.Model):
|
||||
|
|
@ -17,15 +18,15 @@ class Template(models.Model):
|
|||
Defines a template model for use with the database template loader.
|
||||
The field ``name`` is the equivalent to the filename of a static template.
|
||||
"""
|
||||
id = models.AutoField(primary_key=True, verbose_name=_('ID'),
|
||||
serialize=False, auto_created=True)
|
||||
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=_(u'sites'),
|
||||
sites = models.ManyToManyField(Site, verbose_name=_('sites'),
|
||||
blank=True)
|
||||
creation_date = models.DateTimeField(_('creation date'),
|
||||
default=now)
|
||||
last_changed = models.DateTimeField(_('last changed'),
|
||||
default=now)
|
||||
creation_date = models.DateTimeField(_('creation date'), auto_now_add=True)
|
||||
last_changed = models.DateTimeField(_('last changed'), auto_now=True)
|
||||
|
||||
objects = models.Manager()
|
||||
on_site = CurrentSiteManager('sites')
|
||||
|
|
@ -36,7 +37,7 @@ class Template(models.Model):
|
|||
verbose_name_plural = _('templates')
|
||||
ordering = ('name',)
|
||||
|
||||
def __unicode__(self):
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def populate(self, name=None):
|
||||
|
|
@ -54,12 +55,11 @@ class Template(models.Model):
|
|||
pass
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
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:
|
||||
self.populate()
|
||||
super(Template, self).save(*args, **kwargs)
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
|
||||
def add_default_site(instance, **kwargs):
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import io
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
from unittest import mock
|
||||
|
||||
from django.conf import settings as django_settings
|
||||
from django.core.cache.backends.base import BaseCache
|
||||
|
|
@ -22,11 +22,12 @@ from dbtemplates.management.commands.sync_templates import (FILES_TO_DATABASE,
|
|||
|
||||
class DbTemplatesTestCase(TestCase):
|
||||
def setUp(self):
|
||||
self.old_template_loaders = settings.TEMPLATE_LOADERS
|
||||
if 'dbtemplates.loader.Loader' not in settings.TEMPLATE_LOADERS:
|
||||
self.old_TEMPLATES = settings.TEMPLATES
|
||||
if 'dbtemplates.loader.Loader' not in settings.TEMPLATES:
|
||||
loader.template_source_loaders = None
|
||||
settings.TEMPLATE_LOADERS = (list(settings.TEMPLATE_LOADERS) +
|
||||
['dbtemplates.loader.Loader'])
|
||||
settings.TEMPLATES = list(settings.TEMPLATES) + [
|
||||
'dbtemplates.loader.Loader'
|
||||
]
|
||||
|
||||
self.site1, created1 = Site.objects.get_or_create(
|
||||
domain="example.com", name="example.com")
|
||||
|
|
@ -40,7 +41,7 @@ class DbTemplatesTestCase(TestCase):
|
|||
|
||||
def tearDown(self):
|
||||
loader.template_source_loaders = None
|
||||
settings.TEMPLATE_LOADERS = self.old_template_loaders
|
||||
settings.TEMPLATES = self.old_TEMPLATES
|
||||
|
||||
def test_basics(self):
|
||||
self.assertEqual(list(self.t1.sites.all()), [self.site1])
|
||||
|
|
@ -102,9 +103,9 @@ class DbTemplatesTestCase(TestCase):
|
|||
old_template_dirs = settings.TEMPLATES[0].get('DIRS', [])
|
||||
temp_template_dir = tempfile.mkdtemp('dbtemplates')
|
||||
temp_template_path = os.path.join(temp_template_dir, 'temp_test.html')
|
||||
temp_template = io.open(temp_template_path, 'w', encoding='utf-8')
|
||||
temp_template = open(temp_template_path, 'w', encoding='utf-8')
|
||||
try:
|
||||
temp_template.write(u'temp test')
|
||||
temp_template.write('temp test')
|
||||
settings.TEMPLATES[0]['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
|
||||
|
|
@ -119,13 +120,13 @@ class DbTemplatesTestCase(TestCase):
|
|||
Template.objects.filter(name='temp_test.html').exists())
|
||||
|
||||
t = Template.objects.get(name='temp_test.html')
|
||||
t.content = u'temp test modified'
|
||||
t.content = 'temp test modified'
|
||||
t.save()
|
||||
call_command('sync_templates', force=True,
|
||||
verbosity=0, overwrite=DATABASE_TO_FILES)
|
||||
self.assertEqual(u'temp test modified',
|
||||
io.open(temp_template_path,
|
||||
encoding='utf-8').read())
|
||||
self.assertEqual('temp test modified',
|
||||
open(temp_template_path,
|
||||
encoding='utf-8').read())
|
||||
|
||||
call_command('sync_templates', force=True, verbosity=0,
|
||||
delete=True, overwrite=DATABASE_TO_FILES)
|
||||
|
|
@ -151,3 +152,24 @@ class DbTemplatesTestCase(TestCase):
|
|||
def test_get_cache_name(self):
|
||||
self.assertEqual(get_cache_key('name with spaces'),
|
||||
'dbtemplates::name-with-spaces::1')
|
||||
|
||||
def test_cache_invalidation(self):
|
||||
# Add t1 into the cache of site2
|
||||
self.t1.sites.add(self.site2)
|
||||
with mock.patch('django.contrib.sites.models.SiteManager.get_current',
|
||||
return_value=self.site2):
|
||||
result = loader.get_template("base.html").render()
|
||||
self.assertEqual(result, 'base')
|
||||
|
||||
# Update content
|
||||
self.t1.content = 'new content'
|
||||
self.t1.save()
|
||||
result = loader.get_template("base.html").render()
|
||||
self.assertEqual(result, 'new content')
|
||||
|
||||
# Cache invalidation should work across sites.
|
||||
# Site2 should see the new content.
|
||||
with mock.patch('django.contrib.sites.models.SiteManager.get_current',
|
||||
return_value=self.site2):
|
||||
result = loader.get_template("base.html").render()
|
||||
self.assertEqual(result, 'new content')
|
||||
|
|
|
|||
|
|
@ -18,12 +18,15 @@ DATABASES = {
|
|||
INSTALLED_APPS = [
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sites',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'dbtemplates',
|
||||
]
|
||||
|
||||
MIDDLEWARE_CLASSES = (
|
||||
MIDDLEWARE = (
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
)
|
||||
|
|
@ -41,6 +44,7 @@ TEMPLATES = [
|
|||
'loaders': TEMPLATE_LOADERS,
|
||||
'context_processors': [
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
from django.core import signals
|
||||
from django.contrib.sites.models import Site
|
||||
from django.template.defaultfilters import slugify
|
||||
|
||||
from dbtemplates.conf import settings
|
||||
from django.contrib.sites.models import Site
|
||||
from django.core import signals
|
||||
from django.template.defaultfilters import slugify
|
||||
|
||||
|
||||
def get_cache_backend():
|
||||
"""
|
||||
Compatibilty wrapper for getting Django's cache backend instance
|
||||
"""
|
||||
from django.core.cache import _create_cache
|
||||
cache = _create_cache(settings.DBTEMPLATES_CACHE_BACKEND)
|
||||
from django.core.cache import caches
|
||||
cache = caches.create_connection(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
|
||||
|
|
@ -21,13 +21,14 @@ def get_cache_backend():
|
|||
cache = get_cache_backend()
|
||||
|
||||
|
||||
def get_cache_key(name):
|
||||
current_site = Site.objects.get_current()
|
||||
return 'dbtemplates::%s::%s' % (slugify(name), current_site.pk)
|
||||
def get_cache_key(name, site=None):
|
||||
if site is None:
|
||||
site = Site.objects.get_current()
|
||||
return f"dbtemplates::{slugify(name)}::{site.pk}"
|
||||
|
||||
|
||||
def get_cache_notfound_key(name):
|
||||
return get_cache_key(name) + '::notfound'
|
||||
return get_cache_key(name) + "::notfound"
|
||||
|
||||
|
||||
def remove_notfound_key(instance):
|
||||
|
|
@ -57,4 +58,5 @@ def remove_cached_template(instance, **kwargs):
|
|||
Called via Django's signals to remove cached templates, if the template
|
||||
in the database was changed or deleted.
|
||||
"""
|
||||
cache.delete(get_cache_key(instance.name))
|
||||
for site in instance.sites.all():
|
||||
cache.delete(get_cache_key(instance.name, site=site))
|
||||
|
|
|
|||
|
|
@ -61,8 +61,17 @@ Short installation howto
|
|||
3. Sync your database with ``python manage.py syncdb``
|
||||
4. Set ``DBTEMPLATES_USE_REVERSION`` setting to ``True``
|
||||
|
||||
History compare view
|
||||
--------------------
|
||||
|
||||
You can also use ``dbtemplates`` together with `django-reversion-compare`_ which
|
||||
provides a history compare view to compare two versions of a model which is under
|
||||
reversion.
|
||||
|
||||
.. _django-reversion: https://github.com/etianen/django-reversion
|
||||
.. _django-reversion's documentation: https://django-reversion.readthedocs.io/en/latest/
|
||||
.. _django-reversion-compare: https://github.com/jedie/django-reversion-compare
|
||||
|
||||
|
||||
.. _commands:
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,57 @@
|
|||
Changelog
|
||||
=========
|
||||
|
||||
v5.0 (unreleased)
|
||||
-----------------
|
||||
|
||||
.. warning::
|
||||
|
||||
This is a backwards-incompatible release!
|
||||
|
||||
* Dropped support for Python 3.7 and Django < 4.2.
|
||||
|
||||
* Added support for Python 3.11, 3.12, 3.13.
|
||||
|
||||
* Django 5.x support
|
||||
|
||||
v4.0 (2022-09-3)
|
||||
-----------------
|
||||
|
||||
.. warning::
|
||||
|
||||
This is a backwards-incompatible release!
|
||||
|
||||
* Dropped support for Python 2.7 and Django < 3.2.
|
||||
|
||||
* Added support for Python 3.8, 3.9, 3.10.
|
||||
|
||||
* Moved test runner to GitHub Actions:
|
||||
|
||||
http://github.com/jazzband/django-dbtemplates/actions
|
||||
|
||||
* Django 4.x support
|
||||
|
||||
v3.0 (2019-01-27)
|
||||
-----------------
|
||||
|
||||
.. warning::
|
||||
|
||||
This is a backwards-incompatible release!
|
||||
|
||||
* Dropped support for Django < 1.11.
|
||||
|
||||
* Added support for Django 2.0 and 2.1.
|
||||
|
||||
* Added support for Python 3.7.
|
||||
|
||||
* Recompiled Russian locale.
|
||||
|
||||
* Fixed byte string in migration file that caused the migration
|
||||
system to falsely think that there are new changes.
|
||||
|
||||
* Fixed string representation of template model, e.g. to improve
|
||||
readability in choice fields.
|
||||
|
||||
v2.0 (2016-09-29)
|
||||
-----------------
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# django-dbtemplates documentation build configuration file, created by
|
||||
# sphinx-quickstart on Fri Oct 9 14:52:11 2009.
|
||||
|
|
@ -37,8 +36,8 @@ source_suffix = '.txt'
|
|||
master_doc = 'index'
|
||||
|
||||
# General information about the project.
|
||||
project = u'django-dbtemplates'
|
||||
copyright = u'2007-2012, Jannis Leidel and contributors'
|
||||
project = 'django-dbtemplates'
|
||||
copyright = '2007-2019, 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
|
||||
|
|
@ -177,8 +176,8 @@ htmlhelp_basename = 'django-dbtemplatesdoc'
|
|||
# Grouping the document tree into LaTeX files. List of tuples
|
||||
# (source start file, target name, title, author, documentclass [howto/manual]).
|
||||
latex_documents = [
|
||||
('index', 'django-dbtemplates.tex', u'django-dbtemplates Documentation',
|
||||
u'Jannis Leidel and contributors', 'manual'),
|
||||
('index', 'django-dbtemplates.tex', 'django-dbtemplates Documentation',
|
||||
'Jannis Leidel and contributors', 'manual'),
|
||||
]
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top of
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@ Setup
|
|||
|
||||
1. Get the source from the `Git repository`_ or install it from the
|
||||
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:
|
||||
2. Edit the settings.py of your Django site:
|
||||
|
||||
* Add ``dbtemplates`` to the ``INSTALLED_APPS`` setting
|
||||
|
||||
|
|
@ -61,8 +60,8 @@ Setup
|
|||
from the database to be used to override templates in other locations,
|
||||
put ``dbtemplates.loader.Loader`` at the beginning of ``loaders``.
|
||||
|
||||
4. Sync your database ``python manage.py migrate``
|
||||
5. Restart your Django server
|
||||
3. Sync your database ``python manage.py migrate``
|
||||
4. Restart your Django server
|
||||
|
||||
.. _Git repository: https://github.com/jazzband/django-dbtemplates/
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,11 @@ Set to ``False`` by default.
|
|||
|
||||
A boolean, if enabled triggers the use of ``django-reversion``.
|
||||
|
||||
``DBTEMPLATES_USE_REVERSION_COMPARE``
|
||||
-----------------------------
|
||||
|
||||
A boolean, if enabled triggers the use of ``django-reversion-compare``.
|
||||
|
||||
``DBTEMPLATES_MEDIA_PREFIX``
|
||||
----------------------------
|
||||
|
||||
|
|
|
|||
51
pyproject.toml
Normal file
51
pyproject.toml
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
[build-system]
|
||||
requires = [
|
||||
"setuptools>=61.2",
|
||||
"setuptools_scm",
|
||||
]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "django-dbtemplates"
|
||||
authors = [{name = "Jannis Leidel", email = "jannis@leidel.info"}]
|
||||
description = "Template loader for templates stored in the database"
|
||||
readme = "README.rst"
|
||||
classifiers = [
|
||||
"Development Status :: 5 - Production/Stable",
|
||||
"Environment :: Web Environment",
|
||||
"Intended Audience :: Developers",
|
||||
"License :: OSI Approved :: BSD License",
|
||||
"Operating System :: OS Independent",
|
||||
"Programming Language :: Python",
|
||||
"Programming Language :: Python :: 3",
|
||||
"Programming Language :: Python :: 3 :: Only",
|
||||
"Programming Language :: Python :: 3.8",
|
||||
"Programming Language :: Python :: 3.9",
|
||||
"Programming Language :: Python :: 3.10",
|
||||
"Programming Language :: Python :: 3.11",
|
||||
"Programming Language :: Python :: 3.12",
|
||||
"Programming Language :: Python :: 3.13",
|
||||
"Framework :: Django",
|
||||
]
|
||||
requires-python = ">=3.8"
|
||||
dependencies = ["django-appconf >= 0.4"]
|
||||
dynamic = ["version"]
|
||||
|
||||
[project.urls]
|
||||
Documentation = "https://django-dbtemplates.readthedocs.io/"
|
||||
Changelog = "https://django-dbtemplates.readthedocs.io/en/latest/changelog.html"
|
||||
Source = "https://github.com/jazzband/django-dbtemplates"
|
||||
|
||||
[tool.setuptools]
|
||||
zip-safe = false
|
||||
include-package-data = false
|
||||
|
||||
[tool.setuptools.packages]
|
||||
find = {namespaces = false}
|
||||
|
||||
[tool.setuptools.package-data]
|
||||
dbtemplates = [
|
||||
"locale/*/LC_MESSAGES/*",
|
||||
"static/dbtemplates/css/*.css",
|
||||
"static/dbtemplates/js/*.js",
|
||||
]
|
||||
1
requirements/docs.txt
Normal file
1
requirements/docs.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
django
|
||||
13
setup.cfg
13
setup.cfg
|
|
@ -1,13 +0,0 @@
|
|||
[egg_info]
|
||||
#tag_build = a1
|
||||
|
||||
[build_sphinx]
|
||||
source-dir = docs/
|
||||
build-dir = docs/_build
|
||||
all_files = 1
|
||||
|
||||
[upload_docs]
|
||||
upload-dir = docs/_build/html
|
||||
|
||||
[upload_sphinx]
|
||||
upload-dir = docs/_build/html
|
||||
60
setup.py
60
setup.py
|
|
@ -1,60 +0,0 @@
|
|||
import ast
|
||||
import os
|
||||
import io
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
|
||||
class VersionFinder(ast.NodeVisitor):
|
||||
def __init__(self):
|
||||
self.version = None
|
||||
|
||||
def visit_Assign(self, node):
|
||||
if node.targets[0].id == '__version__':
|
||||
self.version = node.value.s
|
||||
|
||||
|
||||
def read(*parts):
|
||||
filename = os.path.join(os.path.dirname(__file__), *parts)
|
||||
with io.open(filename, encoding='utf-8') as fp:
|
||||
return fp.read()
|
||||
|
||||
|
||||
def find_version(*parts):
|
||||
finder = VersionFinder()
|
||||
finder.visit(ast.parse(read(*parts)))
|
||||
return finder.version
|
||||
|
||||
|
||||
setup(
|
||||
name='django-dbtemplates',
|
||||
version=find_version('dbtemplates', '__init__.py'),
|
||||
description='Template loader for templates stored in the database',
|
||||
long_description=read('README.rst'),
|
||||
author='Jannis Leidel',
|
||||
author_email='jannis@leidel.info',
|
||||
url='https://django-dbtemplates.readthedocs.io/',
|
||||
packages=find_packages(),
|
||||
zip_safe=False,
|
||||
package_data={
|
||||
'dbtemplates': [
|
||||
'locale/*/LC_MESSAGES/*',
|
||||
'static/dbtemplates/css/*.css',
|
||||
'static/dbtemplates/js/*.js',
|
||||
],
|
||||
},
|
||||
classifiers=[
|
||||
'Development Status :: 5 - Production/Stable',
|
||||
'Environment :: Web Environment',
|
||||
'Intended Audience :: Developers',
|
||||
'License :: OSI Approved :: BSD License',
|
||||
'Operating System :: OS Independent',
|
||||
'Programming Language :: Python',
|
||||
'Programming Language :: Python :: 2',
|
||||
'Programming Language :: Python :: 2.7',
|
||||
'Programming Language :: Python :: 3',
|
||||
'Programming Language :: Python :: 3.4',
|
||||
'Programming Language :: Python :: 3.5',
|
||||
'Framework :: Django',
|
||||
],
|
||||
install_requires=['django-appconf >= 0.4'],
|
||||
)
|
||||
75
tox.ini
75
tox.ini
|
|
@ -1,51 +1,58 @@
|
|||
[tox]
|
||||
skipsdist = True
|
||||
usedevelop = True
|
||||
minversion = 1.8
|
||||
minversion = 4.0
|
||||
envlist =
|
||||
flake8-py27,
|
||||
flake8-py37,
|
||||
readme-py27,
|
||||
readme-py37,
|
||||
py{27,34,35,36}-dj111
|
||||
py{34,35,36,37}-dj20
|
||||
py{34,35,36,37}-dj21
|
||||
flake8
|
||||
py3{8,9,10,11,12}-dj42
|
||||
py3{10,11,12}-dj{50}
|
||||
py3{10,11,12,13}-dj{51,52}
|
||||
py3{12,13}-dj{main}
|
||||
coverage
|
||||
|
||||
[gh-actions]
|
||||
python =
|
||||
3.8: py38
|
||||
3.9: py39
|
||||
3.10: py310
|
||||
3.10: py310, flake8
|
||||
3.11: py311
|
||||
3.12: py312
|
||||
3.13: py313
|
||||
|
||||
[testenv]
|
||||
skipsdist = true
|
||||
package = editable
|
||||
basepython =
|
||||
py27: python2.7
|
||||
py34: python3.4
|
||||
py35: python3.5
|
||||
py36: python3.6
|
||||
py37: python3.7
|
||||
usedevelop = true
|
||||
py38: python3.8
|
||||
py39: python3.9
|
||||
py310: python3.10
|
||||
py311: python3.11
|
||||
py312: python3.12
|
||||
py313: python3.13
|
||||
setenv =
|
||||
DJANGO_SETTINGS_MODULE = dbtemplates.test_settings
|
||||
deps =
|
||||
-r requirements/tests.txt
|
||||
dj111: Django<2.0
|
||||
dj20: Django<2.1
|
||||
dj21: Django<2.2
|
||||
djmaster: https://github.com/django/django/archive/master.tar.gz#egg=django
|
||||
dj42: Django>=4.2,<4.3
|
||||
dj50: Django>=5.0,<5.1
|
||||
dj51: Django>=5.1,<5.2
|
||||
dj52: Django>=5.2,<5.3
|
||||
djmain: https://github.com/django/django/archive/main.tar.gz#egg=django
|
||||
|
||||
commands =
|
||||
python --version
|
||||
coverage run {envbindir}/django-admin.py test -v2 {posargs:dbtemplates}
|
||||
python -c "import django ; print(django.VERSION)"
|
||||
coverage run --branch --parallel-mode {envbindir}/django-admin test -v2 {posargs:dbtemplates}
|
||||
|
||||
[testenv:coverage]
|
||||
basepython = python3.10
|
||||
deps = coverage
|
||||
commands =
|
||||
coverage combine
|
||||
coverage report
|
||||
coverage xml
|
||||
|
||||
[testenv:readme-py27]
|
||||
commands = python setup.py check -r -s
|
||||
deps = readme_renderer
|
||||
|
||||
[testenv:readme-py37]
|
||||
commands = python setup.py check -r -s
|
||||
deps = readme_renderer
|
||||
|
||||
[testenv:flake8-py27]
|
||||
commands = flake8 dbtemplates
|
||||
deps = flake8
|
||||
|
||||
[testenv:flake8-py37]
|
||||
[testenv:flake8]
|
||||
basepython = python3.10
|
||||
commands = flake8 dbtemplates
|
||||
deps = flake8
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue