aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/db/models.py
diff options
context:
space:
mode:
authorCaleb Forbes Davis V <caldavis@gmail.com>2011-07-02 06:15:58 -0500
committerCaleb Forbes Davis V <caldavis@gmail.com>2011-07-02 06:15:58 -0500
commit9c0fe63fadc848b5154c7c1d4b2ff72dd05bc1c6 (patch)
treee958264fe3d34cfe35e077ea1d0a137c0af3af9d /mediagoblin/db/models.py
parent0e3400357d55caf9099f4288ce8aef90eff7867c (diff)
downloadmediagoblin-9c0fe63fadc848b5154c7c1d4b2ff72dd05bc1c6.tar.lz
mediagoblin-9c0fe63fadc848b5154c7c1d4b2ff72dd05bc1c6.tar.xz
mediagoblin-9c0fe63fadc848b5154c7c1d4b2ff72dd05bc1c6.zip
adds previous and next links in the sidebar
Feature #401 - previous/next navigation on media pages * media.html includes a new prev_next.html template containing the links * prev_next.html calls functions added to the media model to retrieve the appropriate objects from the database, formatted with urlgen * a small change to util.py brings ASCENDING into the mix
Diffstat (limited to 'mediagoblin/db/models.py')
-rw-r--r--mediagoblin/db/models.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py
index bf825a23..cfd83430 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
from mediagoblin.util import Pagination
###################
@@ -154,6 +154,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']})