Simplify/Robustify the thumbnail URL usage in templates
[mediagoblin.git] / mediagoblin / templates / mediagoblin / utils / collection_gallery.html
1 {#
2 # GNU MediaGoblin -- federated, autonomous media hosting
3 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Affero General Public License for more details.
14 #
15 # You should have received a copy of the GNU Affero General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #}
18
19 {% from "mediagoblin/utils/pagination.html" import render_pagination %}
20
21 {% macro media_grid(request, collection_items, col_number=5) %}
22 <table class="thumb_gallery">
23 {% for row in gridify_cursor(collection_items, col_number) %}
24 <tr class="thumb_row
25 {%- if loop.first %} thumb_row_first
26 {%- elif loop.last %} thumb_row_last{% endif %}">
27 {% for item in row %}
28 {% set media_entry = item.get_media_entry %}
29 {% set entry_url = media_entry.url_for_self(request.urlgen) %}
30 <td class="collection_thumbnail thumb_entry
31 {%- if loop.first %} thumb_entry_first
32 {%- elif loop.last %} thumb_entry_last{% endif %}">
33 <a href="{{ entry_url }}">
34 <img src="{{ media_entry.thumb_url }}" />
35 </a>
36
37 {% if item.note %}
38 {%- trans note=item.note -%}
39 <br />
40 <a href="{{ entry_url }}">{{ note }}</a>
41 {%- endtrans -%}
42 {% endif %}
43 {% if request.user and
44 (item.in_collection.creator == request.user._id or
45 request.user.is_admin) %}
46 {%- trans remove_url=request.urlgen(
47 'mediagoblin.user_pages.collection_item_confirm_remove',
48 user=item.in_collection.get_creator.username,
49 collection=item.in_collection.slug,
50 collection_item=item.id) -%}
51 <br /><a href="{{ remove_url }}" class="remove">(remove)</a>
52 {%- endtrans -%}
53 {% endif %}
54 </td>
55 {% endfor %}
56 </tr>
57 {% endfor %}
58 </table>
59 {%- endmacro %}
60
61 {#
62 Render a media gallery with pagination.
63
64 Args:
65 - request: Request
66 - collection_items: cursor of collection items
67 - pagination: Paginator object
68 - pagination_base_url: If you want the pagination to point to a
69 different URL, point it here
70 - col_number: How many columns per row (default 5)
71 #}
72 {% macro collection_gallery(request, collection_items, pagination,
73 pagination_base_url=None, col_number=5) %}
74 {% if collection_items and collection_items.count() %}
75 {{ media_grid(request, collection_items, col_number=col_number) }}
76 <div class="clear"></div>
77 {% if pagination_base_url %}
78 {# different url, so set that and don't keep the get params #}
79 {{ render_pagination(request, pagination, pagination_base_url, False) }}
80 {% else %}
81 {{ render_pagination(request, pagination) }}
82 {% endif %}
83 {% else %}
84 <p>
85 <i>
86 {%- trans -%}
87 There doesn't seem to be any media here yet...
88 {%- endtrans -%}
89 </i>
90 </p>
91 {% endif %}
92 {% endmacro %}