collections: add support to browse existing collections

- add a route at /u/<user>/collections/ (note trailing 's') that lists
  all existing collections
- move there the "Create new collection" link, if the user is logged in
- add a new link "Browse collections" from root.html
This commit is contained in:
Stefano Zacchiroli 2012-12-18 12:34:30 +01:00
parent cf764377df
commit b0cc1ade40
4 changed files with 88 additions and 3 deletions

View File

@ -27,9 +27,10 @@
<li><a href="{{ request.urlgen('mediagoblin.submit.start') }}">
{%- trans %}Add media{% endtrans -%}
</a></li>
<li><a href="{{ request.urlgen('mediagoblin.submit.collection') }}">
{%- trans %}Create new collection{% endtrans -%}
</a></li>
<li><a href="{{ request.urlgen('mediagoblin.user_pages.user_collections',
user=request.user.username) }}">
{%- trans %}Browse collections{% endtrans -%}
</a></li>
<li><a href="{{ request.urlgen('mediagoblin.edit.account') }}">
{%- trans %}Change account settings{% endtrans -%}
</a></li>

View File

@ -0,0 +1,63 @@
{#
# GNU MediaGoblin -- federated, autonomous media hosting
# 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
# 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_head %}
<link rel="alternate" type="application/atom+xml"
href="{{ request.urlgen(
'mediagoblin.user_pages.atom_feed',
user=user.username) }}">
{% endblock mediagoblin_head %}
{% block title %}
{%- trans username=user.username -%}
{{ username }}'s collections
{%- endtrans %} &mdash; {{ super() }}
{% endblock %}
{% block mediagoblin_content -%}
<h1>
{%- trans username=user.username,
user_url=request.urlgen(
'mediagoblin.user_pages.user_home',
user=user.username) -%}
<a href="{{ user_url }}">{{ username }}</a>'s collections
{%- endtrans %}
</h1>
{% if request.user %}
{% if request.user.status == 'active' %}
<p>
<a href="{{ request.urlgen('mediagoblin.submit.collection',
user=user.username) }}">
{%- trans %}Create new collection{% endtrans -%}
</p>
{% endif %}
{% endif %}
<ul>
{% for coll in collections %}
{% set coll_url = request.urlgen(
'mediagoblin.user_pages.user_collection',
user=user.username,
collection=coll.slug) %}
<li><a href="{{ coll_url }}">{{ coll.title }}</li>
{% endfor %}
</ul>
{% endblock %}

View File

@ -48,6 +48,10 @@ add_route('mediagoblin.user_pages.media_collect',
'/u/<string:user>/m/<string:media>/collect/',
'mediagoblin.user_pages.views:media_collect')
add_route('mediagoblin.user_pages.user_collections',
'/u/<string:user>/collections/',
'mediagoblin.user_pages.views:user_collections')
add_route('mediagoblin.user_pages.user_collection',
'/u/<string:user>/collection/<string:collection>/',
'mediagoblin.user_pages.views:user_collection')

View File

@ -337,6 +337,23 @@ def user_collection(request, page, url_user=None):
'pagination': pagination})
@active_user_from_url
@uses_pagination
def user_collections(request, page, url_user=None):
"""A User-defined Collection"""
collections = Collection.query.filter_by(
get_creator=url_user)
pagination = Pagination(page, collections)
return render_to_response(
request,
'mediagoblin/user_pages/collections.html',
{'user': url_user,
'collections': collections,
'pagination': pagination})
@get_user_collection_item
@require_active_login
@user_may_alter_collection