From: Marek Stępniowski
Date: Fri, 4 Sep 2009 11:34:01 +0000 (+0200)
Subject: Dodanie możliwości zmiany stopki w panelu administracyjnym serwisu.
X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/6c984d51262f63e88ae8ffb8e6611ea2dd406471?ds=inline;hp=-c
Dodanie możliwości zmiany stopki w panelu administracyjnym serwisu.
---
6c984d51262f63e88ae8ffb8e6611ea2dd406471
diff --git a/apps/chunks/admin.py b/apps/chunks/admin.py
index c44d5a037..614e4e85b 100644
--- a/apps/chunks/admin.py
+++ b/apps/chunks/admin.py
@@ -1,6 +1,6 @@
from django.contrib import admin
-from chunks.models import Chunk
+from chunks.models import Chunk, Attachment
class ChunkAdmin(admin.ModelAdmin):
@@ -9,3 +9,9 @@ class ChunkAdmin(admin.ModelAdmin):
admin.site.register(Chunk, ChunkAdmin)
+
+class AttachmentAdmin(admin.ModelAdmin):
+ list_display = ('key',)
+ search_fields = ('key',)
+
+admin.site.register(Attachment, AttachmentAdmin)
\ No newline at end of file
diff --git a/apps/chunks/models.py b/apps/chunks/models.py
index 396d221ed..86f04660c 100644
--- a/apps/chunks/models.py
+++ b/apps/chunks/models.py
@@ -17,5 +17,17 @@ class Chunk(models.Model):
verbose_name_plural = _('chunks')
def __unicode__(self):
- return u'%s' % (self.key,)
+ return self.key
+
+
+class Attachment(models.Model):
+ key = models.CharField(_('key'), help_text=_('A unique name for this attachment'), primary_key=True, max_length=255)
+ attachment = models.FileField(upload_to='chunks/attachment')
+
+ class Meta:
+ ordering = ('key',)
+ verbose_name, verbose_name_plural = _('attachment'), _('attachments')
+
+ def __unicode__(self):
+ return self.key
diff --git a/apps/chunks/templatetags/chunks.py b/apps/chunks/templatetags/chunks.py
index f79d495ec..595482f41 100644
--- a/apps/chunks/templatetags/chunks.py
+++ b/apps/chunks/templatetags/chunks.py
@@ -2,10 +2,12 @@ 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_"
+Attachment = models.get_model('chunks', 'attachment')
+
def do_get_chunk(parser, token):
# split_contents() knows not to split quoted strings.
@@ -23,6 +25,7 @@ def do_get_chunk(parser, token):
# 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
@@ -30,7 +33,7 @@ class ChunkNode(template.Node):
def render(self, context):
try:
- cache_key = CACHE_PREFIX + self.key
+ cache_key = 'chunk_' + self.key
c = cache.get(cache_key)
if c is None:
c = Chunk.objects.get(key=self.key)
@@ -43,3 +46,18 @@ class ChunkNode(template.Node):
return content
register.tag('chunk', do_get_chunk)
+
+
+def attachment(key, cache_time=0):
+ try:
+ cache_key = 'attachment_' + key
+ c = cache.get(cache_key)
+ if c is None:
+ c = Attachment.objects.get(key=key)
+ cache.set(cache_key, c, int(cache_time))
+ return c.attachment.url
+ except Attachment.DoesNotExist:
+ return ''
+
+register.simple_tag(attachment)
+
diff --git a/wolnelektury/templates/base.html b/wolnelektury/templates/base.html
index 2e687ce87..4e7a6fabd 100644
--- a/wolnelektury/templates/base.html
+++ b/wolnelektury/templates/base.html
@@ -56,8 +56,8 @@
e-mail: fundacja@nowoczesnapolska.org.pl
-
-
+
+