1 # -*- coding: utf-8 -*-
 
   2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
 
   3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
 
   5 from django.conf import settings
 
   6 from django.db import models
 
   7 from django.utils.translation import ugettext_lazy as _
 
   8 from ssify import flush_ssi_includes
 
  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(_('key'), help_text=_('A unique name for this chunk of content'), primary_key=True,
 
  18     description = models.CharField(_('description'), blank=True, max_length=255)
 
  19     content = models.TextField(_('content'), blank=True)
 
  23         verbose_name = _('chunk')
 
  24         verbose_name_plural = _('chunks')
 
  29     def save(self, *args, **kwargs):
 
  30         ret = super(Chunk, self).save(*args, **kwargs)
 
  34     def flush_includes(self):
 
  36             '/chunks/chunk/%s.%s.html' % (self.key, lang)
 
  37             for lang in [lc for (lc, _ln) in settings.LANGUAGES]])
 
  40 class Attachment(models.Model):
 
  41     key = models.CharField(_('key'), help_text=_('A unique name for this attachment'), primary_key=True, max_length=255)
 
  42     attachment = models.FileField(upload_to='chunks/attachment')
 
  46         verbose_name, verbose_name_plural = _('attachment'), _('attachments')