some curriculum
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Thu, 10 Jan 2013 15:51:12 +0000 (16:51 +0100)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Thu, 10 Jan 2013 15:51:12 +0000 (16:51 +0100)
curriculum/models.py
curriculum/templates/curriculum/competence_list.html
curriculum/views.py

index 399536b..debc487 100644 (file)
@@ -28,6 +28,9 @@ class Competence(models.Model):
     def __unicode__(self):
         return self.name
 
     def __unicode__(self):
         return self.name
 
+    def for_level(self, level):
+        return self.competencelevel_set.get(level=level)
+
 class Level(models.Model):
     name = models.CharField(_('name'), max_length=255)
     slug = models.SlugField(_('slug'))
 class Level(models.Model):
     name = models.CharField(_('name'), max_length=255)
     slug = models.SlugField(_('slug'))
index 7e50338..cd4ad2f 100755 (executable)
@@ -1,9 +1,54 @@
 {% extends "base.html" %}
 
 {% extends "base.html" %}
 
-{% block title %}Katalog kompetencji{% endblock %}
+{% block title %}Katalog kompetencji medialnych i informacyjnych{% endblock %}
 
 {% block body %}
 
 {% block body %}
-<h1>Katalog kompetencji</h1>
+<h1>Katalog kompetencji medialnych i informacyjnych</h1>
 
 
+<form>
+<h3>Poziom edukacyjny:</h3>
+{% if errors.level %}<p class="error">{{ errors.level }}</p>{% endif %}
+<strong>edukacja formalna:</strong>
+<ul>
+{% for lev in levels %}
+    <li><label><input type="radio" name="level" value="{{ lev.slug }}"
+        {% if lev == level %}checked="checked"{% endif %} />
+        {{ lev }}</label></li>
+{% endfor %}
+</ul>
+<strong>edukacja ustawiczna:</strong>
+
+<h3>Kategorie kompetencji:</h3>
+{% if errors.competences %}<p class="error">{{ errors.competences }}</p>{% endif %}
+<ul>
+{% for section in sections %}
+    <li>
+    <label><input type="checkbox" name="s" value="{{ section.pk }}"
+        {% if section.pk in sect_ids %}checked="checked"{% endif %} /> {{ section }}</label>
+        <span class="curriculum-section-toggler" >(rozwiń)</span>
+    <ul>
+    {% for competence in section.competence_set.all %}
+        <li><label><input type="checkbox" name="c" value="{{ competence.pk }}"
+            {% if competence.pk in comp_ids %}checked="checked"{% endif %} />
+            {{ competence }}</label></li>
+    {% endfor %}
+    </ul>
+    </li>
+{% endfor %}
+</ul>
+<button>Pokaż</button>
+</form>
+
+{% if chosen_competences %}
+
+{% for section, competences in chosen_competences.items %}
+    <h3>{{ section }}</h3>
+    {% for competence in competences %}
+        <h4>{{ competence }}</h4>
+        {{ competence.for_level_.description }}
+    {% endfor %}
+{% endfor %}
+
+{% endif %}
 
 {% endblock %}
\ No newline at end of file
 
 {% endblock %}
\ No newline at end of file
index 4239f11..32e91e0 100644 (file)
@@ -1,19 +1,59 @@
-from .models import Competence, Section, Level
-
-
+from django.db import models
 from django.views.generic import DetailView, ListView
 from django.views.generic import DetailView, ListView
+from django.utils.datastructures import SortedDict
+from .models import Competence, Section, Level, CompetenceLevel
+
 
 class CompetenceDetailView(DetailView):
     model = Competence
 
 
 class CompetenceDetailView(DetailView):
     model = Competence
 
+
 class CompetencesView(ListView):
     model = Competence
 
     def get_context_data(self, **kwargs):
 class CompetencesView(ListView):
     model = Competence
 
     def get_context_data(self, **kwargs):
-        print 'kwargs', kwargs
         context = super(CompetencesView, self).get_context_data(**kwargs)
         context = super(CompetencesView, self).get_context_data(**kwargs)
+        context['levels'] = Level.objects.all()
+        context['sections'] = Section.objects.all()
+
+        errors = {}
+
+        try:
+            level = Level.objects.get(slug=self.request.GET.get('level'))
+        except Level.DoesNotExist:
+            level = None
+        context['level'] = level
+
+        comp_ids = set()
+        for c in self.request.GET.getlist('c'):
+            try:
+                comp_ids.add(int(c))
+            except ValueError:
+                pass
+        context['comp_ids'] = comp_ids
+        sect_ids = set()
+        for c in self.request.GET.getlist('s'):
+            try:
+                sect_ids.add(int(c))
+            except ValueError:
+                pass
+        context['sect_ids'] = sect_ids
 
 
-        queryset = self.get_queryset()
+        if not (comp_ids or sect_ids):
+            if level:
+                errors["competences"] = "Please!"
+        elif level is None:
+            errors["level"] = "Please!"
+        else:
+            chosen_competences = SortedDict()
+            for competence in Competence.objects.filter(
+                    models.Q(pk__in=comp_ids) | models.Q(section__pk__in=sect_ids)):
+                try:
+                    competence.for_level_ = competence.for_level(level)
+                except CompetenceLevel.DoesNotExist:
+                    pass
+                chosen_competences.setdefault(competence.section, []).append(competence)
+            context['chosen_competences'] = chosen_competences
 
 
+        context["errors"] = errors
         return context
         return context
-