From: Radek Czajka Date: Mon, 4 Feb 2013 14:58:49 +0000 (+0100) Subject: move to librarian 1.5 IOFile, add some curriculum links X-Git-Url: https://git.mdrn.pl/edumed.git/commitdiff_plain/cd8813f7be8e11b18b7e23d217dd6404e26d07d4?ds=sidebyside move to librarian 1.5 IOFile, add some curriculum links --- diff --git a/catalogue/admin.py b/catalogue/admin.py index ffad76e..eb634c3 100755 --- a/catalogue/admin.py +++ b/catalogue/admin.py @@ -1,7 +1,11 @@ from django.contrib import admin -from .models import Section, Lesson +from .models import Attachment, Section, Lesson -admin.site.register(Section) -admin.site.register(Lesson) +class AttachmentInline(admin.TabularInline): + model = Attachment +class LessonAdmin(admin.ModelAdmin): + inlines = [AttachmentInline] +admin.site.register(Section) +admin.site.register(Lesson, LessonAdmin) diff --git a/catalogue/management/commands/importlessons.py b/catalogue/management/commands/importlessons.py index 6efd246..6252fb5 100755 --- a/catalogue/management/commands/importlessons.py +++ b/catalogue/management/commands/importlessons.py @@ -11,6 +11,7 @@ from django.core.management.base import BaseCommand from django.core.management.color import color_style from django.core.files import File +from librarian import IOFile from catalogue.models import Lesson #from search import Index @@ -26,8 +27,13 @@ class Command(BaseCommand): def import_book(self, file_path, options): verbose = options.get('verbose') - with open(file_path) as f: - lesson = Lesson.publish(f) + iofile = IOFile.from_filename(file_path) + basename, ext = file_path.rsplit('.', 1) + if os.path.isdir(basename): + for att_name in os.listdir(basename): + iofile.attachments[att_name] = IOFile.from_filename( + os.path.join(basename, att_name)) + lesson = Lesson.publish(iofile) def handle(self, *directories, **options): from django.db import transaction diff --git a/catalogue/migrations/0006_auto__add_field_attachment_slug__add_field_attachment_ext__add_unique_.py b/catalogue/migrations/0006_auto__add_field_attachment_slug__add_field_attachment_ext__add_unique_.py new file mode 100644 index 0000000..043627d --- /dev/null +++ b/catalogue/migrations/0006_auto__add_field_attachment_slug__add_field_attachment_ext__add_unique_.py @@ -0,0 +1,85 @@ +# -*- coding: utf-8 -*- +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + + +class Migration(SchemaMigration): + + def forwards(self, orm): + # Adding field 'Attachment.slug' + db.add_column('catalogue_attachment', 'slug', + self.gf('django.db.models.fields.CharField')(default='', max_length=255), + keep_default=False) + + # Adding field 'Attachment.ext' + db.add_column('catalogue_attachment', 'ext', + self.gf('django.db.models.fields.CharField')(default='', max_length=15), + keep_default=False) + + # Adding unique constraint on 'Attachment', fields ['ext', 'lesson', 'slug'] + db.create_unique('catalogue_attachment', ['ext', 'lesson_id', 'slug']) + + + def backwards(self, orm): + # Removing unique constraint on 'Attachment', fields ['ext', 'lesson', 'slug'] + db.delete_unique('catalogue_attachment', ['ext', 'lesson_id', 'slug']) + + # Deleting field 'Attachment.slug' + db.delete_column('catalogue_attachment', 'slug') + + # Deleting field 'Attachment.ext' + db.delete_column('catalogue_attachment', 'ext') + + + models = { + 'catalogue.attachment': { + 'Meta': {'unique_together': "(['lesson', 'slug', 'ext'],)", 'object_name': 'Attachment'}, + 'ext': ('django.db.models.fields.CharField', [], {'max_length': '15'}), + 'file': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'lesson': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalogue.Lesson']"}), + 'slug': ('django.db.models.fields.CharField', [], {'max_length': '255'}) + }, + 'catalogue.lesson': { + 'Meta': {'ordering': "['section', 'level', 'depth', 'order']", 'object_name': 'Lesson'}, + 'dc': ('jsonfield.fields.JSONField', [], {'default': "'{}'"}), + 'depth': ('django.db.models.fields.IntegerField', [], {}), + 'html_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'level': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['curriculum.Level']"}), + 'order': ('django.db.models.fields.IntegerField', [], {}), + 'package': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), + 'pdf': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), + 'section': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalogue.Section']"}), + 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50'}), + 'student_package': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), + 'student_pdf': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'xml_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}) + }, + 'catalogue.part': { + 'Meta': {'object_name': 'Part'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'lesson': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalogue.Lesson']"}), + 'pdf': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), + 'student_pdf': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}) + }, + 'catalogue.section': { + 'Meta': {'ordering': "['order']", 'object_name': 'Section'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'order': ('django.db.models.fields.IntegerField', [], {}), + 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50'}), + 'title': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}) + }, + 'curriculum.level': { + 'Meta': {'ordering': "['order']", 'object_name': 'Level'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'order': ('django.db.models.fields.IntegerField', [], {}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'}) + } + } + + complete_apps = ['catalogue'] \ No newline at end of file diff --git a/catalogue/models.py b/catalogue/models.py index 7b6b1b2..394e938 100644 --- a/catalogue/models.py +++ b/catalogue/models.py @@ -62,8 +62,7 @@ class Lesson(models.Model): def publish(cls, infile): from librarian.parser import WLDocument from django.core.files.base import ContentFile - # infile should be IOFile, now it's a regular file - xml = infile.read() + xml = infile.get_string() wldoc = WLDocument.from_string(xml) slug = wldoc.book_info.url.slug @@ -72,14 +71,20 @@ class Lesson(models.Model): except cls.DoesNotExist: lesson = cls(slug=slug) + lesson.attachment_set.all().delete() + for att_name, att_file in infile.attachments.items(): + try: + slug, ext = att_name.rsplit('.', 1) + except ValueError: + slug, ext = att_name, '' + attachment = lesson.attachment_set.create(slug=slug, ext=ext) + attachment.file.save(att_name, ContentFile(att_file.get_string())) + # Save XML file lesson.xml_file.save('%s.xml' % slug, ContentFile(xml), save=False) lesson.title = wldoc.book_info.title - #book.extra_info = wldoc.book_info.to_dict() - # FIXME: - #lesson.level = Level.objects.get(slug=wldoc.book_info.audience) - lesson.level = Level.objects.get(name=wldoc.book_info.audience) + lesson.level = Level.objects.get(slug=wldoc.book_info.audience) # TODO: no xml data? lesson.section = Section.objects.all()[0] lesson.order = 1 @@ -123,9 +128,18 @@ class Lesson(models.Model): class Attachment(models.Model): + slug = models.CharField(max_length=255) + ext = models.CharField(max_length=15) lesson = models.ForeignKey(Lesson) file = models.FileField(upload_to="catalogue/attachment") + class Meta: + ordering = ['slug', 'ext'] + unique_together = ['lesson', 'slug', 'ext'] + + def __unicode__(self): + return "%s.%s" % (self.slug, self.ext) + class Part(models.Model): lesson = models.ForeignKey(Lesson) diff --git a/catalogue/templates/catalogue/lesson_detail.html b/catalogue/templates/catalogue/lesson_detail.html index 9aab890..518eb53 100755 --- a/catalogue/templates/catalogue/lesson_detail.html +++ b/catalogue/templates/catalogue/lesson_detail.html @@ -1,6 +1,8 @@ {% extends "base.html" %} {% load url from future %} {% load lesson_nav person_list from catalogue_tags %} +{% load find_competence url_for_level from curriculum_tags %} + {% block title %}{{ object }}{% endblock %} @@ -51,6 +53,23 @@ + {% if object.dc.competences %} +
+ +
+ {% endif %} +

