fix contact digest
[edumed.git] / catalogue / management / commands / republish.py
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.
4 #
5 from optparse import make_option
6
7 import librarian
8 from django.core.management.base import BaseCommand
9
10
11 class Command(BaseCommand):
12     help = 'Republishes all lessons.'
13
14     option_list = BaseCommand.option_list + (
15         make_option('--exclude', dest='exclude', metavar="PATH", default=None,
16                     help='PATH to file with excluded lesson slugs.'),
17         make_option('--ignore-incomplete', action='store_true', dest='ignore_incomplete', default=False,
18                     help='Attachments dir path.'),
19         make_option('--dont-repackage', action='store_false', dest='repackage', default=True,
20                     help='Don\'t refresh level packages.'),
21     )
22
23     def handle(self, **options):
24         from catalogue.models import Lesson
25         from curriculum.models import Level
26
27         lessons = Lesson.objects.order_by('slug')
28
29         if options.get('exclude'):
30             slugs = [line.strip() for line in open(options['exclude'])]
31             lessons = lessons.exclude(slug__in=slugs)
32
33         for lesson in lessons:
34             print
35             print 'Republishing: %s' % lesson.slug
36             try:
37                 lesson.republish(repackage_level=False)
38             except librarian.ParseError as e:
39                 print '!!!!!! PARSE ERROR !!!!!!'
40                 print e
41
42         if options.get('repackage'):
43             print 'Rebuilding levels...'
44             for level in Level.objects.all():
45                 print level.name
46                 level.build_packages()