From: Michele Azzolari Date: Wed, 11 Jan 2012 14:48:37 +0000 (+0100) Subject: Added PuSH capability X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=5b1a7bae3c8e56ea9b512dcbba6b8a512304a956;p=mediagoblin.git Added PuSH capability --- diff --git a/mediagoblin/config_spec.ini b/mediagoblin/config_spec.ini index eb22bc1b..226356d9 100644 --- a/mediagoblin/config_spec.ini +++ b/mediagoblin/config_spec.ini @@ -50,6 +50,9 @@ allow_attachments = boolean(default=False) # Cookie stuff csrf_cookie_name = string(default='mediagoblin_csrftoken') +# Push stuff +push_enabled = boolean(default=True) +push_url = string(default='https://pubsubhubbub.appspot.com/') [storage:publicstore] storage_class = string(default="mediagoblin.storage.filestorage:BasicFileStorage") diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index dd273c7f..d5aa60fa 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -20,6 +20,7 @@ from os.path import splitext from cgi import FieldStorage from celery import registry +import urllib,urllib2 from werkzeug.utils import secure_filename @@ -125,6 +126,19 @@ def submit_start(request): # re-raise the exception raise + if mg_globals.app_config["push_enabled"]: + feed_url=request.urlgen( + 'mediagoblin.user_pages.atom_feed', + qualified=True,user=request.user.username) + hubparameters = { + 'hub.mode': 'publish', + 'hub.url': feed_url} + huburl = mg_globals.app_config["push_url"] + hubdata = urllib.urlencode(hubparameters) + hubheaders = {"Content-type": "application/x-www-form-urlencoded"} + hubrequest = urllib2.Request(huburl, hubdata,hubheaders) + hubresponse = urllib2.urlopen(hubrequest) + add_message(request, SUCCESS, _('Woohoo! Submitted!')) return redirect(request, "mediagoblin.user_pages.user_home", diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py index a234722f..ee7cfe0f 100644 --- a/mediagoblin/user_pages/views.py +++ b/mediagoblin/user_pages/views.py @@ -228,16 +228,24 @@ def atom_feed(request): """ ATOM feed id is a tag URI (see http://en.wikipedia.org/wiki/Tag_URI) """ + atomlinks = [{ + 'href': request.urlgen( + 'mediagoblin.user_pages.user_home', + qualified=True,user=request.matchdict['user']), + 'rel': 'alternate', + 'type': 'text/html' + }]; + if mg_globals.app_config["push_enabled"]: + atomlinks.append({ + 'rel': 'hub', + 'href': mg_globals.app_config["push_url"]}) + feed = AtomFeed( "MediaGoblin: Feed for user '%s'" % request.matchdict['user'], feed_url=request.url, id='tag:'+request.host+',2011:gallery.user-'+request.matchdict['user'], - links=[{ - 'href': request.urlgen( - 'mediagoblin.user_pages.user_home', - qualified=True,user=request.matchdict['user']), - 'rel': 'alternate', - 'type': 'text/html'}]) + links=atomlinks) + for entry in cursor: feed.add(entry.get('title'),