Merge branch 'release/1.2'

This commit is contained in:
Jannis Leidel 2011-08-15 13:24:51 +02:00
commit 4fb0219dd4
31 changed files with 523 additions and 197 deletions

14
AUTHORS Normal file
View file

@ -0,0 +1,14 @@
Alen Mujezinovic
Alex Gaynor
Alex Kamedov
Alexander Artemenko
Arne Brodowski
David Paccoud
Diego Búrigo Zacarão
Jannis Leidel
Jason Mayfield
Kevin Mooney
Matt Dorn
Oliver George
Stephan Peijnik <spe@anexia.at>, ANEXIA Internetdienstleistungs GmbH, http://www.anexia.at/
Zhang Kun

View file

@ -1,5 +1,6 @@
include INSTALL
include LICENSE
include AUTHORS
include README.rst
include MANIFEST.in
recursive-include docs *.txt

View file

@ -1,4 +1,4 @@
VERSION = (1, 1, 1, "f", 0) # following PEP 386
VERSION = (1, 2, 0, "f", 0) # following PEP 386
DEV_N = None

View file

@ -7,6 +7,7 @@ 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.utils.template import check_template_syntax
# Check if django-reversion is installed and use reversions' VersionAdmin
# as the base admin class if yes
@ -91,30 +92,54 @@ class TemplateAdmin(TemplateModelAdmin):
list_filter = ('sites',)
save_as = True
search_fields = ('name', 'content')
actions = ['invalidate_cache', 'repopulate_cache']
actions = ['invalidate_cache', 'repopulate_cache', 'check_syntax']
def invalidate_cache(self, request, queryset):
for template in queryset:
remove_cached_template(template)
count = queryset.count()
message = ungettext(
"Cache of one template successfully invalidated.",
"Cache of %(count)d templates successfully invalidated.",
len(queryset))
self.message_user(request, message % {'count': len(queryset)})
count)
self.message_user(request, message % {'count': count})
invalidate_cache.short_description = _("Invalidate cache of "
"selected templates")
def repopulate_cache(self, request, queryset):
for template in queryset:
add_template_to_cache(template)
count = queryset.count()
message = ungettext(
"Cache successfully repopulated with one template.",
"Cache successfully repopulated with %(count)d templates.",
len(queryset))
self.message_user(request, message % {'count': len(queryset)})
count)
self.message_user(request, message % {'count': count})
repopulate_cache.short_description = _("Repopulate cache with "
"selected templates")
def check_syntax(self, request, queryset):
errors = []
for template in queryset:
valid, error = check_template_syntax(template)
if not valid:
errors.append('%s: %s' % (template.name, error))
if errors:
count = len(errors)
message = ungettext(
"Template syntax check FAILED for %(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(
"Template syntax OK.",
"Template syntax OK for %(count)d templates.", count)
self.message_user(request, message % {'count': count})
check_syntax.short_description = _("Check template syntax")
def site_list(self, template):
return ", ".join([site.name for site in template.sites.all()])
site_list.short_description = _('sites')

View file

@ -3,7 +3,8 @@ 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
from dbtemplates.utils.cache import (cache, get_cache_key,
set_and_return, get_cache_notfound_key)
from django.template.loader import BaseLoader
@ -19,6 +20,18 @@ class Loader(BaseLoader):
is_usable = True
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.
# * Now check the cache if a lookup for the given template
# has failed lately and hand over control to the next template
# loader waiting in line.
# * If this still did not fail we first try to find a site-specific
# template in the database.
# * On a failure from our last attempt we try to load the global
# template from the database.
# * If all of the above steps have failed we generate a new key
# 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)
@ -30,15 +43,30 @@ class Loader(BaseLoader):
return backend_template, template_name
except:
pass
# Not found in cache, move on.
cache_notfound_key = get_cache_notfound_key(template_name)
if cache:
try:
notfound = cache.get(cache_notfound_key)
if notfound:
raise TemplateDoesNotExist(template_name)
except:
raise TemplateDoesNotExist(template_name)
# Not marked as not-found, move on...
try:
template = Template.objects.get(name__exact=template_name)
template = Template.objects.get(name__exact=template_name,
sites__in=[site.id])
return set_and_return(cache_key, template.content, display_name)
except (Template.MultipleObjectsReturned, Template.DoesNotExist):
try:
template = Template.objects.get(
name__exact=template_name, sites__in=[site.id])
return set_and_return(
cache_key, template.content, display_name)
template = Template.objects.get(name__exact=template_name)
return set_and_return(cache_key, template.content, display_name)
except Template.DoesNotExist:
pass
# Mark as not-found in cache.
cache.set(cache_notfound_key, '1')
raise TemplateDoesNotExist(template_name)

View file

