def edit(request, device): device_form = DeviceForm({ 'name': device.name, 'type': device.type, 'uid': device.uid }) synced_with = device.synced_with() sync_targets = list(device.get_sync_targets()) sync_form = SyncForm() sync_form.set_targets(sync_targets, _('Synchronize with the following devices')) return render( request, 'device-edit.html', { 'device': device, 'device_form': device_form, 'sync_form': sync_form, 'synced_with': synced_with, 'has_sync_targets': len(sync_targets) > 0, }, )
def edit(request, device): device_form = DeviceForm({ "name": device.name, "type": device.type, "uid": device.uid }) synced_with = device.synced_with() sync_targets = list(device.get_sync_targets()) sync_form = SyncForm() sync_form.set_targets(sync_targets, _("Synchronize with the following devices")) return render( request, "device-edit.html", { "device": device, "device_form": device_form, "sync_form": sync_form, "synced_with": synced_with, "has_sync_targets": len(sync_targets) > 0, }, )
def subscribe(request, podcast): if request.method == 'POST': form = SyncForm(request.POST) try: device = request.user.get_device_by_uid(form.get_target()) podcast.subscribe(request.user, device) except (SubscriptionException, DeviceDoesNotExist) as e: messages.error(request, str(e)) return HttpResponseRedirect(get_podcast_link_target(podcast)) request.user.sync_all() targets = podcast.subscribe_targets(request.user) form = SyncForm() form.set_targets(targets, _('Choose a device:')) return render(request, 'subscribe.html', { 'podcast': podcast, 'can_subscribe': len(targets) > 0, 'form': form })
def show(request, podcast): episodes = episode_list(podcast, request.user) max_listeners = max([e.listeners for e in episodes] + [0]) if podcast.group: group = PodcastGroup.get(podcast.group) rel_podcasts = filter(lambda x: x != podcast, group.podcasts) else: rel_podcasts = [] tags = get_tags(podcast, request.user) if request.user.is_authenticated(): request.user.sync_all() state = podcast.get_user_state(request.user) subscribed_devices = state.get_subscribed_device_ids() subscribed_devices = [request.user.get_device(x) for x in subscribed_devices] subscribe_targets = podcast.subscribe_targets(request.user) history = list(state.actions) def _set_objects(h): #TODO: optimize by indexing devices by id dev = request.user.get_device(h.device) return proxy_object(h, device=dev) history = map(_set_objects, history) is_public = state.settings.get('public_subscription', True) subscribe_form = SyncForm() subscribe_form.set_targets(subscribe_targets, '') return render(request, 'podcast.html', { 'tags': tags, 'history': history, 'podcast': podcast, 'is_public': is_public, 'devices': subscribed_devices, 'related_podcasts': rel_podcasts, 'can_subscribe': len(subscribe_targets) > 0, 'subscribe_form': subscribe_form, 'episodes': episodes, 'max_listeners': max_listeners, }) else: current_site = RequestSite(request) return render(request, 'podcast.html', { 'podcast': podcast, 'related_podcasts': rel_podcasts, 'tags': tags, 'url': current_site, 'episodes': episodes, 'max_listeners': max_listeners, })
def show(request, device): subscriptions = list(device.get_subscribed_podcasts()) synced_with = device.synced_with() sync_targets = list(device.get_sync_targets()) sync_form = SyncForm() sync_form.set_targets(sync_targets, _('Synchronize with the following devices')) return render(request, 'device.html', { 'device': device, 'sync_form': sync_form, 'subscriptions': subscriptions, 'synced_with': synced_with, 'has_sync_targets': len(sync_targets) > 0, })
def sync(request, device): form = SyncForm(request.POST) if not form.is_valid(): return HttpResponseBadRequest('invalid') try: target_uid = form.get_target() sync_target = request.user.client_set.get(uid=target_uid) device.sync_with(sync_target) except Client.DoesNotExist as e: messages.error(request, str(e)) sync_user.delay(request.user) return HttpResponseRedirect(reverse('device', args=[device.uid]))
def show(request, device): subscriptions = list(device.get_subscribed_podcasts().prefetch_related("slugs")) synced_with = device.synced_with() sync_targets = list(device.get_sync_targets()) sync_form = SyncForm() sync_form.set_targets(sync_targets, _("Synchronize with the following devices")) return render( request, "device.html", { "device": device, "sync_form": sync_form, "subscriptions": subscriptions, "synced_with": synced_with, "has_sync_targets": len(sync_targets) > 0, }, )
def edit(request, device): device_form = DeviceForm({ 'name': device.name, 'type': device.type, 'uid': device.uid }) synced_with = device.synced_with() sync_targets = list(device.get_sync_targets()) sync_form = SyncForm() sync_form.set_targets(sync_targets, _('Synchronize with the following devices')) return render(request, 'device-edit.html', { 'device': device, 'device_form': device_form, 'sync_form': sync_form, 'synced_with': synced_with, 'has_sync_targets': len(sync_targets) > 0, })
def sync(request, device): form = SyncForm(request.POST) if not form.is_valid(): return HttpResponseBadRequest('invalid') @repeat_on_conflict(['user']) def do_sync(user, device, sync_target): user.sync_devices(device, sync_target) user.save() try: target_uid = form.get_target() sync_target = request.user.get_device_by_uid(target_uid) do_sync(user=request.user, device=device, sync_target=sync_target) except DeviceDoesNotExist as e: messages.error(request, str(e)) return HttpResponseRedirect(reverse('device', args=[device.uid]))