diff --git a/chunks/locale/ru/LC_MESSAGES/django.mo b/chunks/locale/ru/LC_MESSAGES/django.mo index 0c4130b..4b1dc4e 100644 Binary files a/chunks/locale/ru/LC_MESSAGES/django.mo and b/chunks/locale/ru/LC_MESSAGES/django.mo differ diff --git a/chunks/locale/ru/LC_MESSAGES/django.po b/chunks/locale/ru/LC_MESSAGES/django.po index 9612326..ac9e76b 100644 --- a/chunks/locale/ru/LC_MESSAGES/django.po +++ b/chunks/locale/ru/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2012-05-27 01:43+0400\n" +"POT-Creation-Date: 2014-07-26 12:07+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -39,10 +39,14 @@ msgstr "Описание" msgid "Short Description" msgstr "Краткое описание блока" -#: models.py:17 +#: models.py:15 +msgid "Enabled" +msgstr "Включено" + +#: models.py:18 msgid "chunk" msgstr "блок" -#: models.py:18 +#: models.py:19 msgid "chunks" msgstr "блоки" diff --git a/chunks/migrations/0003_auto__add_field_chunk_enabled.py b/chunks/migrations/0003_auto__add_field_chunk_enabled.py new file mode 100644 index 0000000..9c8466d --- /dev/null +++ b/chunks/migrations/0003_auto__add_field_chunk_enabled.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + + +class Migration(SchemaMigration): + + def forwards(self, orm): + # Adding field 'Chunk.enabled' + db.add_column(u'chunks_chunk', 'enabled', + self.gf('django.db.models.fields.BooleanField')(default=True), + keep_default=False) + + + def backwards(self, orm): + # Deleting field 'Chunk.enabled' + db.delete_column(u'chunks_chunk', 'enabled') + + + models = { + u'chunks.chunk': { + 'Meta': {'object_name': 'Chunk'}, + 'content': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'description': ('django.db.models.fields.CharField', [], {'max_length': '64', 'blank': 'True'}), + 'enabled': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}) + } + } + + complete_apps = ['chunks'] \ No newline at end of file diff --git a/chunks/models.py b/chunks/models.py index 22a7c0a..cd44e55 100644 --- a/chunks/models.py +++ b/chunks/models.py @@ -12,6 +12,7 @@ class Chunk(models.Model): key = models.CharField(_(u'Key'), help_text=_(u"A unique name for this chunk of content"), blank=False, max_length=255, unique=True) content = models.TextField(_(u'Content'), blank=True) description = models.CharField(_(u'Description'), blank=True, max_length=64, help_text=_(u"Short Description")) + enabled = models.BooleanField(_(u'Enabled'), default=True) class Meta: verbose_name = _(u'chunk') diff --git a/chunks/templatetags/chunks.py b/chunks/templatetags/chunks.py index d669213..2b22ece 100644 --- a/chunks/templatetags/chunks.py +++ b/chunks/templatetags/chunks.py @@ -7,6 +7,7 @@ Chunk = models.get_model('chunks', 'chunk') CACHE_PREFIX = "chunk_" + def do_chunk(parser, token): # split_contents() knows not to split quoted strings. tokens = token.split_contents() @@ -20,7 +21,9 @@ def do_chunk(parser, token): key = ensure_quoted_string(key, "%r tag's argument should be in quotes" % tag_name) return ChunkNode(key, cache_time) + class ChunkNode(template.Node): + def __init__(self, key, cache_time=0): self.key = key self.cache_time = cache_time @@ -32,7 +35,10 @@ def render(self, context): if c is None: c = Chunk.objects.get(key=self.key) cache.set(cache_key, c, int(self.cache_time)) - content = c.content + if c.enabled: + content = c.content + else: + content = '' except Chunk.DoesNotExist: content = '' return content @@ -46,6 +52,7 @@ def do_get_chunk(parser, token): key = ensure_quoted_string(key, "Key argument to %r must be in quotes" % tagname) return GetChunkNode(key, varname) + class GetChunkNode(template.Node): def __init__(self, key, varname): self.key = key