@ -1,15 +1,14 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# Michael Lind Mortensen <illio@cs.au.dk>, 2009.
#
#
msgid ""
msgstr ""
"Project-Id-Version: django-dbtemplates\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2009-10-09 13:45+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Report-Msgid-Bugs-To: https://github.com/jezdez/django-dbtemplates/issues\n"
"POT-Creation-Date: 2011-08-15 13:13+0200\n"
"PO-Revision-Date: 2011-08-15 11:14+0000\n"
"Last-Translator: Jannis <jannis@leidel.info>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@ -17,72 +16,93 @@ msgstr ""
"Language: da\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
#: admin.py:53
#: admin.py:56
msgid ""
"Leaving this empty causes Django to look for a template with the given name "
"and populate this field with its content."
msgstr ""
"Hvis du efterlader dette felt tomt, så vil Django søge efter en template med "
"det givne navn og udfylde dette felt med dets indhold."
"Hvis du efterlader dette felt tomt, så vil Django søge efter en template med"
" det givne navn og udfylde dette felt med dets indhold."
#: admin.py:77
#: admin.py:82
msgid "Advanced"
msgstr ""
#: admin.py:80
#: admin.py:85
msgid "Date/time"
msgstr "Dato/tid"
#: admin.py:98
#: admin.py:102
#, python-format
msgid "Cache of one template successfully invalidated."
msgid_plural "Cache of %(count)d templates successfully invalidated."
msgstr[0] ""
msgstr[1] ""
#: admin.py:102
#: admin.py:106
msgid "Invalidate cache of selected templates"
msgstr ""
#: admin.py:111
#: admin.py:114
#, python-format
msgid "Cache successfully repopulated with one template."
msgid_plural "Cache successfully repopulated with %(count)d templates."
msgstr[0] ""
msgstr[1] ""
#: admin.py:115
#: admin.py:118
msgid "Repopulate cache with selected templates"
msgstr ""
#: admin.py:119 models.py:29
#: admin.py:130
#, python-format
msgid "Template syntax check FAILED for %(names)s."
msgid_plural ""
"Template syntax check FAILED for %(count)d templates: %(names)s."
msgstr[0] ""
msgstr[1] ""
#: admin.py:138
#, python-format
msgid "Template syntax OK."
msgid_plural "Template syntax OK for %(count)d templates."
msgstr[0] ""
msgstr[1] ""
#: admin.py:141
msgid "Check template syntax"
msgstr ""
#: admin.py:145 models.py:25
msgid "sites"
msgstr "websider"
#: models.py:26
#: models.py:22
msgid "name"
msgstr "navn"
#: models.py:27
#: models.py:23
msgid "Example: 'flatpages/default.html'"
msgstr "Eksempel: 'flatpages/default.html'"
#: models.py:28
#: models.py:24
msgid "content"
msgstr "indhold"
#: models.py:30
#: models.py:27
msgid "creation date"
msgstr "oprettelsesdato"
#: models.py:32
#: models.py:29
msgid "last changed"
msgstr "sidst ændret"
#: models.py:40
#: models.py:37
msgid "template"
msgstr "skabelon"
#: models.py:41
#: models.py:38
msgid "templates"
msgstr "skabeloner"

View file

