From 71aba8bfb06340b9f96cb837f50d7e4c58d4ee01 Mon Sep 17 00:00:00 2001 From: Stefan Koegl Date: Sat, 10 Apr 2010 23:42:37 +0200 Subject: [PATCH] publisher can request feed-update per url request --- mygpo/publisher/templates/publisher/podcast.html | 4 ++++ mygpo/publisher/views.py | 23 +++++++++++++++++++++++ mygpo/urls.py | 1 + mygpo/web/models.py | 4 ++++ 4 files changed, 32 insertions(+) diff --git a/mygpo/publisher/templates/publisher/podcast.html b/mygpo/publisher/templates/publisher/podcast.html index 9f59ef55..697b2ddc 100644 --- a/mygpo/publisher/templates/publisher/podcast.html +++ b/mygpo/publisher/templates/publisher/podcast.html @@ -35,6 +35,10 @@

{% trans "Update from Feed" %} {% trans "(this might take a few seconds)" %}

+
To update all of your published podcasts automatically, you can request the URL (Create a new token)
+ http://{{ site }}/publisher/{{ user.username }}/update?token={{ update_token.token }} +
+

Episodes

View and edit episode data.

diff --git a/mygpo/publisher/views.py b/mygpo/publisher/views.py index 27680a0e..b08b9e50 100644 --- a/mygpo/publisher/views.py +++ b/mygpo/publisher/views.py @@ -10,6 +10,9 @@ from mygpo.publisher.forms import SearchPodcastForm, EpisodeForm, PodcastForm from mygpo.publisher.utils import listener_data, episode_listener_data, check_publisher_permission, episode_list, subscriber_data from django.contrib.sites.models import Site from mygpo.data.feeddownloader import update_podcasts +from mygpo.decorators import requires_token +from mygpo.web.models import SecurityToken +from django.contrib.auth.models import User def home(request): @@ -59,12 +62,22 @@ def podcast(request, id): elif request.method == 'GET': form = PodcastForm(instance=p) + update_token, c = SecurityToken.objects.get_or_create(user=request.user, object='published_feeds', action='update') + + if 'new_token' in request.GET: + update_token.random_token() + update_token.save() + + site = Site.objects.get_current() + return render_to_response('publisher/podcast.html', { + 'site': site, 'podcast': p, 'form': form, 'timeline_data': timeline_data, 'subscriber_data': subscription_data, 'device_data': device_data, + 'update_token': update_token, }, context_instance=RequestContext(request)) @@ -80,6 +93,16 @@ def update_podcast(request, id): return HttpResponseRedirect('/publisher/podcast/%s' % id) +@requires_token(object='published_feeds', action='update') +def update_published_podcasts(request, username): + user = get_object_or_404(User, username=username) + + published_podcasts = [p.podcast for p in PodcastPublisher.objects.filter(user=user)] + update_podcasts(published_podcasts) + + return HttpResponse('Updated:\n' + '\n'.join([p.url for p in published_podcasts]), mimetype='text/plain') + + @require_publisher def episodes(request, id): p = get_object_or_404(Podcast, pk=id) diff --git a/mygpo/urls.py b/mygpo/urls.py index e3abe96f..3a566a19 100644 --- a/mygpo/urls.py +++ b/mygpo/urls.py @@ -115,6 +115,7 @@ urlpatterns = patterns('', (r'^accounts/', include('registration.urls')), (r'^publisher/$', 'mygpo.publisher.views.home'), + (r'^publisher/(?P\w+)/update', 'mygpo.publisher.views.update_published_podcasts'), (r'^publisher/podcast/(?P\d+)$', 'mygpo.publisher.views.podcast'), (r'^publisher/podcast/(?P\d+)/update$', 'mygpo.publisher.views.update_podcast'), (r'^publisher/podcast/(?P\d+)/episodes$', 'mygpo.publisher.views.episodes'), diff --git a/mygpo/web/models.py b/mygpo/web/models.py index 51247f9a..ca7b6f55 100644 --- a/mygpo/web/models.py +++ b/mygpo/web/models.py @@ -47,3 +47,7 @@ class SecurityToken(models.Model): def __unicode__(self): return '%s %s %s: %s' % (self.user, self.object, self.action, self.token[:5]) + def random_token(self): + self.token = "".join(random.sample(string.letters+string.digits, 32)) + + -- 2.11.4.GIT