1 # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
4 from django.conf import settings
5 from django.core.cache import cache
6 from django.db import models
7 from django.urls import reverse
8 from django.utils.safestring import mark_safe
11 class Chunk(models.Model):
13 A Chunk is a piece of content associated with a unique key that can be inserted into
14 any template with the use of a special template tag.
16 key = models.CharField('klucz', help_text='Unikalna nazwa dla tego kawałka treści', primary_key=True,
18 description = models.CharField('opis', blank=True, max_length=255)
19 content = models.TextField('zawartość', blank=True)
23 verbose_name = 'kawałek'
24 verbose_name_plural = 'kawałki'
29 def save(self, *args, **kwargs):
30 ret = super(Chunk, self).save(*args, **kwargs)
31 for lc, ln in settings.LANGUAGES:
32 cache.delete('chunk:%s:%s' % (self.key, lc))
36 class Attachment(models.Model):
37 key = models.CharField(
38 'klucz', help_text='Unikalna nazwa dla tego załącznika',
39 primary_key=True, max_length=255)
40 attachment = models.FileField(upload_to='chunks/attachment')
44 verbose_name, verbose_name_plural = 'załącznik', 'załączniki'
49 def get_absolute_url(self):
50 return reverse('chunks_attachment', args=[self.key, self.attachment.name.rsplit('.', 1)[-1]])
53 class Menu(models.Model):
54 identifier = models.CharField(max_length=255, unique=True)
57 return self.identifier
60 class MenuItem(models.Model):
61 menu = models.ForeignKey(Menu, models.CASCADE)
62 order = models.SmallIntegerField()
63 highlight = models.BooleanField()
64 infopage = models.ForeignKey(
65 'infopages.InfoPage', models.PROTECT, null=True, blank=True)
66 url = models.CharField(max_length=255, blank=True)
67 name = models.CharField(max_length=255, blank=True)
75 return mark_safe('<hr>')
79 return self.infopage.title
85 return self.infopage.get_absolute_url()
90 return self.url or self.infopage