@ -1,19 +1,23 @@
#
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
#
# Jannis Leidel <jannis@leidel.info>, 2011.
msgid ""
msgstr ""
"Project-Id-Version: django-dbtemplates\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2010-11-07 00:01+0100\n"
"PO-Revision-Date: 2008-08-19 17:11+0100\n"
"Last-Translator: Jannis Leidel <jannis@leidel.info>\n"
"Language-Team: Jannis Leidel <jannis@leidel.info>\n"
"Report-Msgid-Bugs-To: https://github.com/jezdez/django-dbtemplates/issues\n"
"POT-Creation-Date: 2011-08-15 13:13+0200\n"
"PO-Revision-Date: 2011-08-15 11:14+0000\n"
"Last-Translator: Jannis <jannis@leidel.info>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: de\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
#: admin.py:53
#: admin.py:56
msgid ""
"Leaving this empty causes Django to look for a template with the given name "
"and populate this field with its content."
@ -21,66 +25,86 @@ msgstr ""
"Wenn Sie dieses Feld leer lassen, wird Django versuchen, das Template mit "
"dem angegebenen Namen zu finden und mit dessen Inhalt das Feld zu füllen."
#: admin.py:77
#: admin.py:82
msgid "Advanced"
msgstr "Erweiterte Einstellungen"
#: admin.py:80
#: admin.py:85
msgid "Date/time"
msgstr "Datum/Uhrzeit"
#: admin.py:98
#: admin.py:102
#, python-format
msgid "Cache of one template successfully invalidated."
msgid_plural "Cache of %(count)d templates successfully invalidated."
msgstr[0] "Der Cache eines Templates wurde erfolgreich geleert."
msgstr[1] "Der Cache von %(count)d Templates wurde erfolgreich geleert."
#: admin.py:102
#: admin.py:106
msgid "Invalidate cache of selected templates"
msgstr "Cache der ausgewählten Templates leeren"
#: admin.py:111
#: admin.py:114
#, python-format
msgid "Cache successfully repopulated with one template."
msgid_plural "Cache successfully repopulated with %(count)d templates."
msgstr[0] ""
"Der Cache eines Templates wurde erfolgreich geleert und neu gefüllt."
msgstr[0] "Der Cache eines Templates wurde erfolgreich geleert und neu gefüllt."
msgstr[1] ""
"Der Cache von %(count)d Templates wurde erfolgreich geleert und neu gefüllt."
#: admin.py:115
#: admin.py:118
msgid "Repopulate cache with selected templates"
msgstr "Cache der ausgewählten Templates neu füllen"
#: admin.py:119 models.py:29
#: admin.py:130
#, python-format
msgid "Template syntax check FAILED for %(names)s."
msgid_plural ""
"Template syntax check FAILED for %(count)d templates: %(names)s."
msgstr[0] "Template-Syntax von %(names)s ist FEHLERHAFT."
msgstr[1] "Template-Syntax von %(count)d Templates (%(names)s) ist FEHLERHAFT."
#: admin.py:138
#, python-format
msgid "Template syntax OK."
msgid_plural "Template syntax OK for %(count)d templates."
msgstr[0] "Template-Syntax ist OK."
msgstr[1] "Template-Syntax von %(count)d Templates ist OK."
#: admin.py:141
msgid "Check template syntax"
msgstr "Template-Syntax überprüfen"
#: admin.py:145 models.py:25
msgid "sites"
msgstr "Seiten"
#: models.py:26
#: models.py:22
msgid "name"
msgstr "Name"
#: models.py:27
#: models.py:23
msgid "Example: 'flatpages/default.html'"
msgstr "Zum Beispiel: 'flatpages/default.html'"
#: models.py:28
#: models.py:24
msgid "content"
msgstr "Inhalt"
#: models.py:30
#: models.py:27
msgid "creation date"
msgstr "Erstellt"
#: models.py:32
#: models.py:29
msgid "last changed"
msgstr "Geändert"
#: models.py:40
#: models.py:37
msgid "template"
msgstr "Template"
#: models.py:41
#: models.py:38
msgid "templates"
msgstr "Templates"

View file

@ -8,51 +8,70 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2011-07-06 21:19+0200\n"
"POT-Creation-Date: 2011-08-15 13:13+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: admin.py:55
#: admin.py:56
msgid ""
"Leaving this empty causes Django to look for a template with the given name "
"and populate this field with its content."
msgstr ""
#: admin.py:81
#: admin.py:82
msgid "Advanced"
msgstr ""
#: admin.py:84
#: admin.py:85
msgid "Date/time"
msgstr ""
#: admin.py:100
#: admin.py:102
#, python-format
msgid "Cache of one template successfully invalidated."
msgid_plural "Cache of %(count)d templates successfully invalidated."
msgstr[0] ""
msgstr[1] ""
#: admin.py:104
#: admin.py:106
msgid "Invalidate cache of selected templates"
msgstr ""
#: admin.py:111
#: admin.py:114
#, python-format
msgid "Cache successfully repopulated with one template."
msgid_plural "Cache successfully repopulated with %(count)d templates."
msgstr[0] ""
msgstr[1] ""
#: admin.py:115
#: admin.py:118
msgid "Repopulate cache with selected templates"
msgstr ""
#: admin.py:120 models.py:25
#: admin.py:130
#, python-format
msgid "Template syntax check FAILED for %(names)s."
msgid_plural "Template syntax check FAILED for %(count)d templates: %(names)s."
msgstr[0] ""
msgstr[1] ""
#: admin.py:138
#, python-format
msgid "Template syntax OK."
msgid_plural "Template syntax OK for %(count)d templates."
msgstr[0] ""
msgstr[1] ""
#: admin.py:141
msgid "Check template syntax"
msgstr ""
#: admin.py:145 models.py:25
msgid "sites"
msgstr ""

View file

