63e072d3968671932cebb6ca3d89cb6bd5573274
[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 django.core.management.base import BaseCommand
6
7
8 class Command(BaseCommand):
9     help = 'Republishes all lessons.'
10
11     def handle(self, **options):
12         from catalogue.models import Lesson
13         from curriculum.models import Level
14
15         from catalogue.management.commands.importlessons import Command
16         from django.conf import settings
17         import os.path
18
19         attachments = Command.all_attachments(os.path.join(settings.MEDIA_ROOT, 'catalogue', 'attachments'))
20
21         for lesson in Lesson.objects.all():
22             print
23             print 'Republishing: %s' % lesson.slug
24             try:
25                 lesson.republish(repackage_level=False)
26             except BaseException as e:
27                 print '!!!!!! EXCEPTION !!!!!!'
28                 print e
29
30         print 'Rebuilding levels...'
31         for level in Level.objects.all():
32             level.build_packages()