X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=mediagoblin%2Flistings%2Fviews.py;h=fa6b5ba779be9af4c559561ece6432d057becac9;hb=2a01c5e793b218add8b1b8d9c9ed84952930b1bc;hp=5a09de4350d33789e292f80c17fecb4c555f025a;hpb=99d2ac1d83962fb4dc38f01d63d2ad4036226765;p=mediagoblin.git diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index 5a09de43..fa6b5ba7 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -1,5 +1,5 @@ # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -14,11 +14,13 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from mediagoblin.db.util import DESCENDING - +from mediagoblin import mg_globals +from mediagoblin.db.models import MediaEntry +from mediagoblin.db.util import media_entries_for_tag_slug +from mediagoblin.decorators import uses_pagination +from mediagoblin.plugins.api.tools import get_media_file_paths from mediagoblin.tools.pagination import Pagination from mediagoblin.tools.response import render_to_response -from mediagoblin.decorators import uses_pagination from werkzeug.contrib.atom import AtomFeed @@ -29,12 +31,13 @@ def _get_tag_name_from_entries(media_entries, tag_slug): """ # ... this is slightly hacky looking :\ tag_name = tag_slug - if media_entries.count(): - for tag in media_entries[0]['tags']: + + for entry in media_entries: + for tag in entry.tags: if tag['slug'] == tag_slug: - tag_name == tag['name'] + tag_name = tag['name'] break - + break return tag_name @@ -43,10 +46,8 @@ def tag_listing(request, page): """'Gallery'/listing for this tag slug""" tag_slug = request.matchdict[u'tag'] - cursor = request.db.MediaEntry.find( - {u'state': u'processed', - u'tags.slug': tag_slug}) - cursor = cursor.sort('created', DESCENDING) + cursor = media_entries_for_tag_slug(request.db, tag_slug) + cursor = cursor.order_by(MediaEntry.created.desc()) pagination = Pagination(page, cursor) media_entries = pagination() @@ -65,29 +66,71 @@ def tag_listing(request, page): ATOM_DEFAULT_NR_OF_UPDATED_ITEMS = 15 -def tag_atom_feed(request): +def atom_feed(request): """ generates the atom feed with the tag images """ - tag_slug = request.matchdict[u'tag'] - - cursor = request.db.MediaEntry.find( - {u'state': u'processed', - u'tags.slug': tag_slug}) - cursor = cursor.sort('created', DESCENDING) + tag_slug = request.matchdict.get(u'tag') + feed_title = "MediaGoblin Feed" + if tag_slug: + feed_title += " for tag '%s'" % tag_slug + link = request.urlgen('mediagoblin.listings.tags_listing', + qualified=True, tag=tag_slug ) + cursor = media_entries_for_tag_slug(request.db, tag_slug) + else: # all recent item feed + feed_title += " for all recent items" + link = request.urlgen('index', qualified=True) + cursor = MediaEntry.query.filter_by(state=u'processed') + cursor = cursor.order_by(MediaEntry.created.desc()) cursor = cursor.limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS) + + """ + ATOM feed id is a tag URI (see http://en.wikipedia.org/wiki/Tag_URI) + """ + atomlinks = [{ + 'href': link, + 'rel': 'alternate', + 'type': 'text/html'}] + + if mg_globals.app_config["push_urls"]: + for push_url in mg_globals.app_config["push_urls"]: + atomlinks.append({ + 'rel': 'hub', + 'href': push_url}) + feed = AtomFeed( - "MediaGoblin: Feed for tag '%s'" % tag_slug, + feed_title, feed_url=request.url, - url=request.host_url) + id=link, + links=atomlinks) for entry in cursor: - feed.add(entry.get('title'), - entry.get('description_html'), + # Include a thumbnail image in content. + file_urls = get_media_file_paths(entry.media_files, request.urlgen) + if 'thumb' in file_urls: + content = ' {desc}'.format( + thumb=file_urls['thumb'], desc=entry.description_html) + else: + content = entry.description_html + + feed.add( + entry.get('title'), + content, + id=entry.url_for_self(request.urlgen, qualified=True), content_type='html', - author=entry.get_uploader()['username'], + author={ + 'name': entry.get_actor.username, + 'uri': request.urlgen( + 'mediagoblin.user_pages.user_home', + qualified=True, + user=entry.get_actor.username)}, updated=entry.get('created'), - url=entry.url_for_self(request.urlgen)) + links=[{ + 'href': entry.url_for_self( + request.urlgen, + qualified=True), + 'rel': 'alternate', + 'type': 'text/html'}]) return feed.get_response()