fix
[wolnelektury.git] / src / catalogue / management / commands / update_preview_status.py
1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
3 #
4 from datetime import date
5 from django.core.management.base import BaseCommand
6
7 from catalogue.models import Book
8
9
10 class Command(BaseCommand):
11     def handle(self, *args, **options):
12         for book in Book.objects.filter(preview=True, preview_until__lt=date.today()):
13             book.preview = False
14             book.save()
15             for format_ in Book.formats:
16                 media_file = book.get_media(format_)
17                 if media_file:
18                     media_file.set_readable(True)