You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mediagoblin-oyd/mediagoblin_libreplanet/views.py

63 lines
2.3 KiB

10 years ago
# 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 lp_helper import media_entries_for_tag_slug_case_insensitive
10 years ago
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_case_insensitive(request.db, tag)
cursor = cursor.\
filter((MediaEntry.media_type == media_type)
& (MediaEntry.state == u'processed')).\
10 years ago
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")