From 996389725d454494a8e0046f6b7b4f03d9407463 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Wed, 6 Feb 2013 12:01:21 +0100 Subject: [PATCH] Importing whole sections. --- catalogue/admin.py | 1 + .../management/commands/importlessons.py | 22 ++++- ...d_lesson_type__chg_field_lesson_section.py | 96 +++++++++++++++++++ .../0008_auto__del_field_lesson_depth.py | 72 ++++++++++++++ .../0009_auto__add_field_section_xml_file.py | 73 ++++++++++++++ catalogue/models.py | 60 ++++++++++-- .../static/catalogue/css/section_list.css | 31 +++--- .../static/catalogue/css/section_list.scss | 24 +++-- .../templates/catalogue/lesson_detail.html | 9 +- .../templates/catalogue/section_list.html | 12 ++- .../catalogue/snippets/section_box.html | 15 ++- catalogue/templatetags/catalogue_tags.py | 18 ++-- 12 files changed, 383 insertions(+), 50 deletions(-) create mode 100644 catalogue/migrations/0007_auto__add_field_lesson_type__chg_field_lesson_section.py create mode 100644 catalogue/migrations/0008_auto__del_field_lesson_depth.py create mode 100644 catalogue/migrations/0009_auto__add_field_section_xml_file.py diff --git a/catalogue/admin.py b/catalogue/admin.py index eb634c3..0e3c635 100755 --- a/catalogue/admin.py +++ b/catalogue/admin.py @@ -6,6 +6,7 @@ class AttachmentInline(admin.TabularInline): class LessonAdmin(admin.ModelAdmin): inlines = [AttachmentInline] + list_display = ['title', 'section', 'type'] admin.site.register(Section) admin.site.register(Lesson, LessonAdmin) diff --git a/catalogue/management/commands/importlessons.py b/catalogue/management/commands/importlessons.py index 6252fb5..1d65d18 100755 --- a/catalogue/management/commands/importlessons.py +++ b/catalogue/management/commands/importlessons.py @@ -12,7 +12,7 @@ from django.core.management.color import color_style from django.core.files import File from librarian import IOFile -from catalogue.models import Lesson +from catalogue.models import Lesson, Section #from search import Index @@ -73,9 +73,23 @@ class Command(BaseCommand): sys.stdout.flush() # Import book files - self.import_book(file_path, options) - files_imported += 1 - transaction.commit() + try: + self.import_book(file_path, options) + files_imported += 1 + transaction.commit() + except Section.IncompleteError: + if file_name not in postponed or postponed[file_name] < files_imported: + # Push it back into the queue, maybe the missing lessons will show up. + if verbose > 0: + print self.style.NOTICE('Waiting for missing lessons.') + files.append(file_name) + postponed[file_name] = files_imported + else: + # We're in a loop, nothing's being imported - some lesson is really missing. + raise e + except BaseException, e: + print e + files_skipped += 1 # Print results print diff --git a/catalogue/migrations/0007_auto__add_field_lesson_type__chg_field_lesson_section.py b/catalogue/migrations/0007_auto__add_field_lesson_type__chg_field_lesson_section.py new file mode 100644 index 0000000..25204db --- /dev/null +++ b/catalogue/migrations/0007_auto__add_field_lesson_type__chg_field_lesson_section.py @@ -0,0 +1,96 @@ +# -*- 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 'Lesson.type' + db.add_column('catalogue_lesson', 'type', + self.gf('django.db.models.fields.CharField')(default='course', max_length=15, db_index=True), + keep_default=False) + + # Changing field 'Lesson.section' + db.alter_column('catalogue_lesson', 'section_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['catalogue.Section'], null=True)) + # Adding index on 'Lesson', fields ['order'] + db.create_index('catalogue_lesson', ['order']) + + if not db.dry_run: + orm.Lesson.objects.filter(depth=0).update(type='synthetic') + + + def backwards(self, orm): + # Removing index on 'Lesson', fields ['order'] + db.delete_index('catalogue_lesson', ['order']) + + # Deleting field 'Lesson.type' + db.delete_column('catalogue_lesson', 'type') + + section = 0 + if not db.dry_run: + orm.Lesson.objects.filter(type='synthetic').update(depth=0) + try: + section = orm.Section.objects.all()[0] + except orm.Section.DoesNotExist: + pass + + # Changing field 'Lesson.section' + db.alter_column('catalogue_lesson', 'section_id', + self.gf('django.db.models.fields.related.ForeignKey')(default=section, to=orm['catalogue.Section'])) + + + models = { + 'catalogue.attachment': { + 'Meta': {'ordering': "['slug', 'ext']", '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', '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', [], {'db_index': 'True'}), + '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']", 'null': 'True', 'blank': 'True'}), + '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'}), + 'type': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}), + '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'}, + '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'}) + } + } + + complete_apps = ['catalogue'] diff --git a/catalogue/migrations/0008_auto__del_field_lesson_depth.py b/catalogue/migrations/0008_auto__del_field_lesson_depth.py new file mode 100644 index 0000000..4bd650f --- /dev/null +++ b/catalogue/migrations/0008_auto__del_field_lesson_depth.py @@ -0,0 +1,72 @@ +# -*- 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): + # Deleting field 'Lesson.depth' + db.delete_column('catalogue_lesson', 'depth') + + + def backwards(self, orm): + # Adding field 'Lesson.depth' + db.add_column('catalogue_lesson', 'depth', + self.gf('django.db.models.fields.IntegerField')(default=1), + keep_default=False) + + + models = { + 'catalogue.attachment': { + 'Meta': {'ordering': "['slug', 'ext']", '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', 'order']", 'object_name': 'Lesson'}, + 'dc': ('jsonfield.fields.JSONField', [], {'default': "'{}'"}), + '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', [], {'db_index': 'True'}), + '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']", 'null': 'True', 'blank': 'True'}), + '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'}), + 'type': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}), + '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'}, + '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'}) + } + } + + complete_apps = ['catalogue'] diff --git a/catalogue/migrations/0009_auto__add_field_section_xml_file.py b/catalogue/migrations/0009_auto__add_field_section_xml_file.py new file mode 100644 index 0000000..6686e5c --- /dev/null +++ b/catalogue/migrations/0009_auto__add_field_section_xml_file.py @@ -0,0 +1,73 @@ +# -*- 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 'Section.xml_file' + db.add_column('catalogue_section', 'xml_file', + self.gf('django.db.models.fields.files.FileField')(max_length=100, null=True, blank=True), + keep_default=False) + + + def backwards(self, orm): + # Deleting field 'Section.xml_file' + db.delete_column('catalogue_section', 'xml_file') + + + models = { + 'catalogue.attachment': { + 'Meta': {'ordering': "['slug', 'ext']", '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', 'order']", 'object_name': 'Lesson'}, + 'dc': ('jsonfield.fields.JSONField', [], {'default': "'{}'"}), + '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', [], {'db_index': 'True'}), + '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']", 'null': 'True', 'blank': 'True'}), + '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'}), + 'type': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}), + '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'}), + 'xml_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}) + }, + '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'}) + } + } + + complete_apps = ['catalogue'] \ No newline at end of file diff --git a/catalogue/models.py b/catalogue/models.py index 394e938..e5ee3a9 100644 --- a/catalogue/models.py +++ b/catalogue/models.py @@ -9,30 +9,68 @@ class Section(models.Model): title = models.CharField(max_length=255, unique=True) slug = models.SlugField(unique=True) order = models.IntegerField() + xml_file = models.FileField(upload_to="catalogue/section/xml", + null=True, blank=True) class Meta: ordering = ['order'] + class IncompleteError(BaseException): + pass + def __unicode__(self): return self.title def get_absolute_url(self): return "%s#%s" % (reverse("catalogue_lessons"), self.slug) + @classmethod + def publish(cls, infile): + from librarian.parser import WLDocument + from django.core.files.base import ContentFile + xml = infile.get_string() + wldoc = WLDocument.from_string(xml) + + try: + lessons = [Lesson.objects.get(slug=part.slug) + for part in wldoc.book_info.parts] + except Lesson.DoesNotExist, e: + raise cls.IncompleteError(e) + + slug = wldoc.book_info.url.slug + try: + section = cls.objects.get(slug=slug) + except cls.DoesNotExist: + section = cls(slug=slug, order=0) + + # Save XML file + section.xml_file.save('%s.xml' % slug, ContentFile(xml), save=False) + section.title = wldoc.book_info.title + section.save() + + section.lesson_set.all().update(section=None) + for i, lesson in enumerate(lessons): + lesson.section = section + lesson.order = i + lesson.save() + + return section + + def syntetic_lesson(self): try: - return self.lesson_set.filter(depth=0)[0] + return self.lesson_set.filter(type='synthetic')[0] except IndexError: return None class Lesson(models.Model): - section = models.ForeignKey(Section) + section = models.ForeignKey(Section, null=True, blank=True) level = models.ForeignKey(Level) title = models.CharField(max_length=255) slug = models.SlugField(unique=True) - depth = models.IntegerField() - order = models.IntegerField() + type = models.CharField(max_length=15, db_index=True) + order = models.IntegerField(db_index=True) dc = JSONField(default='{}') xml_file = models.FileField(upload_to="catalogue/lesson/xml", @@ -49,7 +87,7 @@ class Lesson(models.Model): null=True, blank=True) class Meta: - ordering = ['section', 'level', 'depth', 'order'] + ordering = ['section', 'level', 'order'] def __unicode__(self): return self.title @@ -64,8 +102,12 @@ class Lesson(models.Model): from django.core.files.base import ContentFile xml = infile.get_string() wldoc = WLDocument.from_string(xml) - slug = wldoc.book_info.url.slug + # Check if not section metadata block. + if wldoc.book_info.parts: + return Section.publish(infile) + + slug = wldoc.book_info.url.slug try: lesson = cls.objects.get(slug=slug) except cls.DoesNotExist: @@ -85,11 +127,9 @@ class Lesson(models.Model): lesson.title = wldoc.book_info.title lesson.level = Level.objects.get(slug=wldoc.book_info.audience) - # TODO: no xml data? - lesson.section = Section.objects.all()[0] - lesson.order = 1 - lesson.depth = 1 + lesson.order = 0 lesson.populate_dc() + lesson.type = lesson.dc["type"] lesson.save() lesson.build_html() lesson.build_package() diff --git a/catalogue/static/catalogue/css/section_list.css b/catalogue/static/catalogue/css/section_list.css index 8c861a1..2446ded 100644 --- a/catalogue/static/catalogue/css/section_list.css +++ b/catalogue/static/catalogue/css/section_list.css @@ -1,22 +1,23 @@ .section-level { width: 40em; - border-radius: 0.938em; } + border-radius: 0.938em; + margin: 1em 0; } -.section-depth { +.section-type { display: inline-block; vertical-align: top; padding: 1.25em; } - .section-depth h1 { + .section-type h1 { text-transform: uppercase; margin: 0 0 1em 0; font-size: 1em; } - .section-depth .section-lessons { + .section-type .section-lessons { padding: 0 0 0 1em; } -.section-depth-0 { +.section-type-synthetic { width: 16.25em; } -.section-depth-1 { +.section-type-course { border-radius: 0 0.938em 0.938em 0; width: 18.75em; } @@ -25,19 +26,25 @@ color: #67584f; } .section-level-gimnazjum a { color: #67584f; } - .section-level-gimnazjum .section-depth-1 { + .section-level-gimnazjum .section-type-course { background: #ed7831; color: #fff; } - .section-level-gimnazjum .section-depth-1 a { + .section-level-gimnazjum .section-type-course a { color: #fff; } -.section-level-L { +.section-level-liceum { background: #f4ae83; color: #67584f; } - .section-level-L a { + .section-level-liceum a { color: #67584f; } - .section-level-L .section-depth-1 { + .section-level-liceum .section-type-course { background: #ed7831; color: #fff; } - .section-level-L .section-depth-1 a { + .section-level-liceum .section-type-course a { color: #fff; } + +.section-links { + float: right; } + +h2.section-header { + margin: 0; } diff --git a/catalogue/static/catalogue/css/section_list.scss b/catalogue/static/catalogue/css/section_list.scss index 2b0417e..23f248b 100755 --- a/catalogue/static/catalogue/css/section_list.scss +++ b/catalogue/static/catalogue/css/section_list.scss @@ -3,9 +3,10 @@ $px: 0.0625em; .section-level { width: 640*$px; border-radius: 15*$px; + margin: 1em 0; } -.section-depth { +.section-type { display: inline-block; vertical-align: top; padding: 20*$px; @@ -20,10 +21,10 @@ $px: 0.0625em; padding: 0 0 0 1em; } } -.section-depth-0 { +.section-type-synthetic { width: 300*$px - 2 * 20*$px; } -.section-depth-1 { +.section-type-course { border-radius: 0 15*$px 15*$px 0; width: 340*$px - 2 * 20*$px; } @@ -35,9 +36,9 @@ $px: 0.0625em; color: #67584f; } - .section-depth-0 { + .section-type-synthetic { } - .section-depth-1 { + .section-type-course { background: #ed7831; color: #fff; a { @@ -47,16 +48,16 @@ $px: 0.0625em; } -.section-level-L { +.section-level-liceum { background: #f4ae83; color: #67584f; a { color: #67584f; } - .section-depth-0 { + .section-type-synthetic { } - .section-depth-1 { + .section-type-course { background: #ed7831; color: #fff; a { @@ -66,3 +67,10 @@ $px: 0.0625em; } +.section-links { + float: right; +} + +h2.section-header { + margin: 0; +} diff --git a/catalogue/templates/catalogue/lesson_detail.html b/catalogue/templates/catalogue/lesson_detail.html index 518eb53..74e6c3a 100755 --- a/catalogue/templates/catalogue/lesson_detail.html +++ b/catalogue/templates/catalogue/lesson_detail.html @@ -12,22 +12,25 @@
+

