Run 2to3-3.4
[mygpo.git] / mygpo / publisher / management / commands / make-publisher.py
blobf5412f11ab2fc221ebdc29cf6f8ceb8e5e7ab5a5
1 import sys
3 from django.core.management.base import BaseCommand
4 from django.contrib.auth import get_user_model
6 from mygpo.podcasts.models import Podcast
7 from mygpo.publisher.models import PublishedPodcast
10 class Command(BaseCommand):
11 """
12 Makes the specified user a publisher for the specified podcast.
14 The user is specified by its username, the podcast is specified by one of
15 its URLs.
16 """
18 def handle(self, *args, **options):
20 if len(args) < 2:
21 print('Usage: ./manage.py make-publisher <username> <podcast-url-1> [<podcast-url-2> ...]', file=sys.stderr)
22 return
24 username = args[0]
26 User = get_user_model()
27 user = User.objects.get(username=username)
28 if not user:
29 print('User %s does not exist' % username, file=sys.stderr)
30 return
32 urls = args[1:]
33 podcasts = Podcast.objects.filter(urls__url__in=urls)
34 PublishedPodcast.objects.get_or_create(user, podcasts)