diff options
Diffstat (limited to 'app/lib/chunks')
-rwxr-xr-x | app/lib/chunks/__init__.py | 0 | ||||
-rwxr-xr-x | app/lib/chunks/admin.py | 8 | ||||
-rwxr-xr-x | app/lib/chunks/models.py | 14 | ||||
-rwxr-xr-x | app/lib/chunks/templatetags/__init__.py | 0 | ||||
-rwxr-xr-x | app/lib/chunks/templatetags/chunks.py | 43 |
5 files changed, 0 insertions, 65 deletions
diff --git a/app/lib/chunks/__init__.py b/app/lib/chunks/__init__.py deleted file mode 100755 index e69de29..0000000 --- a/app/lib/chunks/__init__.py +++ /dev/null diff --git a/app/lib/chunks/admin.py b/app/lib/chunks/admin.py deleted file mode 100755 index 06dd917..0000000 --- a/app/lib/chunks/admin.py +++ /dev/null @@ -1,8 +0,0 @@ -from django.contrib import admin -from models import Chunk - -class ChunkAdmin(admin.ModelAdmin): - list_display = ('key',) - search_fields = ('key', 'content') - -admin.site.register(Chunk, ChunkAdmin)
\ No newline at end of file diff --git a/app/lib/chunks/models.py b/app/lib/chunks/models.py deleted file mode 100755 index cdb36be..0000000 --- a/app/lib/chunks/models.py +++ /dev/null @@ -1,14 +0,0 @@ -from django.db import models - -class Chunk(models.Model): - """ - A Chunk is a piece of content associated - with a unique key that can be inserted into - any template with the use of a special template - tag - """ - key = models.CharField(help_text="A unique name for this chunk of content", blank=False, max_length=255, unique=True) - content = models.TextField(blank=True) - - def __unicode__(self): - return u"%s" % (self.key,) diff --git a/app/lib/chunks/templatetags/__init__.py b/app/lib/chunks/templatetags/__init__.py deleted file mode 100755 index e69de29..0000000 --- a/app/lib/chunks/templatetags/__init__.py +++ /dev/null diff --git a/app/lib/chunks/templatetags/chunks.py b/app/lib/chunks/templatetags/chunks.py deleted file mode 100755 index 2b06cad..0000000 --- a/app/lib/chunks/templatetags/chunks.py +++ /dev/null @@ -1,43 +0,0 @@ -from django import template -from django.db import models -from django.core.cache import cache - -register = template.Library() - -Chunk = models.get_model('chunks', 'chunk') -CACHE_PREFIX = "chunk_" - -def do_get_chunk(parser, token): - # split_contents() knows not to split quoted strings. - tokens = token.split_contents() - if len(tokens) < 2 or len(tokens) > 3: - raise template.TemplateSyntaxError, "%r tag should have either 2 or 3 arguments" % (tokens[0],) - if len(tokens) == 2: - tag_name, key = tokens - cache_time = 0 - if len(tokens) == 3: - tag_name, key, cache_time = tokens - # Check to see if the key is properly double/single quoted - if not (key[0] == key[-1] and key[0] in ('"', "'")): - raise template.TemplateSyntaxError, "%r tag's argument should be in quotes" % tag_name - # Send key without quotes and caching time - return ChunkNode(key[1:-1], cache_time) - -class ChunkNode(template.Node): - def __init__(self, key, cache_time=0): - self.key = key - self.cache_time = cache_time - - def render(self, context): - try: - cache_key = CACHE_PREFIX + self.key - c = cache.get(cache_key) - if c is None: - c = Chunk.objects.get(key=self.key) - cache.set(cache_key, c, int(self.cache_time)) - content = c.content - except Chunk.DoesNotExist: - content = '' - return content - -register.tag('chunk', do_get_chunk) |