@ -7,9 +7,9 @@ msgid ""
msgstr ""
"Project-Id-Version: django-dbtemplates\n"
"Report-Msgid-Bugs-To: https://github.com/jezdez/django-dbtemplates/issues\n"
"POT-Creation-Date: 2010-11-07 00:02+0100\n"
"PO-Revision-Date: 2011-06-19 11:22+0000\n"
"Last-Translator: Uninen <ville@syneus.fi>\n"
"POT-Creation-Date: 2011-08-15 13:13+0200\n"
"PO-Revision-Date: 2011-08-15 11:14+0000\n"
"Last-Translator: Jannis <jannis@leidel.info>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@ -17,7 +17,7 @@ msgstr ""
"Language: fi\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
#: admin.py:53
#: admin.py:56
msgid ""
"Leaving this empty causes Django to look for a template with the given name "
"and populate this field with its content."
@ -25,65 +25,84 @@ msgstr ""
"Jos tämä jätetään tyhjäksi, Django etsiin annetulla nimellä olevan "
"mallipohjan ja täyttää tähän kenttään sen sisällön."
#: admin.py:77
#: admin.py:82
msgid "Advanced"
msgstr "Lisäasetukset"
#: admin.py:80
#: admin.py:85
msgid "Date/time"
msgstr "Päiväys/aika"
#: admin.py:98
#: admin.py:102
#, python-format
msgid "Cache of one template successfully invalidated."
msgid_plural "Cache of %(count)d templates successfully invalidated."
msgstr[0] "Yhden mallipohjan välimuisti on onnistuneesti tyhjennetty."
msgstr[1] "%(count)d mallipohjan välimusti on onnistuneesti tyhjennetty."
#: admin.py:102
#: admin.py:106
msgid "Invalidate cache of selected templates"
msgstr "Tyhjennä valittujen mallipohjien välimuisti."
#: admin.py:111
#: admin.py:114
#, python-format
msgid "Cache successfully repopulated with one template."
msgid_plural "Cache successfully repopulated with %(count)d templates."
msgstr[0] "Yhden mallipohjan välimuisti on täytetty onnistuneesti."
msgstr[1] "%(count)d mallipohjan välimuisti on täytetty onnistuneesti."
#: admin.py:115
#: admin.py:118
msgid "Repopulate cache with selected templates"
msgstr "Täytä valittujen mallipohjien välimuisti."
#: admin.py:119 models.py:29
#: admin.py:130
#, python-format
msgid "Template syntax check FAILED for %(names)s."
msgid_plural ""
"Template syntax check FAILED for %(count)d templates: %(names)s."
msgstr[0] ""
msgstr[1] ""
#: admin.py:138
#, python-format
msgid "Template syntax OK."
msgid_plural "Template syntax OK for %(count)d templates."
msgstr[0] ""
msgstr[1] ""
#: admin.py:141
msgid "Check template syntax"
msgstr ""
#: admin.py:145 models.py:25
msgid "sites"
msgstr "sivustot"
#: models.py:26
#: models.py:22
msgid "name"
msgstr "nimi"
#: models.py:27
#: models.py:23
msgid "Example: 'flatpages/default.html'"
msgstr "Esimerkiksi: 'flatpages/default.html'"
#: models.py:28
#: models.py:24
msgid "content"
msgstr "sisätö"
#: models.py:30
#: models.py:27
msgid "creation date"
msgstr "luontipäivä"
#: models.py:32
#: models.py:29
msgid "last changed"
msgstr "viimeksi muutettu"
#: models.py:40
#: models.py:37
msgid "template"
msgstr "mallipohja"
#: models.py:41
#: models.py:38
msgid "templates"
msgstr "mallipohjat"

View file

