From 71454fd351bcc18662168bd89d6876ea498c3715 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 31 Jul 2011 20:45:49 -0500 Subject: Added tag listing views. Also added routing, added templates, etc. --- mediagoblin/listings/__init__.py | 19 ++++++++++++++ mediagoblin/listings/routing.py | 25 +++++++++++++++++++ mediagoblin/listings/views.py | 53 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 mediagoblin/listings/__init__.py create mode 100644 mediagoblin/listings/routing.py create mode 100644 mediagoblin/listings/views.py (limited to 'mediagoblin/listings') diff --git a/mediagoblin/listings/__init__.py b/mediagoblin/listings/__init__.py new file mode 100644 index 00000000..fbccb9b8 --- /dev/null +++ b/mediagoblin/listings/__init__.py @@ -0,0 +1,19 @@ +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011 Free Software Foundation, Inc +# +# 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +""" +Non-user listing views and routing should go in this submodule. +""" diff --git a/mediagoblin/listings/routing.py b/mediagoblin/listings/routing.py new file mode 100644 index 00000000..90580601 --- /dev/null +++ b/mediagoblin/listings/routing.py @@ -0,0 +1,25 @@ +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011 Free Software Foundation, Inc +# +# 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + + +from routes.route import Route + +tag_routes = [ + # Route('mediagoblin.listings.tags_home', "/", + # controller="mediagoblin.listings.views:tags_home"), + Route('mediagoblin.listings.tags_listing', "/{tag}/", + controller="mediagoblin.listings.views:tag_listing")] + diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py new file mode 100644 index 00000000..cdb3db31 --- /dev/null +++ b/mediagoblin/listings/views.py @@ -0,0 +1,53 @@ +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011 Free Software Foundation, Inc +# +# 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# 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.util import Pagination, render_to_response +from mediagoblin.decorators import uses_pagination + + +@uses_pagination +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) + + pagination = Pagination(page, cursor) + media_entries = pagination() + + # Take the tag "name" from the first MediaEntry's non-normalized + # tag naming. + # ... this is slightly hacky looking :\ + tag_name = tag_slug + if media_entries.count(): + for tag in media_entries[0]['tags']: + if tag['slug'] == tag_slug: + tag_name == tag['name'] + break + else: + tag_name = tag_slug + + return render_to_response( + request, + 'mediagoblin/listings/tag.html', + {'tag_name': tag_name, + 'media_entries': media_entries, + 'pagination': pagination}) -- cgit v1.2.3 From 1a897068725233b607d377b713b733c6d5084477 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 31 Jul 2011 21:24:33 -0500 Subject: Added tags atom feed and linked it in the appropriate places --- mediagoblin/listings/routing.py | 5 +++- mediagoblin/listings/views.py | 62 +++++++++++++++++++++++++++++++++-------- 2 files changed, 54 insertions(+), 13 deletions(-) (limited to 'mediagoblin/listings') diff --git a/mediagoblin/listings/routing.py b/mediagoblin/listings/routing.py index 90580601..61dd5210 100644 --- a/mediagoblin/listings/routing.py +++ b/mediagoblin/listings/routing.py @@ -21,5 +21,8 @@ tag_routes = [ # Route('mediagoblin.listings.tags_home', "/", # controller="mediagoblin.listings.views:tags_home"), Route('mediagoblin.listings.tags_listing', "/{tag}/", - controller="mediagoblin.listings.views:tag_listing")] + controller="mediagoblin.listings.views:tag_listing"), + Route('mediagoblin.listings.tag_atom_feed', "/{tag}/atom/", + controller="mediagoblin.listings.views:tag_atom_feed"), + ] diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index cdb3db31..aade7e64 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -19,6 +19,23 @@ from mediagoblin.db.util import DESCENDING from mediagoblin.util import Pagination, render_to_response from mediagoblin.decorators import uses_pagination +from werkzeug.contrib.atom import AtomFeed + + +def _get_tag_name_from_entries(media_entries, tag_slug): + """ + Get a tag name from the first entry by looking it up via its slug. + """ + # ... this is slightly hacky looking :\ + tag_name = tag_slug + if media_entries.count(): + for tag in media_entries[0]['tags']: + if tag['slug'] == tag_slug: + tag_name == tag['name'] + break + + return tag_name + @uses_pagination def tag_listing(request, page): @@ -33,21 +50,42 @@ def tag_listing(request, page): pagination = Pagination(page, cursor) media_entries = pagination() - # Take the tag "name" from the first MediaEntry's non-normalized - # tag naming. - # ... this is slightly hacky looking :\ - tag_name = tag_slug - if media_entries.count(): - for tag in media_entries[0]['tags']: - if tag['slug'] == tag_slug: - tag_name == tag['name'] - break - else: - tag_name = tag_slug + tag_name = _get_tag_name_from_entries(media_entries, tag_slug) return render_to_response( request, 'mediagoblin/listings/tag.html', - {'tag_name': tag_name, + {'tag_slug': tag_slug, + 'tag_name': tag_name, 'media_entries': media_entries, 'pagination': pagination}) + + +ATOM_DEFAULT_NR_OF_UPDATED_ITEMS = 15 + +def tag_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) + cursor = cursor.limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS) + + feed = AtomFeed( + "MediaGoblin: Feed for tag '%s'" % tag_slug, + feed_url=request.url, + url=request.host_url) + + for entry in cursor: + feed.add(entry.get('title'), + entry.get('description_html'), + content_type='html', + author=entry.uploader()['username'], + updated=entry.get('created'), + url=entry.url_for_self(request.urlgen)) + + return feed.get_response() -- cgit v1.2.3 From 12a100e4d8bdda7bd2353403a7e08e3a94669498 Mon Sep 17 00:00:00 2001 From: Will Kahn-Greene Date: Thu, 1 Sep 2011 20:49:54 -0400 Subject: 508. Updates copyright/license information --- mediagoblin/listings/__init__.py | 2 +- mediagoblin/listings/routing.py | 2 +- mediagoblin/listings/views.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'mediagoblin/listings') diff --git a/mediagoblin/listings/__init__.py b/mediagoblin/listings/__init__.py index fbccb9b8..0c53acf5 100644 --- a/mediagoblin/listings/__init__.py +++ b/mediagoblin/listings/__init__.py @@ -1,5 +1,5 @@ # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011 Free Software Foundation, Inc +# Copyright (C) 2011 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 diff --git a/mediagoblin/listings/routing.py b/mediagoblin/listings/routing.py index 61dd5210..b72bd015 100644 --- a/mediagoblin/listings/routing.py +++ b/mediagoblin/listings/routing.py @@ -1,5 +1,5 @@ # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011 Free Software Foundation, Inc +# Copyright (C) 2011 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 diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index aade7e64..b3384eb4 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -1,5 +1,5 @@ # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011 Free Software Foundation, Inc +# Copyright (C) 2011 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 -- cgit v1.2.3 From 152a3bfaa36d58e44979f217c5799531f780250f Mon Sep 17 00:00:00 2001 From: Aaron Williamson Date: Sat, 1 Oct 2011 18:05:44 -0400 Subject: Finished splitting util.py into separate files. --- mediagoblin/listings/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mediagoblin/listings') diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index b3384eb4..01aad803 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -16,7 +16,8 @@ from mediagoblin.db.util import DESCENDING -from mediagoblin.util import Pagination, render_to_response +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 -- cgit v1.2.3 From 243c3843bd574129caa7663e25d1a843b2d2dd30 Mon Sep 17 00:00:00 2001 From: Nathan Yergler Date: Sat, 1 Oct 2011 15:10:02 -0700 Subject: Whitespace and formatting cleanup. * Removed trailing whitespace * Line length < 80 where possible * Honor conventions on number of blank lines * Honor conventions about spaces around :, = --- mediagoblin/listings/routing.py | 1 - mediagoblin/listings/views.py | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'mediagoblin/listings') diff --git a/mediagoblin/listings/routing.py b/mediagoblin/listings/routing.py index b72bd015..234f2595 100644 --- a/mediagoblin/listings/routing.py +++ b/mediagoblin/listings/routing.py @@ -25,4 +25,3 @@ tag_routes = [ Route('mediagoblin.listings.tag_atom_feed', "/{tag}/atom/", controller="mediagoblin.listings.views:tag_atom_feed"), ] - diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index b3384eb4..2d61ee9b 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -46,7 +46,7 @@ def tag_listing(request, page): {u'state': u'processed', u'tags.slug': tag_slug}) cursor = cursor.sort('created', DESCENDING) - + pagination = Pagination(page, cursor) media_entries = pagination() @@ -63,6 +63,7 @@ def tag_listing(request, page): ATOM_DEFAULT_NR_OF_UPDATED_ITEMS = 15 + def tag_atom_feed(request): """ generates the atom feed with the tag images -- cgit v1.2.3 From 30188321531e1b0d3c78166498702bbd8c7dc2bc Mon Sep 17 00:00:00 2001 From: Elrond Date: Mon, 21 Nov 2011 21:40:48 +0100 Subject: Rename MediaEntry.uploader() to .get_uploader() The .uploader() method conflicts with the uploader database field. As we're moving to .FIELD for db field access, this is a relevant conflict. So renaming .uploader() to .get_uploader() --- mediagoblin/listings/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/listings') diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index 12e539e7..5a09de43 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -86,7 +86,7 @@ def tag_atom_feed(request): feed.add(entry.get('title'), entry.get('description_html'), content_type='html', - author=entry.uploader()['username'], + author=entry.get_uploader()['username'], updated=entry.get('created'), url=entry.url_for_self(request.urlgen)) -- cgit v1.2.3 From 5a4e3ff1e2a0f2ed451bc191c1d44bcd694b8e75 Mon Sep 17 00:00:00 2001 From: Elrond Date: Mon, 14 Nov 2011 15:39:57 +0100 Subject: Dot-Notation for Users.username --- mediagoblin/listings/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/listings') diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index 5a09de43..6b83ffcf 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -86,7 +86,7 @@ def tag_atom_feed(request): feed.add(entry.get('title'), entry.get('description_html'), content_type='html', - author=entry.get_uploader()['username'], + author=entry.get_uploader().username, updated=entry.get('created'), url=entry.url_for_self(request.urlgen)) -- cgit v1.2.3 From 05751758469a03835975dd2998aa727fa29c9a16 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sat, 24 Dec 2011 00:08:28 +0100 Subject: Turn media.get_uploader into a property sqlalchemy gives autoloading (hopefully caching) link to other objects as properties. So turn get_uploader on the current mongo based stuff into a property to ease transition. --- mediagoblin/listings/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/listings') diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index 6b83ffcf..3ecf06f4 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -86,7 +86,7 @@ def tag_atom_feed(request): feed.add(entry.get('title'), entry.get('description_html'), content_type='html', - author=entry.get_uploader().username, + author=entry.get_uploader.username, updated=entry.get('created'), url=entry.url_for_self(request.urlgen)) -- cgit v1.2.3 From 1df68a3524d92caee5601a8acc011ac8e1fe16d4 Mon Sep 17 00:00:00 2001 From: Michele Azzolari Date: Thu, 5 Jan 2012 18:48:23 +0100 Subject: Fixed #724 and added extra infos to the atom feed (author uri and links to the html version of each entry) --- mediagoblin/listings/views.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'mediagoblin/listings') diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index 3ecf06f4..ca8e8229 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -77,17 +77,33 @@ def tag_atom_feed(request): cursor = cursor.sort('created', DESCENDING) cursor = cursor.limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS) + """ + ATOM feed id is a tag URI (see http://en.wikipedia.org/wiki/Tag_URI) + """ feed = AtomFeed( "MediaGoblin: Feed for tag '%s'" % tag_slug, feed_url=request.url, - url=request.host_url) - + id='tag:'+request.host+',2011:gallery.tag-%s' % tag_slug, + links=[{'href': request.urlgen( + 'mediagoblin.listings.tags_listing', + qualified=True, tag=tag_slug ), + 'rel': 'alternate', + 'type': 'text/html'}]) for entry in cursor: feed.add(entry.get('title'), entry.get('description_html'), + id=entry.url_for_self(request.urlgen,qualified=True), content_type='html', - author=entry.get_uploader.username, + author={'name': entry.get_uploader.username, + 'uri': request.urlgen( + 'mediagoblin.user_pages.user_home', + qualified=True, user=entry.get_uploader.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() -- cgit v1.2.3 From cf29e8a824e0ef4612f1144f079c80c1d20b89e5 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Thu, 2 Feb 2012 09:44:13 -0600 Subject: It's 2012 all up in here --- mediagoblin/listings/__init__.py | 2 +- mediagoblin/listings/routing.py | 2 +- mediagoblin/listings/views.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'mediagoblin/listings') diff --git a/mediagoblin/listings/__init__.py b/mediagoblin/listings/__init__.py index 0c53acf5..3f873e0c 100644 --- a/mediagoblin/listings/__init__.py +++ b/mediagoblin/listings/__init__.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 diff --git a/mediagoblin/listings/routing.py b/mediagoblin/listings/routing.py index 234f2595..d228a727 100644 --- a/mediagoblin/listings/routing.py +++ b/mediagoblin/listings/routing.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 diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index ca8e8229..48320cb2 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 -- cgit v1.2.3 From 1e72e075f8d542f4aa1ad0262f4fd1a5645cc731 Mon Sep 17 00:00:00 2001 From: Elrond Date: Mon, 13 Feb 2012 13:42:59 +0100 Subject: Drop pre-rendered html: MediaEntry.description_html After a bit of discussion, we decided to drop the pre-rendered html from the database and render it on the fly. In another step, we will use some proper caching method to cache this stuff. This commit affects the MediaEntry.description_html part. --- mediagoblin/listings/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/listings') diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index 48320cb2..ba23fc46 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -91,7 +91,7 @@ def tag_atom_feed(request): 'type': 'text/html'}]) for entry in cursor: feed.add(entry.get('title'), - entry.get('description_html'), + entry.description_html, id=entry.url_for_self(request.urlgen,qualified=True), content_type='html', author={'name': entry.get_uploader.username, -- cgit v1.2.3 From 1b4d9edaef6d9b5650c4e54f82059f965ef75a31 Mon Sep 17 00:00:00 2001 From: Elrond Date: Fri, 16 Mar 2012 21:18:04 +0100 Subject: Fix _get_tag_name_from_entries(). Replace == by =. --- mediagoblin/listings/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/listings') diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index ba23fc46..73a0feb3 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -32,7 +32,7 @@ def _get_tag_name_from_entries(media_entries, tag_slug): if media_entries.count(): for tag in media_entries[0]['tags']: if tag['slug'] == tag_slug: - tag_name == tag['name'] + tag_name = tag['name'] break return tag_name -- cgit v1.2.3 From 1eff10fa0fbb93bf5669bbd09cb6e2ac6ad24813 Mon Sep 17 00:00:00 2001 From: Elrond Date: Fri, 16 Mar 2012 17:57:27 +0100 Subject: More efficient first element fetching and Dot-Notation. _get_tag_name_from_entries: 1) Replace: if q.count(): elem = q[0] by: for element in q: ... break this doesn't do two db queries but only one. 2) And another dose of Dot-Notation as usual. --- mediagoblin/listings/views.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'mediagoblin/listings') diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index 73a0feb3..d96b9606 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -29,11 +29,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']: + # if media_entries.count(): + for entry in media_entries: + for tag in entry.tags: if tag['slug'] == tag_slug: tag_name = tag['name'] break + break return tag_name -- cgit v1.2.3 From d8409c26a0bf40b336e036aecf3224aa74f5b8f3 Mon Sep 17 00:00:00 2001 From: Elrond Date: Fri, 16 Mar 2012 20:59:44 +0100 Subject: Fix for mongo. pymongo does not rewind a cursor after leaving a for loop. So let us do it by hand. Well. --- mediagoblin/listings/views.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'mediagoblin/listings') diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index d96b9606..5c365ed2 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -29,13 +29,16 @@ def _get_tag_name_from_entries(media_entries, tag_slug): """ # ... this is slightly hacky looking :\ tag_name = tag_slug - # if media_entries.count(): + for entry in media_entries: for tag in entry.tags: if tag['slug'] == tag_slug: tag_name = tag['name'] break break + # TODO: Remove after SQL-switch, it's mongo specific + if hasattr(media_entries, "rewind"): + media_entries.rewind() return tag_name -- cgit v1.2.3 From 07163593ee29b60b688205af14433588e42c6498 Mon Sep 17 00:00:00 2001 From: Elrond Date: Fri, 16 Mar 2012 18:13:46 +0100 Subject: Create function to search media by slug. Searching media by slug is easy on mongo. But doing the joins in sqlalchemy is not as nice. So created a function for doing it. Well, and create the same function for mongo, so that it also works. --- mediagoblin/listings/views.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'mediagoblin/listings') diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index 5c365ed2..9244293f 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -14,7 +14,7 @@ # 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.db.util import media_entries_for_tag_slug, DESCENDING from mediagoblin.tools.pagination import Pagination from mediagoblin.tools.response import render_to_response @@ -48,9 +48,7 @@ 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 = media_entries_for_tag_slug(request.db, tag_slug) cursor = cursor.sort('created', DESCENDING) pagination = Pagination(page, cursor) -- cgit v1.2.3 From cb9b2b2a6fde39c8df8ee69a3c6dc8b8022d7483 Mon Sep 17 00:00:00 2001 From: Elrond Date: Mon, 9 Apr 2012 22:43:25 +0200 Subject: Fix atom feed for tags. This one was missed. Needs to call a big sql join. Luckily the join was already implemented. --- mediagoblin/listings/views.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'mediagoblin/listings') diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index 9244293f..a8824390 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -74,9 +74,7 @@ def tag_atom_feed(request): """ tag_slug = request.matchdict[u'tag'] - cursor = request.db.MediaEntry.find( - {u'state': u'processed', - u'tags.slug': tag_slug}) + cursor = media_entries_for_tag_slug(request.db, tag_slug) cursor = cursor.sort('created', DESCENDING) cursor = cursor.limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS) -- cgit v1.2.3 From 7742dcc1fbda04c3a1c76a057a1a93a8f504502e Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Sun, 14 Oct 2012 13:46:31 +0200 Subject: Switched most stuff over from Routes Removed the Routes routing functionality and replaced it with werkzeug.routes. Most views are functional. Known issues: - Translation integration with the request object is not yet figured out. This breaks 404 pages. --- mediagoblin/listings/routing.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'mediagoblin/listings') diff --git a/mediagoblin/listings/routing.py b/mediagoblin/listings/routing.py index d228a727..d25f1c8c 100644 --- a/mediagoblin/listings/routing.py +++ b/mediagoblin/listings/routing.py @@ -14,14 +14,10 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +from mediagoblin.routing import add_route -from routes.route import Route - -tag_routes = [ - # Route('mediagoblin.listings.tags_home', "/", - # controller="mediagoblin.listings.views:tags_home"), - Route('mediagoblin.listings.tags_listing', "/{tag}/", - controller="mediagoblin.listings.views:tag_listing"), - Route('mediagoblin.listings.tag_atom_feed', "/{tag}/atom/", - controller="mediagoblin.listings.views:tag_atom_feed"), - ] +add_route('mediagoblin.listings.tags_listing', + "/tag//", + "mediagoblin.listings.views:tag_listing") +add_route('mediagoblin.listings.tag_atom_feed', "/tag//atom/", + "mediagoblin.listings.views:tag_atom_feed") -- cgit v1.2.3 From 3d9143323019e0793451eac60eef8e55c09f6c47 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 16 Dec 2012 00:50:20 +0100 Subject: Move things from routing.py to tools/routing.py This stops a cyclic import. Move add_route, mount and endpoint_to_controller into tools/routing.py and change all callers. --- mediagoblin/listings/routing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/listings') diff --git a/mediagoblin/listings/routing.py b/mediagoblin/listings/routing.py index d25f1c8c..e5683168 100644 --- a/mediagoblin/listings/routing.py +++ b/mediagoblin/listings/routing.py @@ -14,7 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from mediagoblin.routing import add_route +from mediagoblin.tools.routing import add_route add_route('mediagoblin.listings.tags_listing', "/tag//", -- cgit v1.2.3 From bc142abc5592975c08319416d0af12c108504887 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Thu, 29 Nov 2012 17:23:28 +0100 Subject: RIP out mongo Since sqlalchemy is providing our database abstraction and we have moved away from Mongo as the underlying database, it is now time to simplify things and rip out mongo. This provides the bulk of the changes, and can stand on its own. There are some followup tasks that can be done, such as removing now unneeded abstraction layers, e.g. db.sql.fake.py --- mediagoblin/listings/views.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'mediagoblin/listings') diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index a8824390..3064096c 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -36,10 +36,6 @@ def _get_tag_name_from_entries(media_entries, tag_slug): tag_name = tag['name'] break break - # TODO: Remove after SQL-switch, it's mongo specific - if hasattr(media_entries, "rewind"): - media_entries.rewind() - return tag_name -- cgit v1.2.3 From 0efe9e2796b6feb722acd075218d934aff5e841e Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Mon, 7 Jan 2013 11:15:04 +0100 Subject: Remove mediagoblin.db.sql.fake.DESCENDING This is the last remnant that requires us to keep db.sql.fake.py. Use ModelName.desc() or sqlalchemy.sql.expression.desc(column) to achieve descending sorts. Signed-off-by: Sebastian Spaeth --- mediagoblin/listings/views.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'mediagoblin/listings') diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index 3064096c..80182124 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -14,8 +14,8 @@ # 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 media_entries_for_tag_slug, DESCENDING - +from mediagoblin.db.sql.models import MediaEntry +from mediagoblin.db.util import media_entries_for_tag_slug from mediagoblin.tools.pagination import Pagination from mediagoblin.tools.response import render_to_response from mediagoblin.decorators import uses_pagination @@ -45,7 +45,7 @@ def tag_listing(request, page): tag_slug = request.matchdict[u'tag'] cursor = media_entries_for_tag_slug(request.db, tag_slug) - cursor = cursor.sort('created', DESCENDING) + cursor = cursor.order_by(MediaEntry.created.desc()) pagination = Pagination(page, cursor) media_entries = pagination() @@ -71,7 +71,7 @@ def tag_atom_feed(request): tag_slug = request.matchdict[u'tag'] cursor = media_entries_for_tag_slug(request.db, tag_slug) - cursor = cursor.sort('created', DESCENDING) + cursor = cursor.order_by(MediaEntry.created.desc()) cursor = cursor.limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS) """ -- cgit v1.2.3 From b0c8328e547288028e7e43f0ceb1fa9f7c8dac4a Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Fri, 30 Nov 2012 10:10:35 +0100 Subject: Move db.sql.models* to db.models* --- mediagoblin/listings/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/listings') diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index 80182124..d37161fc 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -14,7 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from mediagoblin.db.sql.models import MediaEntry +from mediagoblin.db.models import MediaEntry from mediagoblin.db.util import media_entries_for_tag_slug from mediagoblin.tools.pagination import Pagination from mediagoblin.tools.response import render_to_response -- cgit v1.2.3 From b624ca0f8befe7315c9079402b1f598e3f07dd21 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Tue, 27 Mar 2012 15:58:58 -0500 Subject: Adding an Atom RSS feed for all media on the server Go to /atom/ in your browser to see it. --- mediagoblin/listings/routing.py | 5 +++++ mediagoblin/listings/views.py | 24 ++++++++++++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) (limited to 'mediagoblin/listings') diff --git a/mediagoblin/listings/routing.py b/mediagoblin/listings/routing.py index e5683168..f762c6be 100644 --- a/mediagoblin/listings/routing.py +++ b/mediagoblin/listings/routing.py @@ -19,5 +19,10 @@ from mediagoblin.tools.routing import add_route add_route('mediagoblin.listings.tags_listing', "/tag//", "mediagoblin.listings.views:tag_listing") + +# Atom feeds: add_route('mediagoblin.listings.tag_atom_feed', "/tag//atom/", "mediagoblin.listings.views:tag_atom_feed") +# The all new entries feed +add_route('mediagoblin.listings.atom_feed', '/atom/', + "mediagoblin.listings.views:tag_atom_feed") diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index d37161fc..a09aa24d 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -68,22 +68,26 @@ def tag_atom_feed(request): """ generates the atom feed with the tag images """ - tag_slug = request.matchdict[u'tag'] + tag_slug = request.matchdict.get(u'tag') + feed_title = "MediaGoblin Feed" + if tag_slug: + cursor = media_entries_for_tag_slug(request.db, tag_slug) + link = request.urlgen('mediagoblin.listings.tags_listing', + qualified=True, tag=tag_slug ) + feed_title += "for tag '%s'" % tag_slug, + else: # all recent item feed + cursor = MediaEntry.query.filter_by(state=u'processed') + link = request.urlgen('index', qualified=True) + feed_title += "for all recent items" - cursor = media_entries_for_tag_slug(request.db, tag_slug) 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) - """ feed = AtomFeed( - "MediaGoblin: Feed for tag '%s'" % tag_slug, + feed_title, feed_url=request.url, - id='tag:'+request.host+',2011:gallery.tag-%s' % tag_slug, - links=[{'href': request.urlgen( - 'mediagoblin.listings.tags_listing', - qualified=True, tag=tag_slug ), + id=link, + links=[{'href': link, 'rel': 'alternate', 'type': 'text/html'}]) for entry in cursor: -- cgit v1.2.3 From ec3f1012b197128b36f8fc5dcde14768379011ab Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Fri, 22 Feb 2013 15:04:06 -0600 Subject: Changing name for atom feed view to be more generic than tags. This commit sponsored by Ben Hutchings. Thanks, Ben! --- mediagoblin/listings/routing.py | 5 +++-- mediagoblin/listings/views.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'mediagoblin/listings') diff --git a/mediagoblin/listings/routing.py b/mediagoblin/listings/routing.py index f762c6be..ee8f5020 100644 --- a/mediagoblin/listings/routing.py +++ b/mediagoblin/listings/routing.py @@ -22,7 +22,8 @@ add_route('mediagoblin.listings.tags_listing', # Atom feeds: add_route('mediagoblin.listings.tag_atom_feed', "/tag//atom/", - "mediagoblin.listings.views:tag_atom_feed") + "mediagoblin.listings.views:atom_feed") + # The all new entries feed add_route('mediagoblin.listings.atom_feed', '/atom/', - "mediagoblin.listings.views:tag_atom_feed") + "mediagoblin.listings.views:atom_feed") diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index a09aa24d..f92c0705 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -64,7 +64,7 @@ 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 """ -- cgit v1.2.3 From 6e2e5b3600d24b27ef07e81657c09697364ffdd3 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Fri, 22 Feb 2013 22:36:00 +0100 Subject: Fix stray comma in listings.views.atom_feed --- mediagoblin/listings/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/listings') diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index f92c0705..35af7148 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -74,7 +74,7 @@ def atom_feed(request): cursor = media_entries_for_tag_slug(request.db, tag_slug) link = request.urlgen('mediagoblin.listings.tags_listing', qualified=True, tag=tag_slug ) - feed_title += "for tag '%s'" % tag_slug, + feed_title += "for tag '%s'" % tag_slug else: # all recent item feed cursor = MediaEntry.query.filter_by(state=u'processed') link = request.urlgen('index', qualified=True) -- cgit v1.2.3