def _decorator(request, podcast_id, *args, **kwargs): try: podcast = Podcast.objects.filter(id=podcast_id) podcast = podcast.prefetch_related('slugs', 'urls').get() # if the podcast has a slug, redirect to its canonical URL if podcast.slug: return HttpResponseRedirect(get_podcast_link_target(podcast)) return f(request, podcast, *args, **kwargs) except Podcast.DoesNotExist: podcast = get_object_or_404(Podcast, merged_uuids__uuid=podcast_id) return HttpResponseRedirect(get_podcast_link_target(podcast))
def save_podcast(request, podcast): twitter = normalize_twitter(request.POST.get("twitter", "")) podcast.twitter = twitter podcast.save() messages.success(request, _("Data updated")) url = get_podcast_link_target(podcast, "podcast-publisher-detail") return HttpResponseRedirect(url)
def podcast_data(obj, domain, scaled_logo_size=64): if obj is None: raise ValueError('podcast should not be None') if isinstance(obj, SubscribedPodcast): url = obj.ref_url podcast = obj.podcast else: podcast = obj url = podcast.url subscribers = podcast.subscribers last_subscribers = podcast.subscribers scaled_logo_url = get_logo_url(podcast, scaled_logo_size) return { "url": url, "title": podcast.title, "description": podcast.description, "subscribers": subscribers, "subscribers_last_week": last_subscribers, "logo_url": podcast.logo_url, "scaled_logo_url": 'http://%s%s' % (domain, scaled_logo_url), "website": podcast.link, "mygpo_link": 'http://%s%s' % (domain, get_podcast_link_target(podcast)), }
def save_podcast(request, podcast): twitter = normalize_twitter(request.POST.get('twitter', '')) podcast.twitter = twitter podcast.save() messages.success(request, _('Data updated')) url = get_podcast_link_target(podcast, 'podcast-publisher-detail') return HttpResponseRedirect(url)
def add_tag(request, podcast): tag_str = request.GET.get('tag', '') if not tag_str: return HttpResponseBadRequest() user = request.user tags = tag_str.split(',') tags = map(str.strip, tags) tags = map(str.lower, tags) tags = list(filter(None, tags)) ContentType.objects.get_for_model(podcast) for tag in tags: # trim to maximum length tag = to_maxlength(Tag, 'tag', tag) Tag.objects.get_or_create( tag=tag, source=Tag.USER, user=user, content_type=ContentType.objects.get_for_model(podcast), object_id=podcast.id, ) if request.GET.get('next', '') == 'mytags': return HttpResponseRedirect('/tags/') return HttpResponseRedirect(get_podcast_link_target(podcast))
def remove_tag(request, podcast): tag_str = request.GET.get('tag', None) if tag_str is None: return HttpResponseBadRequest() user = request.user tags = tag_str.split(',') tags = list(map(str.strip, tags)) ContentType.objects.get_for_model(podcast) for tag in tags: Tag.objects.filter( tag__iexact=tag, source=Tag.USER, user=user, content_type=ContentType.objects.get_for_model(podcast), object_id=podcast.id, ).delete() if request.GET.get('next', '') == 'mytags': return HttpResponseRedirect('/tags/') return HttpResponseRedirect(get_podcast_link_target(podcast))
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 })
def add_tag(request, podcast): tag_str = request.GET.get('tag', '') if not tag_str: return HttpResponseBadRequest() user = request.user tags = tag_str.split(',') tags = map(str.strip, tags) ContentType.objects.get_for_model(podcast) for tag in tags: Tag.objects.get_or_create( tag=tag, source=Tag.USER, user=user, content_type=ContentType.objects.get_for_model(podcast), object_id=podcast.id, ) if request.GET.get('next', '') == 'mytags': return HttpResponseRedirect('/tags/') return HttpResponseRedirect(get_podcast_link_target(podcast))
def remove_tag(request, podcast): tag_str = request.GET.get('tag', '') if not tag_str: return HttpResponseBadRequest() user = request.user tags = tag_str.split(',') tags = list(map(str.strip, tags)) ContentType.objects.get_for_model(podcast) Tag.objects.filter( tag__in=tags, source=Tag.USER, user=user, content_type=ContentType.objects.get_for_model(podcast), object_id=podcast.id, ).delete() if request.GET.get('next', '') == 'mytags': return HttpResponseRedirect('/tags/') return HttpResponseRedirect(get_podcast_link_target(podcast))
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(podcast, request.user, device) 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, })
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 podcast_data(obj, domain, scaled_logo_size=64): if obj is None: raise ValueError('podcast should not be None') if isinstance(obj, Podcast): podcast = obj elif isinstance(obj, PodcastGroup): podcast = obj.get_podcast() subscribers = obj.subscriber_count() last_subscribers = obj.prev_subscriber_count() scaled_logo_url = obj.get_logo_url(scaled_logo_size) return { "url": podcast.url, "title": podcast.title, "description": podcast.description, "subscribers": subscribers, "subscribers_last_week": last_subscribers, "logo_url": podcast.logo_url, "scaled_logo_url": 'http://%s%s' % (domain, scaled_logo_url), "website": podcast.link, "mygpo_link": 'http://%s%s' % (domain, get_podcast_link_target(obj)), }
def podcast_data(obj, domain, scaled_logo_size=64): if obj is None: raise ValueError('podcast should not be None') if isinstance(obj, SubscribedPodcast): url = obj.ref_url podcast = obj.podcast else: podcast = obj url = podcast.url subscribers = podcast.subscribers scaled_logo_url = get_logo_url(podcast, scaled_logo_size) return { "url": url, "title": podcast.title, "author": podcast.author, "description": podcast.description, "subscribers": subscribers, "logo_url": podcast.logo_url, "scaled_logo_url": 'http://%s%s' % (domain, scaled_logo_url), "website": podcast.link, "mygpo_link": 'http://%s%s' % (domain, get_podcast_link_target(podcast)), }
def podcast_link(podcast, title=None): """ Returns the link for a single Podcast """ title = title or podcast.display_title title = strip_tags(title) return '<a href="%(target)s" title="%(title)s">%(title)s</a>' % \ dict(target=get_podcast_link_target(podcast), title=title)
def podcast_link(podcast, title=None): """ Returns the link for a single Podcast """ title = title or podcast.display_title title = strip_tags(title) return format_html('<a href="{target}" title="{title}">{title}</a>', target=get_podcast_link_target(podcast), title=title)
def set_public(request, podcast, public): settings, created = UserSettings.objects.get_or_create( user=request.user, content_type=ContentType.objects.get_for_model(podcast), object_id=podcast.pk, ) settings.set_wksetting(PUBLIC_SUB_PODCAST, public) settings.save() return HttpResponseRedirect(get_podcast_link_target(podcast))
def update_podcast(request, podcast): if not check_publisher_permission(request.user, podcast): return HttpResponseForbidden() update_podcasts( [podcast] ) url = get_podcast_link_target(podcast, 'podcast-publisher-detail') return HttpResponseRedirect(url)
def podcast_link(podcast, title=None): """ Returns the link for a single Podcast """ title = title or getattr(podcast, 'display_title', None) or podcast.title title = strip_tags(title) return '<a href="%(target)s" title="%(title)s">%(title)s</a>' % \ dict(target=get_podcast_link_target(podcast), title=title)
def update_podcast(request, podcast): if not check_publisher_permission(request.user, podcast): return HttpResponseForbidden() update_podcasts.delay([podcast.url]) messages.success(request, _('The update has been scheduled. It might take some time until the results are visible.')) url = get_podcast_link_target(podcast, 'podcast-publisher-detail') return HttpResponseRedirect(url)
def opengraph_podcast(podcast): s = OPENGRAPH_STR % dict( title = podcast.title, type = 'episode', image = 'http://gpodder.net%s' % podcast.get_logo_url(PODCAST_LOGO_BIG_SIZE), url = 'http://gpodder.net%s' % get_podcast_link_target(podcast), site_name = 'gpodder.net', admins = '0' ) return mark_safe(s)
def opengraph_podcast(podcast): s = OPENGRAPH_STR % dict( title=podcast.title, type='episode', image='http://gpodder.net%s' % get_logo_url(podcast, PODCAST_LOGO_BIG_SIZE), url='http://gpodder.net%s' % get_podcast_link_target(podcast), site_name='gpodder.net', admins='0') return mark_safe(s)
def search_podcast(request): form = SearchPodcastForm(request.POST) if form.is_valid(): podcast_url = form.cleaned_data["url"] podcast = get_object_or_404(Podcast, urls__url=podcast_url) url = get_podcast_link_target(podcast, "podcast-publisher-detail") else: url = reverse("publisher") return HttpResponseRedirect(url)
def search_podcast(request): form = SearchPodcastForm(request.POST) if form.is_valid(): podcast_url = form.cleaned_data['url'] podcast = get_objet_or_404(Podcast, urls__url=podcast_url) url = get_podcast_link_target(podcast, 'podcast-publisher-detail') else: url = reverse('publisher') return HttpResponseRedirect(url)
def opengraph_podcast(podcast): s = OPENGRAPH_STR % dict( title=podcast.title, type="episode", image="http://gpodder.net%s" % get_logo_url(podcast, PODCAST_LOGO_BIG_SIZE), url="http://gpodder.net%s" % get_podcast_link_target(podcast), site_name="gpodder.net", admins="0", ) return mark_safe(s)
def _decorator(request, slug_id, *args, **kwargs): podcast = podcast_for_slug_id(slug_id) if podcast is None: raise Http404 # redirect when Id or a merged (non-cannonical) slug is used if podcast.slug and slug_id != podcast.slug: return HttpResponseRedirect(get_podcast_link_target(podcast)) return f(request, podcast, *args, **kwargs)
def remove_tag(request, podcast): podcast_state = podcast_state_for_user_podcast(request.user, podcast) tag_str = request.GET.get('tag', '') if not tag_str: return HttpResponseBadRequest() remove_podcast_tags(podcast_state, tag_str) if request.GET.get('next', '') == 'mytags': return HttpResponseRedirect('/tags/') return HttpResponseRedirect(get_podcast_link_target(podcast))
def _decorator(request, pid, *args, **kwargs): try: pid = int(pid) except (TypeError, ValueError): raise Http404 podcast = podcast_for_oldid(pid) if not podcast: raise Http404 # redirect to Id or slug URL return HttpResponseRedirect(get_podcast_link_target(podcast))
def subscribe_url(request): url = request.GET.get('url', None) if not url: raise Http404('http://my.gpodder.org/subscribe?url=http://www.example.com/podcast.xml') url = normalize_feed_url(url) if not url: raise Http404('Please specify a valid url') podcast = Podcast.objects.get_or_create_for_url(url) return HttpResponseRedirect(get_podcast_link_target(podcast, 'subscribe'))
def subscribe_url(request): url = request.GET.get('url', None) if not url: raise Http404('http://my.gpodder.org/subscribe?url=http://www.example.com/podcast.xml') url = sanitize_url(url) if url == '': raise Http404('Please specify a valid url') podcast = Podcast.for_url(url, create=True) return HttpResponseRedirect(get_podcast_link_target(podcast, 'subscribe'))
def subscribe_all(request, podcast): """ subscribe all of the user's devices to the podcast """ user = request.user devs = podcast.subscribe_targets(user) # ungroup groups devs = [dev[0] if isinstance(dev, list) else dev for dev in devs] try: podcast.subscribe(user, devs) except (SubscriptionException, DeviceDoesNotExist, ValueError) as e: messages.error(request, str(e)) return HttpResponseRedirect(get_podcast_link_target(podcast))
def search_podcast(request): form = SearchPodcastForm(request.POST) if form.is_valid(): url = form.cleaned_data['url'] podcast = podcast_for_url(url) if not podcast: raise Http404 url = get_podcast_link_target(podcast, 'podcast-publisher-detail') else: url = reverse('publisher') return HttpResponseRedirect(url)
def _decorator(request, slug, *args, **kwargs): try: podcast = Podcast.objects.filter( slugs__slug=slug, slugs__content_type=ContentType.objects.get_for_model(Podcast), ) podcast = podcast.prefetch_related('slugs', 'urls').get() except Podcast.DoesNotExist: raise Http404 # redirect when a non-cannonical slug is used if slug != podcast.slug: return HttpResponseRedirect(get_podcast_link_target(podcast)) return f(request, podcast, *args, **kwargs)
def subscribe_url(request): url = request.GET.get('url', None) if not url: raise Http404( 'http://my.gpodder.org/subscribe?url=http://www.example.com/podcast.xml' ) url = normalize_feed_url(url) if not url: raise Http404('Please specify a valid url') podcast = Podcast.objects.get_or_create_for_url(url).object return HttpResponseRedirect(get_podcast_link_target(podcast, 'subscribe'))
def unsubscribe_all(request, podcast): """ unsubscribe all of the user's devices from the podcast """ user = request.user state = podcast_state_for_user_podcast(user, podcast) dev_ids = state.get_subscribed_device_ids() devs = user.get_devices(dev_ids) # ungroup groups devs = [dev[0] if isinstance(dev, list) else dev for dev in devs] try: podcast.unsubscribe(user, devs) except (SubscriptionException, DeviceDoesNotExist, ValueError) as e: messages.error(request, str(e)) return HttpResponseRedirect(get_podcast_link_target(podcast))
def flattr_podcast(request, podcast): """ Flattrs a podcast, records an event and redirects to the podcast """ user = request.user site = RequestSite(request) now = datetime.utcnow() # do flattring via the tasks queue, but wait for the result task = flattr_thing.delay(user.pk, podcast.get_id(), site.domain, request.is_secure(), 'Podcast') success, msg = task.get() if success: messages.success(request, _("Flattr\'d")) else: messages.error(request, msg) return HttpResponseRedirect(get_podcast_link_target(podcast))
def remove_tag(request, podcast): podcast_state = podcast.get_user_state(request.user) tag_str = request.GET.get('tag', '') if not tag_str: return HttpResponseBadRequest() @repeat_on_conflict(['state']) def update(state): tags = list(state.tags) if tag_str in tags: state.tags.remove(tag_str) state.save() update(state=podcast_state) if request.GET.get('next', '') == 'mytags': return HttpResponseRedirect('/tags/') return HttpResponseRedirect(get_podcast_link_target(podcast))
def add_tag(request, podcast): podcast_state = podcast.get_user_state(request.user) tag_str = request.GET.get('tag', '') if not tag_str: return HttpResponseBadRequest() tags = tag_str.split(',') @repeat_on_conflict(['state']) def update(state): state.add_tags(tags) state.save() update(state=podcast_state) if request.GET.get('next', '') == 'mytags': return HttpResponseRedirect('/tags/') return HttpResponseRedirect(get_podcast_link_target(podcast))
def flattr_podcast(request, podcast): """ Flattrs a podcast, records an event and redirects to the podcast """ user = request.user site = RequestSite(request) # do flattring via the tasks queue, but wait for the result task = flattr_thing.delay(user, podcast.get_id(), site.domain, request.is_secure(), 'Podcast') success, msg = task.get() if success: action = SubscriptionAction() action.action = 'flattr' state = podcast_state_for_user_podcast(request.user, podcast) add_subscription_action(state, action) messages.success(request, _("Flattr\'d")) else: messages.error(request, msg) return HttpResponseRedirect(get_podcast_link_target(podcast))
def render(self, context): podcast = self.podcast.resolve(context) add_args = [arg.resolve(context) for arg in self.add_args] return get_podcast_link_target(podcast, self.view_name, add_args)
def fb_like_podcast(podcast): url = 'http://gpodder.net%s' % get_podcast_link_target(podcast) s = LIKE_BUTTON_STR % dict(url=url) return mark_safe(s)
def subscribe_all(request, podcast): """ subscribe all of the user's devices to the podcast """ user = request.user subscribe_podcast_all(podcast, user) return HttpResponseRedirect(get_podcast_link_target(podcast))
def item_link(self, item): return get_podcast_link_target(item.podcast)
def fb_like_podcast(podcast): url = "http://gpodder.net%s" % get_podcast_link_target(podcast) s = LIKE_BUTTON_STR % dict(url=url) return s
def unsubscribe_all(request, podcast): """ unsubscribe all of the user's devices from the podcast """ user = request.user unsubscribe_podcast_all.delay(podcast.pk, user.pk) return HttpResponseRedirect(get_podcast_link_target(podcast))
def unsubscribe_all(request, podcast): """ unsubscribe all of the user's devices from the podcast """ user = request.user unsubscribe_podcast_all(podcast, user) return HttpResponseRedirect(get_podcast_link_target(podcast))