@ -1,21 +1,22 @@
# Roland Frédéric <frederic.roland@creativeconvergence.be>, 2009.
#
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
#
msgid ""
msgstr ""
"Project-Id-Version: django-dbtemplates\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: David Paccoud <dpaccoud@gmail.com>\n"
"Language-Team: French\n"
"POT-Creation-Date: 2011-01-31 11:10+0100\n"
"PO-Revision-Date: 2011-01-31 10:08+0000\n"
"Report-Msgid-Bugs-To: https://github.com/jezdez/django-dbtemplates/issues\n"
"POT-Creation-Date: 2011-08-15 13:13+0200\n"
"PO-Revision-Date: 2011-08-15 11:14+0000\n"
"Last-Translator: Jannis <jannis@leidel.info>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: fr\n"
"Plural-Forms: nplurals=2; plural=(n > 1)\n"
#: admin.py:53
#: admin.py:56
msgid ""
"Leaving this empty causes Django to look for a template with the given name "
"and populate this field with its content."
@ -23,64 +24,85 @@ msgstr ""
"Si vous laissez ceci vide , Django recherchera un modèle avec le nom donné "
"et remplira ce champ avec son contenu."
#: admin.py:77
#: admin.py:82
msgid "Advanced"
msgstr ""
#: admin.py:80
#: admin.py:85
msgid "Date/time"
msgstr "Date/heure"
#: admin.py:98
#, python-format
#: admin.py:102
#, fuzzy, python-format
msgid "Cache of one template successfully invalidated."
msgid_plural "Cache of %(count)d templates successfully invalidated."
msgstr[0] "Le cache d'un modèle a été invalidé avec succès."
msgstr[1] ""
#: admin.py:102
#: admin.py:106
msgid "Invalidate cache of selected templates"
msgstr "Invalidation du cache des modèles sélectionnés"
#: admin.py:111
#, python-format
#: admin.py:114
#, fuzzy, python-format
msgid "Cache successfully repopulated with one template."
msgid_plural "Cache successfully repopulated with %(count)d templates."
msgstr[0] "Le cache d'un modèle a été rechargé avec succès."
msgstr[1] ""
#: admin.py:115
#: admin.py:118
msgid "Repopulate cache with selected templates"
msgstr "Rechargement du cache des modèles sélectionnés"
#: admin.py:119 models.py:29
#: admin.py:130
#, python-format
msgid "Template syntax check FAILED for %(names)s."
msgid_plural ""
"Template syntax check FAILED for %(count)d templates: %(names)s."
msgstr[0] ""
msgstr[1] ""
#: admin.py:138
#, python-format
msgid "Template syntax OK."
msgid_plural "Template syntax OK for %(count)d templates."
msgstr[0] ""
msgstr[1] ""
#: admin.py:141
msgid "Check template syntax"
msgstr ""
#: admin.py:145 models.py:25
msgid "sites"
msgstr "sites"
#: models.py:26
#: models.py:22
msgid "name"
msgstr "nom"
#: models.py:27
#: models.py:23
msgid "Example: 'flatpages/default.html'"
msgstr "Exemple : 'flatpages/default.html'"
#: models.py:28
#: models.py:24
msgid "content"
msgstr "contenu"
#: models.py:30
#: models.py:27
msgid "creation date"
msgstr "date de création"
#: models.py:32
#: models.py:29
msgid "last changed"
msgstr "dernier changement"
#: models.py:40
#: models.py:37
msgid "template"
msgstr "modèle"
#: models.py:41
#: models.py:38
msgid "templates"
msgstr "modèles"

View file

@ -1,86 +1,106 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#
msgid ""
msgstr ""
"Project-Id-Version: django-dbtemplates\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"
"POT-Creation-Date: 2011-01-31 11:10+0100\n"
"PO-Revision-Date: 2011-01-31 10:08+0000\n"
"Report-Msgid-Bugs-To: https://github.com/jezdez/django-dbtemplates/issues\n"
"POT-Creation-Date: 2011-08-15 13:13+0200\n"
"PO-Revision-Date: 2011-08-15 11:14+0000\n"
"Last-Translator: Jannis <jannis@leidel.info>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: he\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
#: admin.py:53
#: admin.py:56
msgid ""
"Leaving this empty causes Django to look for a template with the given name "
"and populate this field with its content."
msgstr "אם זה ריק אז ג'נגו מחפש תבנית עם שם סיפק וממלא את השדה עם תוכנו"
#: admin.py:77
#: admin.py:82
msgid "Advanced"
msgstr ""
#: admin.py:80
#: admin.py:85
msgid "Date/time"
msgstr "תאריך / זמן"
#: admin.py:98
#: admin.py:102
#, python-format
msgid "Cache of one template successfully invalidated."
msgid_plural "Cache of %(count)d templates successfully invalidated."
msgstr[0] ""
msgstr[1] ""
#: admin.py:102
#: admin.py:106
msgid "Invalidate cache of selected templates"
msgstr ""
#: admin.py:111
#: admin.py:114
#, python-format
msgid "Cache successfully repopulated with one template."
msgid_plural "Cache successfully repopulated with %(count)d templates."
msgstr[0] ""
msgstr[1] ""
#: admin.py:115
#: admin.py:118
msgid "Repopulate cache with selected templates"
msgstr ""
#: admin.py:119 models.py:29
#: admin.py:130
#, python-format
msgid "Template syntax check FAILED for %(names)s."
msgid_plural ""
"Template syntax check FAILED for %(count)d templates: %(names)s."
msgstr[0] ""
msgstr[1] ""
#: admin.py:138
#, python-format
msgid "Template syntax OK."
msgid_plural "Template syntax OK for %(count)d templates."
msgstr[0] ""
msgstr[1] ""
#: admin.py:141
msgid "Check template syntax"
msgstr ""
#: admin.py:145 models.py:25
msgid "sites"
msgstr "אתרים"
#: models.py:26
#: models.py:22
msgid "name"
msgstr "שם"
#: models.py:27
#: models.py:23
msgid "Example: 'flatpages/default.html'"
msgstr "דוגמא: 'flatpages/default.html'"
#: models.py:28
#: models.py:24
msgid "content"
msgstr "תוכן"
#: models.py:30
#: models.py:27
msgid "creation date"
msgstr "נוצר ב"
#: models.py:32
#: models.py:29
msgid "last changed"
msgstr "שונה ב"
#: models.py:40
#: models.py:37
msgid "template"
msgstr "תבנית"
#: models.py:41
#: models.py:38
msgid "templates"
msgstr "תבניות"

