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
.tools
.pagination
import Pagination
20 from mediagoblin
.tools
.response
import render_to_response
21 from mediagoblin
.decorators
import uses_pagination
23 from werkzeug
.contrib
.atom
import AtomFeed
26 def _get_tag_name_from_entries(media_entries
, tag_slug
):
28 Get a tag name from the first entry by looking it up via its slug.
30 # ... this is slightly hacky looking :\
32 if media_entries
.count():
33 for tag
in media_entries
[0]['tags']:
34 if tag
['slug'] == tag_slug
:
35 tag_name
== tag
['name']
42 def tag_listing(request
, page
):
43 """'Gallery'/listing for this tag slug"""
44 tag_slug
= request
.matchdict
[u
'tag']
46 cursor
= request
.db
.MediaEntry
.find(
47 {u
'state': u
'processed',
48 u
'tags.slug': tag_slug
})
49 cursor
= cursor
.sort('created', DESCENDING
)
51 pagination
= Pagination(page
, cursor
)
52 media_entries
= pagination()
54 tag_name
= _get_tag_name_from_entries(media_entries
, tag_slug
)
56 return render_to_response(
58 'mediagoblin/listings/tag.html',
59 {'tag_slug': tag_slug
,
61 'media_entries': media_entries
,
62 'pagination': pagination
})
65 ATOM_DEFAULT_NR_OF_UPDATED_ITEMS
= 15
67 def tag_atom_feed(request
):
69 generates the atom feed with the tag images
71 tag_slug
= request
.matchdict
[u
'tag']
73 cursor
= request
.db
.MediaEntry
.find(
74 {u
'state': u
'processed',
75 u
'tags.slug': tag_slug
})
76 cursor
= cursor
.sort('created', DESCENDING
)
77 cursor
= cursor
.limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS
)
80 "MediaGoblin: Feed for tag '%s'" % tag_slug
,
85 feed
.add(entry
.get('title'),
86 entry
.get('description_html'),
88 author
=entry
.uploader()['username'],
89 updated
=entry
.get('created'),
90 url
=entry
.url_for_self(request
.urlgen
))
92 return feed
.get_response()