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