fix help
[redakcja.git] / apps / catalogue / management / commands / publish.py
1 # -*- coding: utf-8 -*-
2 import sys
3 from optparse import make_option
4
5 from django.contrib.auth.models import User
6 from django.core.management.base import BaseCommand
7
8 from catalogue.models import Book
9
10
11 class Command(BaseCommand):
12     help = 'Publish lessons based on slugs in stdin'
13     option_list = BaseCommand.option_list + (
14         # make_option('-q', '--quiet', action='store_false', dest='verbose',
15         #     default=True, help='Less output'),
16         # make_option('-d', '--dry-run', action='store_true', dest='dry_run',
17         #     default=False, help="Don't actually touch anything"),
18         make_option(
19             '-u', '--username', dest='username', metavar='USER',
20             help='Assign commits to this user (required, preferably yourself).'),
21     )
22
23     def handle(self, *args, **options):
24         user = User.objects.get(username=options.get('username'))
25         slugs = [line.strip() for line in sys.stdin if line.strip()]
26         for slug in slugs:
27             lesson = Book.objects.get(slug=slug)
28             print lesson.slug
29             lesson.assert_publishable()
30             lesson.publish(user)