diff options
-rw-r--r-- | mediagoblin/listings/__init__.py | 19 | ||||
-rw-r--r-- | mediagoblin/listings/routing.py | 25 | ||||
-rw-r--r-- | mediagoblin/listings/views.py | 53 | ||||
-rw-r--r-- | mediagoblin/routing.py | 3 | ||||
-rw-r--r-- | mediagoblin/static/css/base.css | 10 | ||||
-rw-r--r-- | mediagoblin/templates/mediagoblin/listings/tag.html | 28 | ||||
-rw-r--r-- | mediagoblin/templates/mediagoblin/user_pages/media.html | 3 | ||||
-rw-r--r-- | mediagoblin/templates/mediagoblin/utils/tags.html | 6 |
8 files changed, 146 insertions, 1 deletions
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 <http://www.gnu.org/licenses/>. + +""" +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 <http://www.gnu.org/licenses/>. + + +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 <http://www.gnu.org/licenses/>. + +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}) diff --git a/mediagoblin/routing.py b/mediagoblin/routing.py index b854c85a..1340da60 100644 --- a/mediagoblin/routing.py +++ b/mediagoblin/routing.py @@ -20,6 +20,8 @@ from mediagoblin.auth.routing import auth_routes from mediagoblin.submit.routing import submit_routes from mediagoblin.user_pages.routing import user_routes from mediagoblin.edit.routing import edit_routes +from mediagoblin.listings.routing import tag_routes + def get_mapper(): mapping = Mapper() @@ -33,5 +35,6 @@ def get_mapper(): mapping.extend(submit_routes, '/submit') mapping.extend(user_routes, '/u') mapping.extend(edit_routes, '/edit') + mapping.extend(tag_routes, '/tag') return mapping diff --git a/mediagoblin/static/css/base.css b/mediagoblin/static/css/base.css index 70db6da9..c84fe047 100644 --- a/mediagoblin/static/css/base.css +++ b/mediagoblin/static/css/base.css @@ -275,3 +275,13 @@ ul.mediagoblin_messages { background-color: #f7f7f7; color: #272727; } + +ul.mediaentry_tags { + list-style-type: none; +} + +ul.mediaentry_tags li { + display: inline; + margin: 0px 5px 0px 0px; + padding: 0px; +} diff --git a/mediagoblin/templates/mediagoblin/listings/tag.html b/mediagoblin/templates/mediagoblin/listings/tag.html new file mode 100644 index 00000000..db3381d2 --- /dev/null +++ b/mediagoblin/templates/mediagoblin/listings/tag.html @@ -0,0 +1,28 @@ +{# +# 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 <http://www.gnu.org/licenses/>. +#} +{% extends "mediagoblin/base.html" %} + +{% block mediagoblin_content -%} + <h1> + Media tagged with: {{ tag_name }} + </h1> + + <div class="container_16 media_gallery"> + {% include "mediagoblin/utils/object_gallery.html" %} + </div> +{% endblock %} diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index 7622d6e6..353cf91c 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -97,9 +97,11 @@ media = media._id)) }} </div> {% endif %} + <div class="grid_5 omega"> {% include "mediagoblin/utils/prev_next.html" %} <h3>Sidebar content here!</h3> + <p> {% if media['uploader'] == request.user['_id'] or request.user['is_admin'] %} @@ -116,6 +118,7 @@ </p> {% endif %} </p> + {% if media.tags %} {% include "mediagoblin/utils/tags.html" %} {% endif %} diff --git a/mediagoblin/templates/mediagoblin/utils/tags.html b/mediagoblin/templates/mediagoblin/utils/tags.html index 94c4cf69..ade41944 100644 --- a/mediagoblin/templates/mediagoblin/utils/tags.html +++ b/mediagoblin/templates/mediagoblin/utils/tags.html @@ -17,9 +17,13 @@ #} {% block tags_content -%} + <h4>Tags</h4> <ul class="mediaentry_tags"> {% for tag in media.tags %} - <li class="tag">{{ tag['name'] }}</li> + <li class="tag"> + <a href="{{ request.urlgen( + 'mediagoblin.listings.tags_listing', + tag=tag['slug']) }}">{{ tag['name'] }}</li> {% endfor %} </ul> {% endblock %} |