{{ object.dc.description }}

diff --git a/curriculum/admin.py b/curriculum/admin.py index 8d30cf2..d825e6f 100755 --- a/curriculum/admin.py +++ b/curriculum/admin.py @@ -11,7 +11,7 @@ class CompetenceAdmin(admin.ModelAdmin): class LevelAdmin(admin.ModelAdmin): model = Level - list_display = ['name', 'slug', 'order'] + list_display = ['name', 'group', 'slug', 'order'] class SectionAdmin(admin.ModelAdmin): model = Section diff --git a/curriculum/migrations/0002_auto__add_field_level_group.py b/curriculum/migrations/0002_auto__add_field_level_group.py new file mode 100644 index 0000000..0f7cf5d --- /dev/null +++ b/curriculum/migrations/0002_auto__add_field_level_group.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + + +class Migration(SchemaMigration): + + def forwards(self, orm): + # Adding field 'Level.group' + db.add_column('curriculum_level', 'group', + self.gf('django.db.models.fields.CharField')(default='', max_length=255), + keep_default=False) + + + def backwards(self, orm): + # Deleting field 'Level.group' + db.delete_column('curriculum_level', 'group') + + + models = { + 'curriculum.competence': { + 'Meta': {'ordering': "['order']", 'object_name': 'Competence'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'order': ('django.db.models.fields.IntegerField', [], {}), + 'section': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['curriculum.Section']"}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'}) + }, + 'curriculum.competencelevel': { + 'Meta': {'ordering': "['competence', 'level']", 'object_name': 'CompetenceLevel'}, + 'competence': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['curriculum.Competence']"}), + 'description': ('django.db.models.fields.TextField', [], {}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'level': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['curriculum.Level']"}) + }, + 'curriculum.level': { + 'Meta': {'ordering': "['order']", 'object_name': 'Level'}, + 'group': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'order': ('django.db.models.fields.IntegerField', [], {}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'}) + }, + 'curriculum.section': { + 'Meta': {'ordering': "['order']", 'object_name': 'Section'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'order': ('django.db.models.fields.IntegerField', [], {}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'}) + } + } + + complete_apps = ['curriculum'] \ No newline at end of file diff --git a/curriculum/migrations/0003_auto__chg_field_level_slug.py b/curriculum/migrations/0003_auto__chg_field_level_slug.py new file mode 100644 index 0000000..f22e753 --- /dev/null +++ b/curriculum/migrations/0003_auto__chg_field_level_slug.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + + +class Migration(SchemaMigration): + + def forwards(self, orm): + + # Changing field 'Level.slug' + db.alter_column('curriculum_level', 'slug', self.gf('django.db.models.fields.CharField')(max_length=255)) + # Removing index on 'Level', fields ['slug'] + db.delete_index('curriculum_level', ['slug']) + + + def backwards(self, orm): + # Adding index on 'Level', fields ['slug'] + db.create_index('curriculum_level', ['slug']) + + + # Changing field 'Level.slug' + db.alter_column('curriculum_level', 'slug', self.gf('django.db.models.fields.SlugField')(max_length=50)) + + models = { + 'curriculum.competence': { + 'Meta': {'ordering': "['order']", 'object_name': 'Competence'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'order': ('django.db.models.fields.IntegerField', [], {}), + 'section': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['curriculum.Section']"}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'}) + }, + 'curriculum.competencelevel': { + 'Meta': {'ordering': "['competence', 'level']", 'object_name': 'CompetenceLevel'}, + 'competence': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['curriculum.Competence']"}), + 'description': ('django.db.models.fields.TextField', [], {}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'level': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['curriculum.Level']"}) + }, + 'curriculum.level': { + 'Meta': {'ordering': "['order']", 'object_name': 'Level'}, + 'group': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'order': ('django.db.models.fields.IntegerField', [], {}), + 'slug': ('django.db.models.fields.CharField', [], {'max_length': '255'}) + }, + 'curriculum.section': { + 'Meta': {'ordering': "['order']", 'object_name': 'Section'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'order': ('django.db.models.fields.IntegerField', [], {}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'}) + } + } + + complete_apps = ['curriculum'] \ No newline at end of file diff --git a/curriculum/models.py b/curriculum/models.py index debc487..8b99f61 100644 --- a/curriculum/models.py +++ b/curriculum/models.py @@ -1,3 +1,4 @@ +from django.core.urlresolvers import reverse from django.db import models from django.utils.translation import ugettext_lazy as _ @@ -28,12 +29,21 @@ class Competence(models.Model): def __unicode__(self): return self.name + def get_absolute_url(self): + return "%s?c=%d" % (reverse("curriculum"), self.pk) + def for_level(self, level): return self.competencelevel_set.get(level=level) + @classmethod + def from_text(cls, text): + name = text.rsplit(u'\u2013', 1)[-1].strip() + return cls.objects.get(name__iexact=name) + class Level(models.Model): + group = models.CharField(_('group'), max_length=255) name = models.CharField(_('name'), max_length=255) - slug = models.SlugField(_('slug')) + slug = models.CharField(_('slug'), max_length=255) order = models.IntegerField(_('order')) class Meta: @@ -55,4 +65,7 @@ class CompetenceLevel(models.Model): verbose_name_plural = _('competences on levels') def __unicode__(self): - return "%s/%s" % (self.competence, self.level) + return u"%s/%s" % (self.competence, self.level) + + def get_absolute_url(self): + return "%s?c=%d&level=%s&d=1" % (reverse("curriculum"), self.competence.pk, self.level.slug) diff --git a/curriculum/static/curriculum/curriculum.css b/curriculum/static/curriculum/curriculum.css new file mode 100644 index 0000000..e1b5f90 --- /dev/null +++ b/curriculum/static/curriculum/curriculum.css @@ -0,0 +1,29 @@ +.curriculum-form { + border: 1px solid #ddd; + padding: 1em; + border-radius: 0.688em; + background: #ADAEAF; + color: white; } + .curriculum-form h2 { + margin: 0; } + .curriculum-form h2 a { + display: block; + color: white; } + .curriculum-form h2 a span { + display: none; } + .curriculum-form strong { + display: inline-block; + vertical-align: top; + width: 12em; } + .curriculum-form .curriculum-levels { + display: inline-block; + list-style: none; + padding: 0; + margin: 0; + width: 40em; + vertical-align: top; } + .curriculum-form .curriculum-levels li { + display: inline-block; + width: 13em; } + .curriculum-form .curriculum-section-toggler { + display: none; } diff --git a/curriculum/static/curriculum/curriculum.js b/curriculum/static/curriculum/curriculum.js new file mode 100755 index 0000000..e30375a --- /dev/null +++ b/curriculum/static/curriculum/curriculum.js @@ -0,0 +1,43 @@ +$(function() { + if (curriculum_hide_form) { + $('.curriculum-form form').hide(); + $('.curriculum-form h2 a span').show(); + } + $('.curriculum-form h2 a').click(function() { + $('.curriculum-form form').toggle('fast'); + $('span', this).toggle(); + }); + + /* show togglers */ + $('.curriculum-section-toggler').show(); + + $('.curriculum-section').each(function() { + var category = this; + + /* set up togglers */ + $('.curriculum-section-toggler', this).click(function() { + $('ul', category).toggle('fast'); + }); + + /* set up section checkboxes */ + $('.s', category).change(function() { + if ($(this).attr('checked')) { + $('ul input', category).attr('checked', 'checked'); + } + else { + $('ul input', category).removeAttr('checked'); + } + }); + + /* unset section checkbox on unselect single competence */ + $('ul input', category).change(function() { + if (!$(this).attr('checked')) { + $('.s', category).removeAttr('checked', 'checked'); + } + }); + + /* hide unused section details on start */ + if ($('.s', category).attr('checked') || !$('ul input[checked]', category).length) + $('ul', category).hide(); + }); +}); diff --git a/curriculum/static/curriculum/curriculum.scss b/curriculum/static/curriculum/curriculum.scss new file mode 100755 index 0000000..a99dc6f --- /dev/null +++ b/curriculum/static/curriculum/curriculum.scss @@ -0,0 +1,47 @@ +$px: 0.0625em; + +.curriculum-form { + border: 1px solid #ddd; + padding: 1em; + border-radius: 11*$px; + background: #ADAEAF; + color: white; + + h2 { + margin: 0; + a { + display: block; + color: white; + span {display: none;} + } + } + + strong { + display: inline-block; + vertical-align: top; + width: 12em; + } + + .curriculum-levels { + display: inline-block; + list-style: none; + padding: 0; + margin: 0; + width: 40em; + vertical-align: top; + + li { + display: inline-block; + width: 13em; + } + } + + .curriculum-section-toggler { + display: none; + } + + .categories { + + } + +} diff --git a/curriculum/templates/curriculum/competence_list.html b/curriculum/templates/curriculum/competence_list.html index cd4ad2f..70939f1 100755 --- a/curriculum/templates/curriculum/competence_list.html +++ b/curriculum/templates/curriculum/competence_list.html @@ -5,30 +5,34 @@ {% block body %}

