1 # -*- coding: utf-8 -*-
2 # This file is part of EduMed, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
6 from optparse import make_option
7 from django.conf import settings
8 from django.core.management.base import BaseCommand
9 from catalogue.models import Section
13 class Command(BaseCommand):
14 option_list = BaseCommand.option_list + (
15 make_option('-q', '--quiet', action='store_false', dest='verbose', default=True,
16 help='Verbosity level; 0=minimal output, 1=normal output, 2=all output'),
18 help = 'Rebuilds downloadable packages.'
20 def build_package(self, zippath, student, verbose):
21 with open(zippath, 'w') as outf:
22 zipf = zipfile.ZipFile(outf, 'w', zipfile.ZIP_STORED)
24 for si, section in enumerate(Section.objects.all()):
27 for lesson in section.lesson_set.all():
28 advanced = lesson.level.slug == "liceum"
29 section_dir = "%d_%s%s" % (
31 " (zaawansowane)" if advanced else "")
32 if lesson.type == 'course':
39 prefix = "%s/%02d_%s/" % (
40 section_dir, ind, lesson.slug,
42 elif lesson.type == 'synthetic':
43 prefix = "%s/%s (synteza)/" % (
44 section_dir, lesson.slug)
45 elif lesson.type == 'project':
46 prefix = "%s/%s (projekt)/" % (
47 section_dir, lesson.slug)
50 section_dir, lesson.slug)
51 lesson.add_to_zip(zipf, student, prefix)
54 def handle(self, **options):
55 verbose = options.get('verbose')
58 os.path.join(settings.MEDIA_ROOT, settings.CATALOGUE_PACKAGE),
61 os.path.join(settings.MEDIA_ROOT, settings.CATALOGUE_PACKAGE_STUDENT),