sortowanie wyników uczniów w mailu dla nauczyciela
[edumed.git] / chunks / models.py
1 from django.core.cache import cache
2 from django.db import models
3 from django.utils.translation import ugettext_lazy as _
4
5
6 class Chunk(models.Model):
7     """
8     A Chunk is a piece of content associated with a unique key that can be inserted into
9     any template with the use of a special template tag.
10     """
11     key = models.CharField(_('key'), help_text=_('A unique name for this chunk of content'), primary_key=True, max_length=255)
12     description = models.CharField(_('description'), blank=True, max_length=255)
13     content = models.TextField(_('content'), blank=True)
14
15     class Meta:
16         ordering = ('key',)
17         verbose_name = _('chunk')
18         verbose_name_plural = _('chunks')
19
20     def __unicode__(self):
21         return self.key
22
23     def cache_key(self):
24         return 'chunk_' + self.key
25
26     def save(self, *args, **kwargs):
27         ret = super(Chunk, self).save(*args, **kwargs)
28         cache.delete(self.cache_key())
29         return ret
30
31
32 class Attachment(models.Model):
33     key = models.CharField(_('key'), help_text=_('A unique name for this attachment'), primary_key=True, max_length=255)
34     attachment = models.FileField(upload_to='chunks/attachment')
35
36     class Meta:
37         ordering = ('key',)
38         verbose_name, verbose_name_plural = _('attachment'), _('attachments')
39
40     def __unicode__(self):
41         return self.key
42