From 6c984d51262f63e88ae8ffb8e6611ea2dd406471 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20St=C4=99pniowski?= Date: Fri, 4 Sep 2009 13:34:01 +0200 Subject: [PATCH] =?utf8?q?Dodanie=20mo=C5=BCliwo=C5=9Bci=20zmiany=20stopki?= =?utf8?q?=20w=20panelu=20administracyjnym=20serwisu.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- apps/chunks/admin.py | 8 +++++++- apps/chunks/models.py | 14 +++++++++++++- apps/chunks/templatetags/chunks.py | 22 ++++++++++++++++++++-- wolnelektury/templates/base.html | 4 ++-- 4 files changed, 42 insertions(+), 6 deletions(-) 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

- Partnerzy serwisu -GazetaEdukacja.pl - matura, testy, egzaminy, studiaKurier WileńskiRadio znad WiliiMinisterstwo Edukacji NarodowejBiblioteka AnalizPrzekrójTVP KulturaElleRadio TOK.FMTygodnik PowszechnyMinisterstwo Kultury i Dziedzictwa NarodowegoBiblioteka NarodowaPZLEO NetworksKancelaria Prawna Grynhoff Woźny Maliński Spółka komandytowaInformation is artFundacja Nowoczesna Polska + Partnerzy serwisu +{% chunk 'footer-map' %}

-- 2.20.1