added LP 2016 videos to the front page
[mediagoblin-libreplanet.git] / mediagoblin_libreplanet / views.py
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
17 from mediagoblin import mg_globals
18 from mediagoblin.db.models import MediaEntry
19 from mediagoblin.db.util import media_entries_for_tag_slug
20 from lp_helper import media_entries_for_tag_slug_case_insensitive
21 from mediagoblin.tools.pagination import Pagination
22 from mediagoblin.tools.response import render_to_response
23 from mediagoblin.decorators import uses_pagination
24
25 def type_listing(media_type, title, request, page, tag=None):
26 if (tag == None):
27 cursor = MediaEntry.query
28 else:
29 ## case insensitive tag search is not working yet -- sudoman
30 #cursor = media_entries_for_tag_slug_case_insensitive(request.db, tag)
31 cursor = media_entries_for_tag_slug(request.db, tag)
32
33 cursor = cursor.\
34 filter((MediaEntry.media_type == media_type)
35 & (MediaEntry.state == u'processed')).\
36 order_by(MediaEntry.created.desc())
37
38 pagination = Pagination(page, cursor)
39 media_entries = pagination()
40
41 return render_to_response(
42 request,
43 'libreplanet/listing.html',
44 {'title': title,
45 'media_entries': media_entries,
46 'pagination': pagination})
47
48
49 @uses_pagination
50 def image_listing(request, page):
51 return type_listing(u'mediagoblin.media_types.image', 'Photos', request, page)
52
53 @uses_pagination
54 def video_listing(request, page):
55 return type_listing(u'mediagoblin.media_types.video', 'Videos', request, page)
56
57
58 @uses_pagination
59 def featured_image_listing(request, page):
60 return type_listing(u'mediagoblin.media_types.image', 'Featured Photos', request, page, "featured")
61
62 @uses_pagination
63 def featured_video_listing(request, page):
64 return type_listing(u'mediagoblin.media_types.video', 'Featured Videos', request, page, "featured")
65