1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
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
22 from werkzeug
.contrib
.atom
import AtomFeed
25 def _get_tag_name_from_entries(media_entries
, tag_slug
):
27 Get a tag name from the first entry by looking it up via its slug.
29 # ... this is slightly hacky looking :\
31 if media_entries
.count():
32 for tag
in media_entries
[0]['tags']:
33 if tag
['slug'] == tag_slug
:
34 tag_name
== tag
['name']
41 def tag_listing(request
, page
):
42 """'Gallery'/listing for this tag slug"""
43 tag_slug
= request
.matchdict
[u
'tag']
45 cursor
= request
.db
.MediaEntry
.find(
46 {u
'state': u
'processed',
47 u
'tags.slug': tag_slug
})
48 cursor
= cursor
.sort('created', DESCENDING
)
50 pagination
= Pagination(page
, cursor
)
51 media_entries
= pagination()
53 tag_name
= _get_tag_name_from_entries(media_entries
, tag_slug
)
55 return render_to_response(
57 'mediagoblin/listings/tag.html',
58 {'tag_slug': tag_slug
,
60 'media_entries': media_entries
,
61 'pagination': pagination
})
64 ATOM_DEFAULT_NR_OF_UPDATED_ITEMS
= 15
66 def tag_atom_feed(request
):
68 generates the atom feed with the tag images
70 tag_slug
= request
.matchdict
[u
'tag']
72 cursor
= request
.db
.MediaEntry
.find(
73 {u
'state': u
'processed',
74 u
'tags.slug': tag_slug
})
75 cursor
= cursor
.sort('created', DESCENDING
)
76 cursor
= cursor
.limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS
)
79 "MediaGoblin: Feed for tag '%s'" % tag_slug
,
84 feed
.add(entry
.get('title'),
85 entry
.get('description_html'),
87 author
=entry
.uploader()['username'],
88 updated
=entry
.get('created'),
89 url
=entry
.url_for_self(request
.urlgen
))
91 return feed
.get_response()