pep8 and other code-style changes
[wolnelektury.git] / src / chunks / models.py
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.
4 #
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
9
10
11 class Chunk(models.Model):
12     """
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.
15     """
16     key = models.CharField(_('key'), help_text=_('A unique name for this chunk of content'), primary_key=True,
17                            max_length=255)
18     description = models.CharField(_('description'), blank=True, max_length=255)
19     content = models.TextField(_('content'), blank=True)
20
21     class Meta:
22         ordering = ('key',)
23         verbose_name = _('chunk')
24         verbose_name_plural = _('chunks')
25
26     def __unicode__(self):
27         return self.key
28
29     def save(self, *args, **kwargs):
30         ret = super(Chunk, self).save(*args, **kwargs)
31         self.flush_includes()
32         return ret
33
34     def flush_includes(self):
35         flush_ssi_includes([
36             '/chunks/chunk/%s.%s.html' % (self.key, lang)
37             for lang in [lc for (lc, _ln) in settings.LANGUAGES]])
38
39
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')
43
44     class Meta:
45         ordering = ('key',)
46         verbose_name, verbose_name_plural = _('attachment'), _('attachments')
47
48     def __unicode__(self):
49         return self.key