View file

@ -1,18 +1,22 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
#
msgid ""
msgstr ""
"Project-Id-Version: django-dbtemplates\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: Marco Beri <marcoberi@gmail.com>\n"
"Language-Team: Jannis Leidel <jannis@leidel.info>\n"
"POT-Creation-Date: 2011-01-31 11:10+0100\n"
"PO-Revision-Date: 2011-01-31 10:08+0000\n"
"Report-Msgid-Bugs-To: https://github.com/jezdez/django-dbtemplates/issues\n"
"POT-Creation-Date: 2011-08-15 13:13+0200\n"
"PO-Revision-Date: 2011-08-15 11:14+0000\n"
"Last-Translator: Jannis <jannis@leidel.info>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: it\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
#: admin.py:53
#: admin.py:56
msgid ""
"Leaving this empty causes Django to look for a template with the given name "
"and populate this field with its content."
@ -20,64 +24,85 @@ msgstr ""
"Lasciandolo vuoto, Django cercherà un template con lo stesso nome che avete "
"indicato sopra e userà il suo contenuto per riempire questo campo."
#: admin.py:77
#: admin.py:82
msgid "Advanced"
msgstr ""
#: admin.py:80
#: admin.py:85
msgid "Date/time"
msgstr ""
#: admin.py:98
#: admin.py:102
#, python-format
msgid "Cache of one template successfully invalidated."
msgid_plural "Cache of %(count)d templates successfully invalidated."
msgstr[0] ""
msgstr[1] ""
#: admin.py:102
#: admin.py:106
msgid "Invalidate cache of selected templates"
msgstr ""
#: admin.py:111
#: admin.py:114
#, python-format
msgid "Cache successfully repopulated with one template."
msgid_plural "Cache successfully repopulated with %(count)d templates."
msgstr[0] ""
msgstr[1] ""
#: admin.py:115
#: admin.py:118
msgid "Repopulate cache with selected templates"
msgstr ""
#: admin.py:119 models.py:29
#: admin.py:130
#, python-format
msgid "Template syntax check FAILED for %(names)s."
msgid_plural ""
"Template syntax check FAILED for %(count)d templates: %(names)s."
msgstr[0] ""
msgstr[1] ""
#: admin.py:138
#, python-format
msgid "Template syntax OK."
msgid_plural "Template syntax OK for %(count)d templates."
msgstr[0] ""
msgstr[1] ""
#: admin.py:141
msgid "Check template syntax"
msgstr ""
#: admin.py:145 models.py:25
msgid "sites"
msgstr ""
#: models.py:26
#: models.py:22
msgid "name"
msgstr "nome"
#: models.py:27
#: models.py:23
msgid "Example: 'flatpages/default.html'"
msgstr "Esempio: 'flatpages/default.html'"
#: models.py:28
#: models.py:24
msgid "content"
msgstr "contenuto"
#: models.py:30
#: models.py:27
msgid "creation date"
msgstr "data di creazione"
#: models.py:32
#: models.py:29
msgid "last changed"
msgstr "ultimo cambiamento"
#: models.py:40
#: models.py:37
msgid "template"
msgstr "template"
#: models.py:41
#: models.py:38
msgid "templates"
msgstr "template"

View file

