diff options
-rw-r--r-- | .gitignore | 6 | ||||
-rw-r--r-- | mediagoblin/db/mongo/util.py | 11 | ||||
-rw-r--r-- | mediagoblin/db/sql/util.py | 15 | ||||
-rw-r--r-- | mediagoblin/db/util.py | 4 | ||||
-rw-r--r-- | mediagoblin/processing.py | 18 | ||||
-rw-r--r-- | mediagoblin/static/js/keyboard_navigation.js | 33 | ||||
-rw-r--r-- | mediagoblin/templates/mediagoblin/user_pages/media.html | 2 | ||||
-rw-r--r-- | mediagoblin/templates/mediagoblin/utils/prev_next.html | 4 |
8 files changed, 79 insertions, 14 deletions
@@ -19,12 +19,16 @@ /celery.db /kombu.db /server-log.txt +/mediagoblin/db/sql_switch.py # Tests /mediagoblin/tests/user_dev/ -.installed.cfg +# File extensions *.pyc *.pyo *~ *.swp + +# The legacy of buildout +.installed.cfg
\ No newline at end of file diff --git a/mediagoblin/db/mongo/util.py b/mediagoblin/db/mongo/util.py index 4daf616a..89348d98 100644 --- a/mediagoblin/db/mongo/util.py +++ b/mediagoblin/db/mongo/util.py @@ -290,3 +290,14 @@ class MigrationManager(object): self.set_current_migration(migration_number) if post_callback: post_callback(migration_number, migration_func) + + +########################## +# Random utility functions +########################## + + +def atomic_update(table, query_dict, update_values): + table.collection.update( + query_dict, + {"$set": update_values}) diff --git a/mediagoblin/db/sql/util.py b/mediagoblin/db/sql/util.py index 08602414..13bc97e1 100644 --- a/mediagoblin/db/sql/util.py +++ b/mediagoblin/db/sql/util.py @@ -1,5 +1,5 @@ # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. +# 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 @@ -16,6 +16,8 @@ import sys +from mediagoblin.db.sql.base import Session + def _simple_printer(string): """ @@ -269,3 +271,14 @@ def assure_migrations_table_setup(db): if not MigrationData.__table__.exists(db.bind): MigrationData.metadata.create_all( db.bind, tables=[MigrationData.__table__]) + + +########################## +# Random utility functions +########################## + + +def atomic_update(table, query_dict, update_values): + table.find(query_dict).update(update_values, + synchronize_session=False) + Session.commit() diff --git a/mediagoblin/db/util.py b/mediagoblin/db/util.py index 1fc949a6..73aee238 100644 --- a/mediagoblin/db/util.py +++ b/mediagoblin/db/util.py @@ -21,5 +21,7 @@ except ImportError: if use_sql: from mediagoblin.db.sql.fake import ObjectId, InvalidId, DESCENDING + from mediagoblin.db.sql.util import atomic_update else: - from mediagoblin.db.mongo.util import ObjectId, InvalidId, DESCENDING + from mediagoblin.db.mongo.util import \ + ObjectId, InvalidId, DESCENDING, atomic_update diff --git a/mediagoblin/processing.py b/mediagoblin/processing.py index a07de869..1c84c557 100644 --- a/mediagoblin/processing.py +++ b/mediagoblin/processing.py @@ -18,7 +18,7 @@ import logging from celery.task import Task -from mediagoblin.db.util import ObjectId +from mediagoblin.db.util import ObjectId, atomic_update from mediagoblin import mg_globals as mgg from mediagoblin.tools.translate import lazy_pass_to_ugettext as _ @@ -108,22 +108,22 @@ def mark_entry_failed(entry_id, exc): if isinstance(exc, BaseProcessingFail): # Looks like yes, so record information about that failure and any # metadata the user might have supplied. - mgg.database['media_entries'].update( + atomic_update(mgg.database.MediaEntry, {'_id': entry_id}, - {'$set': {u'state': u'failed', - u'fail_error': exc.exception_path, - u'fail_metadata': exc.metadata}}) + {u'state': u'failed', + u'fail_error': exc.exception_path, + u'fail_metadata': exc.metadata}) else: _log.warn("No idea what happened here, but it failed: %r", exc) # Looks like no, so just mark it as failed and don't record a # failure_error (we'll assume it wasn't handled) and don't record # metadata (in fact overwrite it if somehow it had previous info # here) - mgg.database['media_entries'].update( + atomic_update(mgg.database.MediaEntry, {'_id': entry_id}, - {'$set': {u'state': u'failed', - u'fail_error': None, - u'fail_metadata': {}}}) + {u'state': u'failed', + u'fail_error': None, + u'fail_metadata': {}}) class BaseProcessingFail(Exception): diff --git a/mediagoblin/static/js/keyboard_navigation.js b/mediagoblin/static/js/keyboard_navigation.js new file mode 100644 index 00000000..d4039a3c --- /dev/null +++ b/mediagoblin/static/js/keyboard_navigation.js @@ -0,0 +1,33 @@ +/** + * 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/>. + */ + +$(document).keydown(function(event){ + switch(event.which){ + case 37: + if($('a.navigation_left').length) { + window.location = $('a.navigation_left').attr('href'); + } + break; + case 39: + if($('a.navigation_right').length) { + window.location = $('a.navigation_right').attr('href'); + } + break; + } +}); + diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index 43f54f95..11daaac7 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -27,6 +27,8 @@ href="{{ request.staticdirect('/extlib/leaflet/leaflet.ie.css') }}" /><![endif]--> <script type="text/javascript" src="{{ request.staticdirect('/js/comment_show.js') }}"></script> + <script type="text/javascript" + src="{{ request.staticdirect('/js/keyboard_navigation.js') }}"></script> {% if app_config['geolocation_map_visible'] %} <link rel="stylesheet" diff --git a/mediagoblin/templates/mediagoblin/utils/prev_next.html b/mediagoblin/templates/mediagoblin/utils/prev_next.html index f1175ce4..9e262ed9 100644 --- a/mediagoblin/templates/mediagoblin/utils/prev_next.html +++ b/mediagoblin/templates/mediagoblin/utils/prev_next.html @@ -35,12 +35,12 @@ {% endif %} {# Likewise, this could be the very last media entry #} {% if next_entry_url %} - <a class="navigation_button" href="{{ next_entry_url }}"> + <a class="navigation_button navigation_right" href="{{ next_entry_url }}"> {% trans %}older{% endtrans %} → </a> {% else %} {# This is the last entry. display greyed-out 'next' image #} - <p class="navigation_button"> + <p class="navigation_button navigation_right"> {% trans %}older{% endtrans %} → </p> {% endif %} |