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
This commit is contained in:
parent
0e3400357d
commit
9c0fe63fad
@ -22,7 +22,7 @@ from mediagoblin import util
|
|||||||
from mediagoblin.auth import lib as auth_lib
|
from mediagoblin.auth import lib as auth_lib
|
||||||
from mediagoblin import mg_globals
|
from mediagoblin import mg_globals
|
||||||
from mediagoblin.db import migrations
|
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
|
from mediagoblin.util import Pagination
|
||||||
|
|
||||||
###################
|
###################
|
||||||
@ -154,6 +154,32 @@ class MediaEntry(Document):
|
|||||||
'mediagoblin.user_pages.media_home',
|
'mediagoblin.user_pages.media_home',
|
||||||
user=uploader['username'],
|
user=uploader['username'],
|
||||||
media=unicode(self['_id']))
|
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):
|
def uploader(self):
|
||||||
return self.db.User.find_one({'_id': self['uploader']})
|
return self.db.User.find_one({'_id': self['uploader']})
|
||||||
|
@ -30,7 +30,7 @@ document relevant to here:
|
|||||||
import copy
|
import copy
|
||||||
|
|
||||||
# Imports that other modules might use
|
# Imports that other modules might use
|
||||||
from pymongo import DESCENDING
|
from pymongo import ASCENDING, DESCENDING
|
||||||
from pymongo.errors import InvalidId
|
from pymongo.errors import InvalidId
|
||||||
from mongokit import ObjectId
|
from mongokit import ObjectId
|
||||||
|
|
||||||
|
@ -96,6 +96,7 @@
|
|||||||
|
|
||||||
<div class="grid_4 omega media_sidebar">
|
<div class="grid_4 omega media_sidebar">
|
||||||
<p>This is a sidebar! Yay!</p>
|
<p>This is a sidebar! Yay!</p>
|
||||||
|
{% include "mediagoblin/utils/prev_next.html" %}
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>Sorry, no such media found.<p/>
|
<p>Sorry, no such media found.<p/>
|
||||||
|
45
mediagoblin/templates/mediagoblin/utils/prev_next.html
Normal file
45
mediagoblin/templates/mediagoblin/utils/prev_next.html
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
{#
|
||||||
|
# GNU MediaGoblin -- federated, autonomous media hosting
|
||||||
|
# Copyright (C) 2011 Free Software Foundation, Inc
|
||||||
|
#
|
||||||
|
# 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/>.
|
||||||
|
#}
|
||||||
|
|
||||||
|
{# Provide navigation links to neighboring media entries, if possible #}
|
||||||
|
{% set prev_entry_url = media.url_to_prev(request.urlgen) %}
|
||||||
|
{% set next_entry_url = media.url_to_next(request.urlgen) %}
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{# There are no previous entries for the very first media entry #}
|
||||||
|
{% if prev_entry_url %}
|
||||||
|
<a href="{{ prev_entry_url }}">
|
||||||
|
{# TODO - insert 'Previous' and 'X' image sources #}
|
||||||
|
Previous
|
||||||
|
</a>
|
||||||
|
{% else %}
|
||||||
|
{# This is the first entry. display greyed-out 'previous' image #}
|
||||||
|
X
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{# Likewise, this could be the very last media entry #}
|
||||||
|
{% if next_entry_url %}
|
||||||
|
<a href="{{ next_entry_url }}">
|
||||||
|
{# TODO - insert 'Next' and 'X' image sources #}
|
||||||
|
Next
|
||||||
|
</a>
|
||||||
|
{% else %}
|
||||||
|
{# This is the last entry. display greyed-out 'next' image #}
|
||||||
|
X
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
Loading…
x
Reference in New Issue
Block a user