예제 #1
0
파일: podcast.py 프로젝트: mmarinez/mygpo
def subscribe(request, podcast):

    if request.method == 'POST':

        # multiple UIDs from the /podcast/<slug>/subscribe
        device_uids = [k for (k, v) in request.POST.items() if k == v]

        # single UID from /podcast/<slug>
        if 'targets' in request.POST:
            devices = request.POST.get('targets')
            devices = devices.split(',')
            device_uids.extend(devices)

        for uid in device_uids:
            try:
                device = request.user.client_set.get(uid=uid)
                subscribe_podcast.delay(podcast.pk, request.user.pk,
                                        device.uid)

            except Client.DoesNotExist as e:
                messages.error(request, str(e))

        return HttpResponseRedirect(get_podcast_link_target(podcast))

    targets = get_subscribe_targets(podcast, request.user)

    return render(request, 'subscribe.html', {
        'targets': targets,
        'podcast': podcast
    })
예제 #2
0
    def sync(self):
        """ Sync the group, ie bring all members up-to-date """
        from mygpo.subscriptions.tasks import subscribe

        # get all subscribed podcasts
        podcasts = set(self.get_subscribed_podcasts())

        # bring each client up to date, it it is subscribed to all podcasts
        for client in self.client_set.all():
            missing_podcasts = self.get_missing_podcasts(client, podcasts)
            for podcast in missing_podcasts:
                subscribe.delay(podcast.pk, self.user.pk, client.uid)