Tematy

+ + + {% for object in object_list %} + +

{{ object }}

{% section_box object %} {% endfor %} diff --git a/catalogue/templates/catalogue/snippets/section_box.html b/catalogue/templates/catalogue/snippets/section_box.html index 53477cf..6a3b6ec 100755 --- a/catalogue/templates/catalogue/snippets/section_box.html +++ b/catalogue/templates/catalogue/snippets/section_box.html @@ -1,9 +1,14 @@ -{% for level, depths in lessons.items %} +{% for level, types in lessons.items %} +{% if level.slug == "liceum" %} +

Poziom zaawansowany + wróć do spisu treści +

+{% endif %}
{% spaceless %} - {% for depth, lesson_list in depths.items %} -
- {% if depth == 0 %} + {% for lesson_type, lesson_list in types.items %} +
+ {% if lesson_type == 'synthetic' %}

Lekcja syntetyczna

{% else %}

Pełny kurs

@@ -11,7 +16,7 @@
    {% for lesson in lesson_list %}
  • - {{ lesson }}{% if depth == 0 %} + {{ lesson }}{% if depth == 'synthetic' %} (przegląd całego działu w 45 minut) {% endif %}
  • diff --git a/catalogue/templatetags/catalogue_tags.py b/catalogue/templatetags/catalogue_tags.py index 5c96e32..203b794 100755 --- a/catalogue/templatetags/catalogue_tags.py +++ b/catalogue/templatetags/catalogue_tags.py @@ -26,22 +26,26 @@ def section_box(section): lessons = SortedDict() for lesson in section.lesson_set.all(): if lesson.level not in lessons: - lessons[lesson.level] = SortedDict() - if lesson.depth not in lessons[lesson.level]: - lessons[lesson.level][lesson.depth] = [] - lessons[lesson.level][lesson.depth].append(lesson) + newdict = SortedDict() + newdict['synthetic'] = [] + newdict['course'] = [] + lessons[lesson.level] = newdict + if lesson.type not in lessons[lesson.level]: + lessons[lesson.level][lesson.type] = [] + lessons[lesson.level][lesson.type].append(lesson) + print lessons return { "lessons": lessons, } @register.inclusion_tag("catalogue/snippets/lesson_nav.html") def lesson_nav(lesson): - if lesson.depth == 1: + if lesson.type == 'course': root = lesson.section - siblings = root.lesson_set.filter(depth=1) + siblings = root.lesson_set.filter(type='course') else: root = None - siblings = Lesson.objects.filter(depth=0) + siblings = Lesson.objects.filter(type=lesson.type) return { "lesson": lesson, "root": root, -- 2.20.1