Added PuSH capability
authorMichele Azzolari <macno@macno.org>
Wed, 11 Jan 2012 14:48:37 +0000 (15:48 +0100)
committerMichele Azzolari <macno@macno.org>
Wed, 11 Jan 2012 14:48:37 +0000 (15:48 +0100)
mediagoblin/config_spec.ini
mediagoblin/submit/views.py
mediagoblin/user_pages/views.py

index eb22bc1be3078f04bfb333a29f6a09c4461e1397..226356d9682ec8f89e4f1e34ae53d51347f9a825 100644 (file)
@@ -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")
index dd273c7f8ca03156f6d39bf7836577a0e0e3c104..d5aa60fa148784ec1dd78b0671869d5dbb1f6bff 100644 (file)
@@ -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",
index a234722fcf0253c6d59fb0c33f03f3c03ea6a2db..ee7cfe0fa307009b4a96ac329426f9ca9e2187f5 100644 (file)
@@ -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'),