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 def get_absolute_url(self):
21 return "%s?s=%d" % (reverse("curriculum"), self.pk)
23 def url_for_level(self, level):
24 return "%s?s=%d&level=%s&d=1" % (reverse("curriculum"), self.pk, level.slug)
27 class Competence(models.Model):
28 section = models.ForeignKey(Section)
29 name = models.CharField(_('name'), max_length=255)
30 slug = models.SlugField(_('slug'))
31 order = models.IntegerField(_('order'))
34 ordering = ['section', 'order']
35 verbose_name = _('competence')
36 verbose_name_plural = _('competences')
38 def __unicode__(self):
41 def get_absolute_url(self):
42 return "%s?c=%d" % (reverse("curriculum"), self.pk)
44 def for_level(self, level):
45 return self.competencelevel_set.get(level=level)
47 def url_for_level(self, level):
48 return self.for_level(level).get_absolute_url()
51 def from_text(cls, text):
52 """Tries to return a Competence or a Section."""
53 parts = re.split(ur'[-\u2013]', text, 1)
55 return Section.objects.get(name__iexact=text.strip())
57 return cls.objects.get(name__iexact=parts[1].strip())
59 class Level(models.Model):
60 group = models.CharField(_('group'), max_length=255)
61 name = models.CharField(_('name'), max_length=255)
62 slug = models.CharField(_('slug'), max_length=255)
63 order = models.IntegerField(_('order'))
67 verbose_name = _('educational level')
68 verbose_name_plural = _('educational levels')
70 def __unicode__(self):
73 class CompetenceLevel(models.Model):
74 competence = models.ForeignKey(Competence)
75 level = models.ForeignKey(Level)
76 description = models.TextField(_('description'))
79 ordering = ['competence', 'level']
80 verbose_name = _('competence on level')
81 verbose_name_plural = _('competences on levels')
83 def __unicode__(self):
84 return u"%s/%s" % (self.competence, self.level)
86 def get_absolute_url(self):
87 return "%s?c=%d&level=%s&d=1" % (reverse("curriculum"), self.competence.pk, self.level.slug)
91 class CurriculumLevel(models.Model):
92 title = models.CharField(max_length=16, db_index=True)
95 verbose_name = _("curriculum level")
96 verbose_name_plural = _("curriculum levels")
98 def __unicode__(self):
102 class CurriculumCourse(models.Model):
103 title = models.CharField(max_length=255)
104 accusative = models.CharField(max_length=255)
105 slug = models.CharField(max_length=255, db_index=True)
108 verbose_name = _("curriculum course")
109 verbose_name_plural = _("curriculum courses")
112 def __unicode__(self):
116 class Curriculum(models.Model):
117 """Official curriculum."""
118 TYPES = {'c': u'Cele kształcenia', 't': u'Treści nauczania'}
120 identifier = models.CharField(max_length=255, db_index=True)
121 title = models.CharField(max_length=255)
122 course = models.ForeignKey(CurriculumCourse)
123 level = models.ForeignKey(CurriculumLevel)
124 type = models.CharField(max_length=16, choices=TYPES.items())
127 verbose_name = _("curriculum item")
128 verbose_name_plural = _("curriculum items")
130 def __unicode__(self):
131 return self.identifier
134 def from_text(cls, identifier, title):
135 m = re.match(r"^\d+/(?P<level>[^/]+)/(?P<course>[^/]+)/"
136 "(?P<type>(?:%s))[^/]+(?P<roz>/roz)?" %
137 "|".join(cls.TYPES), identifier)
138 assert m is not None, "Curriculum identifier doesn't match template."
139 level, created = CurriculumLevel.objects.get_or_create(
140 title=m.group('level'))
141 def_title = m.group('course').title()
142 course, created = CurriculumCourse.objects.get_or_create(
143 slug=m.group('course').lower(),
146 'accusative': def_title,
148 type_ = m.group('type')
150 title += " (zakres rozszerzony)"
153 curr = cls.objects.get(identifier=identifier)
154 except cls.DoesNotExist:
155 curr = cls(identifier=identifier)