3 from django.core.urlresolvers import reverse
4 from django.db import models
5 from django.utils.translation import ugettext_lazy as _
6 from fnpdjango.utils.models.translation import add_translatable
8 class Section(models.Model):
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)
26 add_translatable(Section, {
27 'name': models.CharField(_('name'), max_length=255, default = '')
31 class Competence(models.Model):
32 section = models.ForeignKey(Section)
33 slug = models.SlugField(_('slug'))
34 order = models.IntegerField(_('order'))
37 ordering = ['section', 'order']
38 verbose_name = _('competence')
39 verbose_name_plural = _('competences')
41 def __unicode__(self):
44 def get_absolute_url(self):
45 return "%s?c=%d" % (reverse("curriculum"), self.pk)
47 def for_level(self, level):
48 return self.competencelevel_set.get(level=level)
50 def url_for_level(self, level):
51 return self.for_level(level).get_absolute_url()
54 def from_text(cls, text):
55 """Tries to return a Competence or a Section."""
56 parts = re.split(ur'[-\u2013]', text, 1)
58 return Section.objects.get(name__iexact=text.strip())
60 return cls.objects.get(name__iexact=parts[1].strip())
62 add_translatable(Competence, {
63 'name': models.CharField(_('name'), max_length=255, default = '')
67 class Level(models.Model):
68 slug = models.CharField(_('slug'), max_length=255)
69 order = models.IntegerField(_('order'))
73 verbose_name = _('educational level')
74 verbose_name_plural = _('educational levels')
76 def __unicode__(self):
79 add_translatable(Level, {
80 'name': models.CharField(_('name'), max_length=255, default = ''),
81 'group': models.CharField(_('group'), max_length=255, default = '')
85 class CompetenceLevel(models.Model):
86 competence = models.ForeignKey(Competence)
87 level = models.ForeignKey(Level)
90 ordering = ['competence', 'level']
91 verbose_name = _('competence on level')
92 verbose_name_plural = _('competences on levels')
94 def __unicode__(self):
95 return u"%s/%s" % (self.competence, self.level)
97 def get_absolute_url(self):
98 return "%s?c=%d&level=%s&d=1" % (reverse("curriculum"), self.competence.pk, self.level.slug)
100 add_translatable(CompetenceLevel, {
101 'description': models.TextField(_('description'), default = '')
105 class CurriculumLevel(models.Model):
106 title = models.CharField(max_length=16, db_index=True)
109 verbose_name = _("curriculum level")
110 verbose_name_plural = _("curriculum levels")
112 def __unicode__(self):
116 class CurriculumCourse(models.Model):
117 title = models.CharField(max_length=255)
118 accusative = models.CharField(max_length=255)
119 slug = models.CharField(max_length=255, db_index=True)
122 verbose_name = _("curriculum course")
123 verbose_name_plural = _("curriculum courses")
126 def __unicode__(self):
130 class Curriculum(models.Model):
131 """Official curriculum."""
132 TYPES = {'c': u'Cele kształcenia', 't': u'Treści nauczania'}
134 identifier = models.CharField(max_length=255, db_index=True)
135 title = models.CharField(max_length=255)
136 course = models.ForeignKey(CurriculumCourse)
137 level = models.ForeignKey(CurriculumLevel)
138 type = models.CharField(max_length=16, choices=TYPES.items())
141 verbose_name = _("curriculum item")
142 verbose_name_plural = _("curriculum items")
144 def __unicode__(self):
145 return self.identifier
148 def from_text(cls, identifier, title):
149 m = re.match(r"^\d+/(?P<level>[^/]+)/(?P<course>[^/]+)/"
150 "(?P<type>(?:%s))[^/]+(?P<roz>/roz)?" %
151 "|".join(cls.TYPES), identifier)
152 assert m is not None, "Curriculum identifier doesn't match template."
153 level, created = CurriculumLevel.objects.get_or_create(
154 title=m.group('level'))
155 def_title = m.group('course').title()
156 course, created = CurriculumCourse.objects.get_or_create(
157 slug=m.group('course').lower(),
160 'accusative': def_title,
162 type_ = m.group('type')
164 title += " (zakres rozszerzony)"
167 curr = cls.objects.get(identifier=identifier)
168 except cls.DoesNotExist:
169 curr = cls(identifier=identifier)