add /photos/libreplanet, /videos/libreplanet pages
[mediagoblin-libreplanet.git] / mediagoblin_libreplanet / views.py
CommitLineData
724f8731
DT
1# MediaGoblin for LibrePlanet
2# Copyright (C) 2015 David Thompson <davet@gnu.org>
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU Affero General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Affero General Public License for more details.
13#
14# You should have received a copy of the GNU Affero General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17from mediagoblin import mg_globals
18from mediagoblin.db.models import MediaEntry
19from mediagoblin.db.util import media_entries_for_tag_slug
20from mediagoblin.tools.pagination import Pagination
21from mediagoblin.tools.response import render_to_response
22from mediagoblin.decorators import uses_pagination
23
44432a3b
AE
24def type_listing(media_type, title, request, page, tag=None):
25 if (tag == None):
26 cursor = MediaEntry.query
27 else:
28 cursor = media_entries_for_tag_slug(request.db, tag)
29
30 cursor = cursor.\
b1c32b81
DT
31 filter((MediaEntry.media_type == media_type)
32 & (MediaEntry.state == u'processed')).\
724f8731
DT
33 order_by(MediaEntry.created.desc())
34
35 pagination = Pagination(page, cursor)
36 media_entries = pagination()
37
38 return render_to_response(
39 request,
40 'libreplanet/listing.html',
41 {'title': title,
42 'media_entries': media_entries,
43 'pagination': pagination})
44
45
46@uses_pagination
47def image_listing(request, page):
48 return type_listing(u'mediagoblin.media_types.image', 'Photos', request, page)
49
50@uses_pagination
51def video_listing(request, page):
52 return type_listing(u'mediagoblin.media_types.video', 'Videos', request, page)
f10f1755
AE
53
54@uses_pagination
55def featured_image_listing(request, page):
56 return type_listing(u'mediagoblin.media_types.image', 'Featured Photos', request, page, "featured")
57
58@uses_pagination
59def featured_video_listing(request, page):
60 return type_listing(u'mediagoblin.media_types.video', 'Featured Videos', request, page, "featured")
61
e24f40c1
AE
62@uses_pagination
63def libreplanet_image_listing(request, page):
64 return type_listing(u'mediagoblin.media_types.image', 'LibrePlanet Photos', request, page, "libreplanet")
65
66@uses_pagination
67def libreplanet_video_listing(request, page):
68 return type_listing(u'mediagoblin.media_types.video', 'LibrePlanet Videos', request, page, "libreplanet")
69