Katalog kompetencji medialnych i informacyjnych

+
+

Przeglądaj kompetencje (rozwiń)

+

Poziom edukacyjny:

{% if errors.level %}

{{ errors.level }}

{% endif %} -edukacja formalna: -
    -{% for lev in levels %} +{% for lev_group, levels in levels.items %} + {{ lev_group }} +
      + {% for lev in levels %}
    • + {% endfor %} +
    {% endfor %} -
-edukacja ustawiczna:

Kategorie kompetencji:

{% if errors.competences %}

{{ errors.competences }}

{% endif %} -
    +
      {% for section in sections %} -
    • -
{% if chosen_competences %} +

Wybrane kompetencje – {{ level }}

+ {% for section, competences in chosen_competences.items %}

{{ section }}

{% for competence in competences %} @@ -51,4 +58,10 @@ {% endif %} -{% endblock %} \ No newline at end of file + +{% if request.GET.d %} + +{% endif %} +{% endblock %} diff --git a/curriculum/templatetags/__init__.py b/curriculum/templatetags/__init__.py new file mode 100755 index 0000000..e69de29 diff --git a/curriculum/templatetags/curriculum_tags.py b/curriculum/templatetags/curriculum_tags.py new file mode 100755 index 0000000..9981411 --- /dev/null +++ b/curriculum/templatetags/curriculum_tags.py @@ -0,0 +1,20 @@ +from django import template +from ..models import Competence + +register = template.Library() + + +@register.filter +def find_competence(text): + try: + return Competence.from_text(text) + except: + return None + +@register.filter +def url_for_level(comp, level): + try: + return comp.for_level(level).get_absolute_url() + except: + return comp.get_absolute_url() + diff --git a/curriculum/views.py b/curriculum/views.py index 32e91e0..e5d30c7 100644 --- a/curriculum/views.py +++ b/curriculum/views.py @@ -13,7 +13,11 @@ class CompetencesView(ListView): def get_context_data(self, **kwargs): context = super(CompetencesView, self).get_context_data(**kwargs) - context['levels'] = Level.objects.all() + + context['levels'] = SortedDict() + for level in Level.objects.all(): + context['levels'].setdefault(level.group, []).append(level) + context['sections'] = Section.objects.all() errors = {} diff --git a/edumed/settings.d/50-static.py b/edumed/settings.d/50-static.py index 23d963a..750caf0 100644 --- a/edumed/settings.d/50-static.py +++ b/edumed/settings.d/50-static.py @@ -22,6 +22,7 @@ PIPELINE_CSS = { 'catalogue/css/lesson.scss', 'catalogue/css/exercise.scss', 'catalogue/css/section_list.scss', + 'curriculum/curriculum.scss', ), 'output_filename': 'compressed/base.css', }, @@ -34,6 +35,7 @@ PIPELINE_JS = { 'catalogue/js/edumed.js', 'catalogue/js/carousel.js', 'sponsors/js/sponsors.js', + 'curriculum/curriculum.js', ), 'output_filename': 'compressed/base.js', },