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 slug = models.CharField(max_length=255, db_index=True)
93 verbose_name = _("curriculum course")
94 verbose_name_plural = _("curriculum courses")
96 def __unicode__(self):
100 class Curriculum(models.Model):
101 """Official curriculum."""
102 TYPES = {'c': u'Cele kształcenia', 't': u'Treści nauczania'}
104 identifier = models.CharField(max_length=255, db_index=True)
105 title = models.CharField(max_length=255)
106 course = models.ForeignKey(CurriculumCourse)
107 level = models.ForeignKey(CurriculumLevel)
108 type = models.CharField(max_length=16, choices=TYPES.items())
111 verbose_name = _("curriculum item")
112 verbose_name_plural = _("curriculum items")
114 def __unicode__(self):
115 return self.identifier
118 def from_text(cls, identifier, title):
119 m = re.match(r"^\d+/(?P<level>[^/]+)/(?P<course>[^/]+)/"
120 "(?P<type>(?:%s))[^/]+(?P<roz>/roz)?" %
121 "|".join(cls.TYPES), identifier)
122 assert m is not None, "Curriculum identifier doesn't match template."
123 level, created = CurriculumLevel.objects.get_or_create(
124 title=m.group('level'))
125 course, created = CurriculumCourse.objects.get_or_create(
126 slug=m.group('course'),
127 defaults={'title': m.group('course').title()})
128 type_ = m.group('type')
130 title += " (zakres rozszerzony)"
133 curr = cls.objects.get(identifier=identifier)
134 except cls.DoesNotExist:
135 curr = cls(identifier=identifier)