3 from django.core.urlresolvers import reverse
4 from django.db import models
5 from django.utils.translation import ugettext_lazy as _
7 class Section(models.Model):
8 name = models.CharField(_('name'), max_length=255)
9 slug = models.SlugField(_('slug'))
10 order = models.IntegerField(_('order'))
14 verbose_name = _('section')
15 verbose_name_plural = _('sections')
17 def __unicode__(self):
20 class Competence(models.Model):
21 section = models.ForeignKey(Section)
22 name = models.CharField(_('name'), max_length=255)
23 slug = models.SlugField(_('slug'))
24 order = models.IntegerField(_('order'))
28 verbose_name = _('competence')
29 verbose_name_plural = _('competences')
31 def __unicode__(self):
34 def get_absolute_url(self):
35 return "%s?c=%d" % (reverse("curriculum"), self.pk)
37 def for_level(self, level):
38 return self.competencelevel_set.get(level=level)
41 def from_text(cls, text):
42 name = text.rsplit(u'\u2013', 1)[-1].strip()
43 return cls.objects.get(name__iexact=name)
45 class Level(models.Model):
46 group = models.CharField(_('group'), max_length=255)
47 name = models.CharField(_('name'), max_length=255)
48 slug = models.CharField(_('slug'), max_length=255)
49 order = models.IntegerField(_('order'))
53 verbose_name = _('educational level')
54 verbose_name_plural = _('educational levels')
56 def __unicode__(self):
59 class CompetenceLevel(models.Model):
60 competence = models.ForeignKey(Competence)
61 level = models.ForeignKey(Level)
62 description = models.TextField(_('description'))
65 ordering = ['competence', 'level']
66 verbose_name = _('competence on level')
67 verbose_name_plural = _('competences on levels')
69 def __unicode__(self):
70 return u"%s/%s" % (self.competence, self.level)
72 def get_absolute_url(self):
73 return "%s?c=%d&level=%s&d=1" % (reverse("curriculum"), self.competence.pk, self.level.slug)
77 class CurriculumLevel(models.Model):
78 title = models.CharField(max_length=16, db_index=True)
81 verbose_name = _("curriculum level")
82 verbose_name_plural = _("curriculum levels")
84 def __unicode__(self):
88 class CurriculumCourse(models.Model):
89 title = models.CharField(max_length=255)
90 accusative = models.CharField(max_length=255)
91 slug = models.CharField(max_length=255, db_index=True)
94 verbose_name = _("curriculum course")
95 verbose_name_plural = _("curriculum courses")
98 def __unicode__(self):
102 class Curriculum(models.Model):
103 """Official curriculum."""
104 TYPES = {'c': u'Cele kształcenia', 't': u'Treści nauczania'}
106 identifier = models.CharField(max_length=255, db_index=True)
107 title = models.CharField(max_length=255)
108 course = models.ForeignKey(CurriculumCourse)
109 level = models.ForeignKey(CurriculumLevel)
110 type = models.CharField(max_length=16, choices=TYPES.items())
113 verbose_name = _("curriculum item")
114 verbose_name_plural = _("curriculum items")
116 def __unicode__(self):
117 return self.identifier
120 def from_text(cls, identifier, title):
121 m = re.match(r"^\d+/(?P<level>[^/]+)/(?P<course>[^/]+)/"
122 "(?P<type>(?:%s))[^/]+(?P<roz>/roz)?" %
123 "|".join(cls.TYPES), identifier)
124 assert m is not None, "Curriculum identifier doesn't match template."
125 level, created = CurriculumLevel.objects.get_or_create(
126 title=m.group('level'))
127 def_title = m.group('course').title()
128 course, created = CurriculumCourse.objects.get_or_create(
129 slug=m.group('course').lower(),
132 'accusative': def_title,
134 type_ = m.group('type')
136 title += " (zakres rozszerzony)"
139 curr = cls.objects.get(identifier=identifier)
140 except cls.DoesNotExist:
141 curr = cls(identifier=identifier)