|
|
|
# MediaGoblin for LibrePlanet
|
|
|
|
# Copyright (C) 2015 David Thompson <davet@gnu.org>
|
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
|
|
|
|
from mediagoblin import mg_globals
|
|
|
|
from mediagoblin.db.models import MediaEntry
|
|
|
|
from mediagoblin.db.util import media_entries_for_tag_slug
|
|
|
|
from mediagoblin.tools.pagination import Pagination
|
|
|
|
from mediagoblin.tools.response import render_to_response
|
|
|
|
from mediagoblin.decorators import uses_pagination
|
|
|
|
|
|
|
|
def type_listing(media_type, title, request, page, tag=None):
|
|
|
|
if (tag == None):
|
|
|
|
cursor = MediaEntry.query
|
|
|
|
else:
|
|
|
|
cursor = media_entries_for_tag_slug(request.db, tag)
|
|
|
|
|
|
|
|
cursor = cursor.\
|
|
|
|
filter((MediaEntry.media_type == media_type)
|
|
|
|
& (MediaEntry.state == u'processed')).\
|
|
|
|
order_by(MediaEntry.created.desc())
|
|
|
|
|
|
|
|
pagination = Pagination(page, cursor)
|
|
|
|
media_entries = pagination()
|
|
|
|
|
|
|
|
return render_to_response(
|
|
|
|
request,
|
|
|
|
'libreplanet/listing.html',
|
|
|
|
{'title': title,
|
|
|
|
'media_entries': media_entries,
|
|
|
|
'pagination': pagination})
|
|
|
|
|
|
|
|
|
|
|
|
@uses_pagination
|
|
|
|
def image_listing(request, page):
|
|
|
|
return type_listing(u'mediagoblin.media_types.image', 'Photos', request, page)
|
|
|
|
|
|
|
|
@uses_pagination
|
|
|
|
def video_listing(request, page):
|
|
|
|
return type_listing(u'mediagoblin.media_types.video', 'Videos', request, page)
|
|
|
|
|
|
|
|
|
|
|
|
@uses_pagination
|
|
|
|
def featured_image_listing(request, page):
|
|
|
|
return type_listing(u'mediagoblin.media_types.image', 'Featured Photos', request, page, "featured")
|
|
|
|
|
|
|
|
@uses_pagination
|
|
|
|
def featured_video_listing(request, page):
|
|
|
|
return type_listing(u'mediagoblin.media_types.video', 'Featured Videos', request, page, "featured")
|
|
|
|
|