Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified chunks/locale/ru/LC_MESSAGES/django.mo
Binary file not shown.
10 changes: 7 additions & 3 deletions chunks/locale/ru/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -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 "блоки"
33 changes: 33 additions & 0 deletions chunks/migrations/0003_auto__add_field_chunk_enabled.py
Original file line number Diff line number Diff line change
@@ -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']
1 change: 1 addition & 0 deletions chunks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
9 changes: 8 additions & 1 deletion chunks/templatetags/chunks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down