1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011 Free Software Foundation, Inc
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.
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.
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/>.
17 from mediagoblin
.db
.util
import DESCENDING
19 from mediagoblin
.util
import Pagination
, render_to_response
20 from mediagoblin
.decorators
import uses_pagination
24 def tag_listing(request
, page
):
25 """'Gallery'/listing for this tag slug"""
26 tag_slug
= request
.matchdict
[u
'tag']
28 cursor
= request
.db
.MediaEntry
.find(
29 {u
'state': u
'processed',
30 u
'tags.slug': tag_slug
})
31 cursor
= cursor
.sort('created', DESCENDING
)
33 pagination
= Pagination(page
, cursor
)
34 media_entries
= pagination()
36 # Take the tag "name" from the first MediaEntry's non-normalized
38 # ... this is slightly hacky looking :\
40 if media_entries
.count():
41 for tag
in media_entries
[0]['tags']:
42 if tag
['slug'] == tag_slug
:
43 tag_name
== tag
['name']
48 return render_to_response(
50 'mediagoblin/listings/tag.html',
51 {'tag_name': tag_name
,
52 'media_entries': media_entries
,
53 'pagination': pagination
})