aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tools
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/tools')
l---------mediagoblin/tools/extlib/wtf_html5.py1
-rw-r--r--mediagoblin/tools/pagination.py3
-rw-r--r--mediagoblin/tools/pluginapi.py3
-rw-r--r--mediagoblin/tools/processing.py89
-rw-r--r--mediagoblin/tools/translate.py22
5 files changed, 97 insertions, 21 deletions
diff --git a/mediagoblin/tools/extlib/wtf_html5.py b/mediagoblin/tools/extlib/wtf_html5.py
new file mode 120000
index 00000000..5028c599
--- /dev/null
+++ b/mediagoblin/tools/extlib/wtf_html5.py
@@ -0,0 +1 @@
+../../../extlib/flask-wtf/html5.py \ No newline at end of file
diff --git a/mediagoblin/tools/pagination.py b/mediagoblin/tools/pagination.py
index ff7d4cad..50e59070 100644
--- a/mediagoblin/tools/pagination.py
+++ b/mediagoblin/tools/pagination.py
@@ -59,7 +59,6 @@ class Pagination(object):
self.active_id = jump_to_id
break
-
def __call__(self):
"""
Returns slice of objects for the requested page
@@ -96,7 +95,7 @@ class Pagination(object):
"""
Get a page url by adding a page= parameter to the base url
"""
- new_get_params = copy.copy(get_params or {})
+ new_get_params = dict(get_params) or {}
new_get_params['page'] = page_no
return "%s?%s" % (
base_url, urllib.urlencode(new_get_params))
diff --git a/mediagoblin/tools/pluginapi.py b/mediagoblin/tools/pluginapi.py
index 7c1e108b..1752dfc8 100644
--- a/mediagoblin/tools/pluginapi.py
+++ b/mediagoblin/tools/pluginapi.py
@@ -125,6 +125,7 @@ class PluginManager(object):
def register_route(self, route):
"""Registers a single route"""
+ _log.debug('registering route: {0}'.format(route))
self.routes.append(route)
def get_routes(self):
@@ -162,7 +163,7 @@ def register_routes(routes):
Be careful when designing your route urls. If they clash with
core urls, then it could result in DISASTER!
"""
- if isinstance(routes, (tuple, list)):
+ if isinstance(routes, list):
for route in routes:
PluginManager().register_route(route)
else:
diff --git a/mediagoblin/tools/processing.py b/mediagoblin/tools/processing.py
new file mode 100644
index 00000000..cff4cb9d
--- /dev/null
+++ b/mediagoblin/tools/processing.py
@@ -0,0 +1,89 @@
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import logging
+import json
+import traceback
+
+from urllib2 import urlopen, Request, HTTPError
+from urllib import urlencode
+
+from mediagoblin.tools.common import TESTS_ENABLED
+
+_log = logging.getLogger(__name__)
+
+TESTS_CALLBACKS = {}
+
+
+def create_post_request(url, data, **kw):
+ '''
+ Issue a HTTP POST request.
+
+ Args:
+ url: The URL to which the POST request should be issued
+ data: The data to be send in the body of the request
+ **kw:
+ data_parser: The parser function that is used to parse the `data`
+ argument
+ '''
+ data_parser = kw.get('data_parser', urlencode)
+ headers = kw.get('headers', {})
+
+ return Request(url, data_parser(data), headers=headers)
+
+
+def json_processing_callback(entry):
+ '''
+ Send an HTTP post to the registered callback url, if any.
+ '''
+ if not entry.processing_metadata:
+ _log.debug('No processing callback for {0}'.format(entry))
+ return
+
+ url = entry.processing_metadata[0].callback_url
+
+ _log.debug('Sending processing callback for {0} ({1})'.format(
+ entry,
+ url))
+
+ headers = {
+ 'Content-Type': 'application/json'}
+
+ data = {
+ 'id': entry.id,
+ 'state': entry.state}
+
+ # Trigger testing mode, no callback will be sent
+ if url.endswith('secrettestmediagoblinparam'):
+ TESTS_CALLBACKS.update({url: data})
+ return True
+
+ request = create_post_request(
+ url,
+ data,
+ headers=headers,
+ data_parser=json.dumps)
+
+ try:
+ urlopen(request)
+ _log.debug('Processing callback for {0} sent'.format(entry))
+
+ return True
+ except HTTPError:
+ _log.error('Failed to send callback: {0}'.format(
+ traceback.format_exc()))
+
+ return False
diff --git a/mediagoblin/tools/translate.py b/mediagoblin/tools/translate.py
index 5ab62a07..01cabe6a 100644
--- a/mediagoblin/tools/translate.py
+++ b/mediagoblin/tools/translate.py
@@ -60,31 +60,17 @@ def get_locale_from_request(request):
Figure out what target language is most appropriate based on the
request
"""
- request_form = request.GET or request.POST
+ request_form = request.GET or request.form
if request_form.has_key('lang'):
return locale_to_lower_upper(request_form['lang'])
- # Your routing can explicitly specify a target language
- matchdict = request.matchdict or {}
-
- if matchdict.has_key('locale'):
- target_lang = matchdict['locale']
- elif request.session.has_key('target_lang'):
+ if 'target_lang' in request.session:
target_lang = request.session['target_lang']
# Pull the first acceptable language or English
else:
- # WebOb recently changed how it handles determining best language.
- # Here's a compromise commit that handles either/or...
- if hasattr(request.accept_language, "best_matches"):
- accept_lang_matches = request.accept_language.best_matches()
- if accept_lang_matches:
- target_lang = accept_lang_matches[0]
- else:
- target_lang = 'en'
- else:
- target_lang = request.accept.best_match(
- request.accept_language, 'en')
+ # TODO: Internationalization broken
+ target_lang = 'en'
return locale_to_lower_upper(target_lang)