From dfcf9b11ca2fc3173a3b6925198836b6ddaaa61c Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Fri, 21 Jun 2013 12:55:10 +0200 Subject: [PATCH 1/1] add lesson stubs --- catalogue/admin.py | 4 +- .../migrations/0012_auto__add_lessonstub.py | 96 +++++++++++++++++++ catalogue/models.py | 14 +++ .../catalogue/snippets/section_box.html | 10 +- catalogue/templatetags/catalogue_tags.py | 11 ++- 5 files changed, 130 insertions(+), 5 deletions(-) create mode 100644 catalogue/migrations/0012_auto__add_lessonstub.py diff --git a/catalogue/admin.py b/catalogue/admin.py index 0e3c635..43488ce 100755 --- a/catalogue/admin.py +++ b/catalogue/admin.py @@ -1,5 +1,5 @@ from django.contrib import admin -from .models import Attachment, Section, Lesson +from .models import Attachment, Section, Lesson, LessonStub class AttachmentInline(admin.TabularInline): model = Attachment @@ -10,3 +10,5 @@ class LessonAdmin(admin.ModelAdmin): admin.site.register(Section) admin.site.register(Lesson, LessonAdmin) +admin.site.register(LessonStub) + diff --git a/catalogue/migrations/0012_auto__add_lessonstub.py b/catalogue/migrations/0012_auto__add_lessonstub.py new file mode 100644 index 0000000..d8e53bb --- /dev/null +++ b/catalogue/migrations/0012_auto__add_lessonstub.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 model 'LessonStub' + db.create_table('catalogue_lessonstub', ( + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('section', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['catalogue.Section'], null=True, blank=True)), + ('level', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['curriculum.Level'])), + ('title', self.gf('django.db.models.fields.CharField')(max_length=255)), + ('type', self.gf('django.db.models.fields.CharField')(max_length=15, db_index=True)), + ('order', self.gf('django.db.models.fields.IntegerField')(db_index=True)), + )) + db.send_create_signal('catalogue', ['LessonStub']) + + + def backwards(self, orm): + # Deleting model 'LessonStub' + db.delete_table('catalogue_lessonstub') + + + 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'}, + 'curriculum_courses': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['curriculum.CurriculumCourse']", 'symmetrical': 'False'}), + 'dc': ('jsonfield.fields.JSONField', [], {'default': "'{}'"}), + 'html_file': ('django.db.models.fields.files.FileField', [], {'max_length': '255', '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': '255', 'null': 'True', 'blank': 'True'}), + 'pdf': ('django.db.models.fields.files.FileField', [], {'max_length': '255', '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': '255'}), + 'student_package': ('django.db.models.fields.files.FileField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), + 'student_pdf': ('django.db.models.fields.files.FileField', [], {'max_length': '255', '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': '255', 'null': 'True', 'blank': 'True'}) + }, + 'catalogue.lessonstub': { + 'Meta': {'ordering': "['section', 'level', 'order']", 'object_name': 'LessonStub'}, + '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'}), + 'section': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalogue.Section']", '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'}) + }, + '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': '255'}), + 'title': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}), + 'xml_file': ('django.db.models.fields.files.FileField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}) + }, + 'curriculum.curriculumcourse': { + 'Meta': {'ordering': "['slug']", 'object_name': 'CurriculumCourse'}, + 'accusative': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'slug': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}), + 'title': ('django.db.models.fields.CharField', [], {'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'] \ No newline at end of file diff --git a/catalogue/models.py b/catalogue/models.py index 652f972..8e6793f 100644 --- a/catalogue/models.py +++ b/catalogue/models.py @@ -250,3 +250,17 @@ class Part(models.Model): null=True, blank=True) student_pdf = models.FileField(upload_to="catalogue/part/student_pdf", null=True, blank=True) + + +class LessonStub(models.Model): + section = models.ForeignKey(Section, null=True, blank=True) + level = models.ForeignKey(Level) + title = models.CharField(max_length=255) + type = models.CharField(max_length=15, db_index=True) + order = models.IntegerField(db_index=True) + + class Meta: + ordering = ['section', 'level', 'order'] + + def __unicode__(self): + return self.title diff --git a/catalogue/templates/catalogue/snippets/section_box.html b/catalogue/templates/catalogue/snippets/section_box.html index 84f1eda..3d265bb 100755 --- a/catalogue/templates/catalogue/snippets/section_box.html +++ b/catalogue/templates/catalogue/snippets/section_box.html @@ -17,9 +17,13 @@ diff --git a/catalogue/templatetags/catalogue_tags.py b/catalogue/templatetags/catalogue_tags.py index 7003dfe..c642f18 100755 --- a/catalogue/templatetags/catalogue_tags.py +++ b/catalogue/templatetags/catalogue_tags.py @@ -24,7 +24,16 @@ def catalogue_section_buttons(): @register.inclusion_tag("catalogue/snippets/section_box.html") def section_box(section): lessons = SortedDict() - for lesson in section.lesson_set.all(): + lesson_lists = [alist for alist in [ + list(section.lesson_set.all()), + list(section.lessonstub_set.all()) + ] if alist] + while lesson_lists: + min_index, min_list = min(enumerate(lesson_lists), key=lambda x: x[1][0].order) + lesson = min_list.pop(0) + if not min_list: + lesson_lists.pop(min_index) + if lesson.level not in lessons: newdict = SortedDict() newdict['synthetic'] = [] -- 2.20.1