@ -7,9 +7,9 @@ msgid ""
msgstr ""
"Project-Id-Version: django-dbtemplates\n"
"Report-Msgid-Bugs-To: https://github.com/jezdez/django-dbtemplates/issues\n"
"POT-Creation-Date: 2010-11-07 00:02+0100\n"
"PO-Revision-Date: 2011-06-01 18:11+0000\n"
"Last-Translator: hersonls <hersonls@gmail.com>\n"
"POT-Creation-Date: 2011-08-15 13:13+0200\n"
"PO-Revision-Date: 2011-08-15 11:14+0000\n"
"Last-Translator: Jannis <jannis@leidel.info>\n"
"Language-Team: Portuguese (Brazilian) (http://www.transifex.net/projects/p/django-dbtemplates/team/pt_BR/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@ -17,7 +17,7 @@ msgstr ""
"Language: pt_BR\n"
"Plural-Forms: nplurals=2; plural=(n > 1)\n"
#: admin.py:53
#: admin.py:56
msgid ""
"Leaving this empty causes Django to look for a template with the given name "
"and populate this field with its content."
@ -25,65 +25,84 @@ msgstr ""
"Manter isto vazio faz com que o Django procure por um modelo (template) com "
"o dado nome e preencha este campo com o seu conteúdo"
#: admin.py:77
#: admin.py:82
msgid "Advanced"
msgstr "Avançado"
#: admin.py:80
#: admin.py:85
msgid "Date/time"
msgstr "Data/hora"
#: admin.py:98
#: admin.py:102
#, python-format
msgid "Cache of one template successfully invalidated."
msgid_plural "Cache of %(count)d templates successfully invalidated."
msgstr[0] ""
msgstr[1] ""
#: admin.py:102
#: admin.py:106
msgid "Invalidate cache of selected templates"
msgstr ""
#: admin.py:111
#: admin.py:114
#, python-format
msgid "Cache successfully repopulated with one template."
msgid_plural "Cache successfully repopulated with %(count)d templates."
msgstr[0] ""
msgstr[1] ""
#: admin.py:115
#: admin.py:118
msgid "Repopulate cache with selected templates"
msgstr ""
#: admin.py:119 models.py:29
#: admin.py:130
#, python-format
msgid "Template syntax check FAILED for %(names)s."
msgid_plural ""
"Template syntax check FAILED for %(count)d templates: %(names)s."
msgstr[0] ""
msgstr[1] ""
#: admin.py:138
#, python-format
msgid "Template syntax OK."
msgid_plural "Template syntax OK for %(count)d templates."
msgstr[0] ""
msgstr[1] ""
#: admin.py:141
msgid "Check template syntax"
msgstr ""
#: admin.py:145 models.py:25
msgid "sites"
msgstr "sites"
#: models.py:26
#: models.py:22
msgid "name"
msgstr "Name"
#: models.py:27
#: models.py:23
msgid "Example: 'flatpages/default.html'"
msgstr "Exemplo: 'flatpages/default.html'"
#: models.py:28
#: models.py:24
msgid "content"
msgstr "conteúdo"
#: models.py:30
#: models.py:27
msgid "creation date"
msgstr "Data de criação"
#: models.py:32
#: models.py:29
msgid "last changed"
msgstr "ultima modificação"
#: models.py:40
#: models.py:37
msgid "template"
msgstr "modelo"
#: models.py:41
#: models.py:38
msgid "templates"
msgstr "modelos"

View file

@ -1,15 +1,14 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#
msgid ""
msgstr ""
"Project-Id-Version: django-dbtemplates\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: 张昆 <zhangkun@web916.com>\n"
"POT-Creation-Date: 2011-01-31 11:10+0100\n"
"PO-Revision-Date: 2011-01-31 10:08+0000\n"
"Report-Msgid-Bugs-To: https://github.com/jezdez/django-dbtemplates/issues\n"
"POT-Creation-Date: 2011-08-15 13:13+0200\n"
"PO-Revision-Date: 2011-08-15 11:14+0000\n"
"Last-Translator: Jannis <jannis@leidel.info>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@ -17,68 +16,87 @@ msgstr ""
"Language: zh_CN\n"
"Plural-Forms: nplurals=1; plural=0\n"
#: admin.py:53
#: admin.py:56
msgid ""
"Leaving this empty causes Django to look for a template with the given name "
"and populate this field with its content."
msgstr "此项目留空将使系统用指定的名称寻找模板并应用到该项目。"
#: admin.py:77
#: admin.py:82
msgid "Advanced"
msgstr ""
#: admin.py:80
#: admin.py:85
msgid "Date/time"
msgstr "日期/时间"
#: admin.py:98
#: admin.py:102
#, fuzzy, python-format
msgid "Cache of one template successfully invalidated."
msgid_plural "Cache of %(count)d templates successfully invalidated."
msgstr[0] "该模板的缓存已经成功撤销。"
#: admin.py:102
#: admin.py:106
msgid "Invalidate cache of selected templates"
msgstr "撤销选中模板的缓存"
#: admin.py:111
#: admin.py:114
#, fuzzy, python-format
msgid "Cache successfully repopulated with one template."
msgid_plural "Cache successfully repopulated with %(count)d templates."
msgstr[0] "该模板的缓存已经成功启用。"
#: admin.py:115
#: admin.py:118
msgid "Repopulate cache with selected templates"
msgstr "重新启用选中模板的缓存"
#: admin.py:119 models.py:29
#: admin.py:130
#, python-format
msgid "Template syntax check FAILED for %(names)s."
msgid_plural ""
"Template syntax check FAILED for %(count)d templates: %(names)s."
msgstr[0] ""
#: admin.py:138
#, python-format
msgid "Template syntax OK."
msgid_plural "Template syntax OK for %(count)d templates."
msgstr[0] ""
#: admin.py:141
msgid "Check template syntax"
msgstr ""
#: admin.py:145 models.py:25
msgid "sites"
msgstr "站点"
#: models.py:26
#: models.py:22
msgid "name"
msgstr "名称"
#: models.py:27
#: models.py:23
msgid "Example: 'flatpages/default.html'"
msgstr "例如: 'flatpages/default.html'"
#: models.py:28
#: models.py:24
msgid "content"
msgstr "内容"
#: models.py:30
#: models.py:27
msgid "creation date"
msgstr "创建日期"
#: models.py:32
#: models.py:29
msgid "last changed"
msgstr "最新变更"
#: models.py:40
#: models.py:37
msgid "template"
msgstr "模板"
#: models.py:41
#: models.py:38
msgid "templates"
msgstr "模板"

