diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 1d91a14b..8aa35ca9 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -22,7 +22,7 @@ from mediagoblin import util from mediagoblin.auth import lib as auth_lib from mediagoblin import mg_globals from mediagoblin.db import migrations -from mediagoblin.db.util import DESCENDING, ObjectId +from mediagoblin.db.util import ASCENDING, DESCENDING, ObjectId ################### # Custom validators @@ -142,6 +142,32 @@ class MediaEntry(Document): 'mediagoblin.user_pages.media_home', user=uploader['username'], media=unicode(self['_id'])) + + def url_to_prev(self, urlgen): + """ + Provide a url to the previous entry from this user, if there is one + """ + cursor = self.db.MediaEntry.find({'_id' : {"$lt": self['_id']}, + 'uploader': self['uploader']}).sort( + '_id', DESCENDING).limit(1) + + if cursor.count(): + return urlgen('mediagoblin.user_pages.media_home', + user=self.uploader()['username'], + media=unicode(cursor[0]['_id'])) + + def url_to_next(self, urlgen): + """ + Provide a url to the next entry from this user, if there is one + """ + cursor = self.db.MediaEntry.find({'_id' : {"$gt": self['_id']}, + 'uploader': self['uploader']}).sort( + '_id', ASCENDING).limit(1) + + if cursor.count(): + return urlgen('mediagoblin.user_pages.media_home', + user=self.uploader()['username'], + media=unicode(cursor[0]['_id'])) def uploader(self): return self.db.User.find_one({'_id': self['uploader']}) diff --git a/mediagoblin/db/util.py b/mediagoblin/db/util.py index 46f899f7..70c37945 100644 --- a/mediagoblin/db/util.py +++ b/mediagoblin/db/util.py @@ -30,7 +30,7 @@ document relevant to here: import copy # Imports that other modules might use -from pymongo import DESCENDING +from pymongo import ASCENDING, DESCENDING from pymongo.errors import InvalidId from mongokit import ObjectId diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index 0c13f5c4..21506ee4 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -91,6 +91,7 @@ {% endif %}