assign publisher permissions via web interface
[mygpo.git] / mygpo / publisher / management / commands / make-publisher.py
blobf891a745ff95a2b67fbd05ec43aaecd6b8b0af16
1 import sys
3 from django.core.management.base import BaseCommand
5 from mygpo.decorators import repeat_on_conflict
6 from mygpo.core.models import Podcast
7 from mygpo.users.models import User
8 from mygpo.db.couchdb.podcast import podcast_for_url
9 from mygpo.db.couchdb.user import add_published_objs
12 class Command(BaseCommand):
13 """
14 Makes the specified user a publisher for the specified podcast.
16 The user is specified by its username, the podcast is specified by one of
17 its URLs.
18 """
20 def handle(self, *args, **options):
22 if len(args) < 2:
23 print >> sys.stderr, 'Usage: ./manage.py make-publisher <username> <podcast-url-1> [<podcast-url-2> ...]'
24 return
26 username = args[0]
28 user = User.get_user(username)
29 if not user:
30 print >> sys.stderr, 'User %s does not exist' % username
31 return
33 urls = args[1:]
34 podcasts = map(podcast_for_url, urls)
35 ids = map(Podcast.get_id, podcasts)
36 add_published_objs(user, ids)