| 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, media_entries, col_number=5) %} |
| 22 | <ul class="thumb_gallery"> |
| 23 | {% for row in gridify_cursor(media_entries, col_number) %} |
| 24 | {% for entry in row %} |
| 25 | {% set entry_url = entry.url_for_self(request.urlgen) %} |
| 26 | <li class="media_thumbnail"> |
| 27 | <a href="{{ entry_url }}"> |
| 28 | <img src="{{ request.app.public_store.file_url( |
| 29 | entry.media_files['thumb']) }}" /> |
| 30 | </a> |
| 31 | {% if entry.title %} |
| 32 | <br /> |
| 33 | <a href="{{ entry_url }}">{{ entry.title }}</a> |
| 34 | {% endif %} |
| 35 | </li> |
| 36 | {% endfor %} |
| 37 | {% endfor %} |
| 38 | </ul> |
| 39 | {%- endmacro %} |
| 40 | |
| 41 | {# |
| 42 | Render a media gallery with pagination. |
| 43 | |
| 44 | Args: |
| 45 | - request: Request |
| 46 | - media_entries: pymongo cursor of media entries |
| 47 | - pagination: Paginator object |
| 48 | - pagination_base_url: If you want the pagination to point to a |
| 49 | different URL, point it here |
| 50 | - col_number: How many columns per row (default 5) |
| 51 | #} |
| 52 | {% macro object_gallery(request, media_entries, pagination, |
| 53 | pagination_base_url=None, col_number=5) %} |
| 54 | {% if media_entries and media_entries.count() %} |
| 55 | {{ media_grid(request, media_entries, col_number=col_number) }} |
| 56 | <div class="clear"></div> |
| 57 | {% if pagination_base_url %} |
| 58 | {# different url, so set that and don't keep the get params #} |
| 59 | {{ render_pagination(request, pagination, pagination_base_url, False) }} |
| 60 | {% else %} |
| 61 | {{ render_pagination(request, pagination) }} |
| 62 | {% endif %} |
| 63 | {% else %} |
| 64 | <p> |
| 65 | <i> |
| 66 | {%- trans -%} |
| 67 | There doesn't seem to be any media here yet... |
| 68 | {%- endtrans -%} |
| 69 | </i> |
| 70 | </p> |
| 71 | {% endif %} |
| 72 | {% endmacro %} |