Fix global ZIP layout.
[edumed.git] / curriculum / models.py
1 from django.core.urlresolvers import reverse
2 from django.db import models
3 from django.utils.translation import ugettext_lazy as _
4
5 class Section(models.Model):
6     name = models.CharField(_('name'), max_length=255)
7     slug = models.SlugField(_('slug'))
8     order = models.IntegerField(_('order'))
9
10     class Meta:
11         ordering = ['order']
12         verbose_name = _('section')
13         verbose_name_plural = _('sections')
14
15     def __unicode__(self):
16         return self.name
17
18 class Competence(models.Model):
19     section = models.ForeignKey(Section)
20     name = models.CharField(_('name'), max_length=255)
21     slug = models.SlugField(_('slug'))
22     order = models.IntegerField(_('order'))
23
24     class Meta:
25         ordering = ['order']
26         verbose_name = _('competence')
27         verbose_name_plural = _('competences')
28
29     def __unicode__(self):
30         return self.name
31
32     def get_absolute_url(self):
33         return "%s?c=%d" % (reverse("curriculum"), self.pk)
34
35     def for_level(self, level):
36         return self.competencelevel_set.get(level=level)
37
38     @classmethod
39     def from_text(cls, text):
40         name = text.rsplit(u'\u2013', 1)[-1].strip()
41         return cls.objects.get(name__iexact=name)
42
43 class Level(models.Model):
44     group = models.CharField(_('group'), max_length=255)
45     name = models.CharField(_('name'), max_length=255)
46     slug = models.CharField(_('slug'), max_length=255)
47     order = models.IntegerField(_('order'))
48
49     class Meta:
50         ordering = ['order']
51         verbose_name = _('educational level')
52         verbose_name_plural = _('educational levels')
53
54     def __unicode__(self):
55         return self.name
56
57 class CompetenceLevel(models.Model):
58     competence = models.ForeignKey(Competence)
59     level = models.ForeignKey(Level)
60     description = models.TextField(_('description'))
61
62     class Meta:
63         ordering = ['competence', 'level']
64         verbose_name = _('competence on level')
65         verbose_name_plural = _('competences on levels')
66
67     def __unicode__(self):
68         return u"%s/%s" % (self.competence, self.level)
69
70     def get_absolute_url(self):
71         return "%s?c=%d&level=%s&d=1" % (reverse("curriculum"), self.competence.pk, self.level.slug)