View file

@ -0,0 +1,20 @@
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."
def handle_noargs(self, **options):
errors = []
for template in Template.objects.all():
valid, error = check_template_syntax(template)
if not valid:
errors.append('%s: %s' % (template.name, error))
if errors:
raise CommandError(
'Some templates contained errors\n%s' % '\n'.join(errors))
# NOTE: printing instead of using self.stdout.write to maintain
# Django 1.2 compatibility
print('OK')

View file

@ -14,7 +14,8 @@ 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.template import get_template_source
from dbtemplates.utils.template import (get_template_source,
check_template_syntax)
from dbtemplates.management.commands.sync_templates import (FILES_TO_DATABASE,
DATABASE_TO_FILES)
@ -96,3 +97,11 @@ class DbTemplatesTestCase(TestCase):
def test_get_cache(self):
self.assertTrue(isinstance(get_cache_backend(), BaseCache))
def test_check_template_syntax(self):
bad_template, _ = Template.objects.get_or_create(
name='bad.html', content='{% if foo %}Bar')
good_template, _ = Template.objects.get_or_create(
name='good.html', content='{% if foo %}Bar{% endif %}')
self.assertFalse(check_template_syntax(bad_template)[0])
self.assertTrue(check_template_syntax(good_template)[0])

View file

@ -16,6 +16,15 @@ def get_cache_key(name):
return 'dbtemplates::%s::%s' % (name, current_site.pk)
def get_cache_notfound_key(name):
return get_cache_key(name) + '::notfound'
def remove_notfound_key(instance):
# Remove notfound key as soon as we save the template.
cache.delete(get_cache_notfound_key(instance.name))
def set_and_return(cache_key, content, display_name):
# Save in cache backend explicitly if manually deleted or invalidated
if cache:
@ -29,6 +38,7 @@ def add_template_to_cache(instance, **kwargs):
in the database was added or changed.
"""
remove_cached_template(instance)
remove_notfound_key(instance)
cache.set(get_cache_key(instance.name), instance.content)

View file

@ -1,5 +1,6 @@
from django import VERSION
from django.template import TemplateDoesNotExist
from django.template import (Template, TemplateDoesNotExist,
TemplateSyntaxError)
from django.utils.importlib import import_module
@ -48,3 +49,11 @@ def get_template_source(name):
except (ImportError, TemplateDoesNotExist):
pass
return None
def check_template_syntax(template):
try:
Template(template.content)
except TemplateSyntaxError, e:
return (False, e)
return (True, None)

View file

@ -82,6 +82,12 @@ Management commands
Tries to add the two templates ``404.html`` and ``500.html`` that are used
by Django when a error occurs.
* ``check_template_syntax``
.. versionadded:: 1.2
Checks the saved templates whether they are valid Django templates.
.. _Django management commands: http://docs.djangoproject.com/en/dev/ref/django-admin/
.. _admin_actions:
@ -101,4 +107,10 @@ Admin actions
Repopulates the cache with selected templates by invalidating it first and
filling then after that.
* ``check_syntax``
.. versionadded:: 1.2
Checks the selected tempaltes for syntax errors.
.. _admin actions: http://docs.djangoproject.com/en/dev/ref/contrib/admin/actions/

View file

@ -1,6 +1,14 @@
Changelog
=========
1.2 (08-15-11)
--------------
* 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)
----------------

View file

@ -38,16 +38,16 @@ master_doc = 'index'
# General information about the project.
project = u'django-dbtemplates'
copyright = u'2007-2011, Jannis Leidel'
copyright = u'2007-2011, 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
# built documents.
#
# The short X.Y version.
version = '1.1'
version = '1.2'
# The full version, including alpha/beta/rc tags.
release = '1.1.1'
release = '1.2'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
@ -173,7 +173,7 @@ htmlhelp_basename = 'django-dbtemplatesdoc'
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'django-dbtemplates.tex', u'django-dbtemplates Documentation',
u'Jannis Leidel', 'manual'),
u'Jannis Leidel and contributors', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of

View file

@ -18,12 +18,16 @@ setup(
],
},
classifiers=[
'Development Status :: 4 - Beta',
'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.5',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Framework :: Django',
],
)