aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mediagoblin/config_spec.ini2
-rw-r--r--mediagoblin/db/sql/fake.py28
-rw-r--r--mediagoblin/submit/views.py28
-rw-r--r--mediagoblin/user_pages/views.py21
4 files changed, 73 insertions, 6 deletions
diff --git a/mediagoblin/config_spec.ini b/mediagoblin/config_spec.ini
index eb22bc1b..dc286a27 100644
--- a/mediagoblin/config_spec.ini
+++ b/mediagoblin/config_spec.ini
@@ -50,6 +50,8 @@ allow_attachments = boolean(default=False)
# Cookie stuff
csrf_cookie_name = string(default='mediagoblin_csrftoken')
+# Push stuff
+push_urls = string_list(default=list())
[storage:publicstore]
storage_class = string(default="mediagoblin.storage.filestorage:BasicFileStorage")
diff --git a/mediagoblin/db/sql/fake.py b/mediagoblin/db/sql/fake.py
new file mode 100644
index 00000000..ba11bfee
--- /dev/null
+++ b/mediagoblin/db/sql/fake.py
@@ -0,0 +1,28 @@
+"""
+This module contains some fake classes and functions to
+calm the rest of the code base. Or provide super minimal
+implementations.
+
+Currently:
+- ObjectId "class": It's a function mostly doing
+ int(init_arg) to convert string primary keys into
+ integer primary keys.
+- InvalidId exception
+- DESCENDING "constant"
+"""
+
+
+DESCENDING = object() # a unique object for this "constant"
+
+
+class InvalidId(Exception):
+ pass
+
+
+def ObjectId(value=None):
+ if value is None:
+ return None
+ try:
+ return int(value)
+ except ValueError:
+ raise InvalidId("%r is an invalid id" % value)
diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py
index c3f5699e..b91fdb8d 100644
--- a/mediagoblin/submit/views.py
+++ b/mediagoblin/submit/views.py
@@ -20,6 +20,10 @@ from os.path import splitext
from cgi import FieldStorage
from celery import registry
+import urllib,urllib2
+import logging
+
+_log = logging.getLogger(__name__)
from werkzeug.utils import secure_filename
@@ -129,6 +133,30 @@ def submit_start(request):
# re-raise the exception
raise
+ if mg_globals.app_config["push_urls"]:
+ feed_url=request.urlgen(
+ 'mediagoblin.user_pages.atom_feed',
+ qualified=True,user=request.user.username)
+ hubparameters = {
+ 'hub.mode': 'publish',
+ 'hub.url': feed_url}
+ hubdata = urllib.urlencode(hubparameters)
+ hubheaders = {
+ "Content-type": "application/x-www-form-urlencoded",
+ "Connection": "close"}
+ for huburl in mg_globals.app_config["push_urls"]:
+ hubrequest = urllib2.Request(huburl, hubdata, hubheaders)
+ try:
+ hubresponse = urllib2.urlopen(hubrequest)
+ except urllib2.HTTPError as exc:
+ # This is not a big issue, the item will be fetched
+ # by the PuSH server next time we hit it
+ _log.warning(
+ "push url %r gave error %r", huburl, exc.code)
+ except urllib2.URLError as exc:
+ _log.warning(
+ "push url %r is unreachable %r", huburl, exc.reason)
+
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..29360e23 100644
--- a/mediagoblin/user_pages/views.py
+++ b/mediagoblin/user_pages/views.py
@@ -228,16 +228,25 @@ 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_urls"]:
+ for push_url in mg_globals.app_config["push_urls"]:
+ atomlinks.append({
+ 'rel': 'hub',
+ 'href': 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'),