Ticket #166: 0001-adds-feature-458-given-a-column-number-limits-the-nu.patch

File 0001-adds-feature-458-given-a-column-number-limits-the-nu.patch, 2.9 KB (added by Karen Rustad, 13 years ago)

0001-adds-feature-458-given-a-column-number-limits-the-nu.patch

  • mediagoblin/templates/mediagoblin/utils/object_gallery.html

    From 6d523edd15358a0c933e2b066f1d716f46d82153 Mon Sep 17 00:00:00 2001
    From: Karen Rustad <karen.rustad@gmail.com>
    Date: Tue, 2 Aug 2011 18:01:02 -0700
    Subject: [PATCH] adds feature #458 -- given a column number, limits the number of items in a row (and adds divs saying so). No CSS styling to make these demarcations visible, though
    
    ---
     .../mediagoblin/utils/object_gallery.html          |   45 ++++++++++++++++---
     1 files changed, 38 insertions(+), 7 deletions(-)
    
    diff --git a/mediagoblin/templates/mediagoblin/utils/object_gallery.html b/mediagoblin/templates/mediagoblin/utils/object_gallery.html
    index 03b85b1..c5e890f 100644
    a b  
    1818
    1919{% from "mediagoblin/utils/pagination.html" import render_pagination %}
    2020
     21{% macro media_grid(media_list, col_number=5) %}
     22    {% set num_items = media_list.count() %}
     23    {% set col_counter = 0 %}
     24    {% set row_counter = 0 %}
     25    {% set item_counter = 0 %}
     26   
     27    {% set num_rows = num_items // col_number %}
     28    {% if num_items % col_number != 0 %}
     29        {% set num_rows = num_rows + 1 %}
     30    {% endif %}
     31   
     32    <div class="thumb_gallery">
     33    {% for entry in media_list %}
     34        {% if col_counter == 0 %}
     35        <div class="thumb_row {% if row_counter == 0 %}thumb_row_first{% endif %}{% if num_rows == row_counter + 1 %}thumb_row_last{% endif %}">
     36        {% endif %}
     37       
     38            <div class="media_thumbnail thumb_entry {% if col_counter == 0 %}thumb_entry_first{% endif %}{% if col_number == col_counter + 1 or num_items == item_counter + 1 %}thumb_entry_last{% endif %}">
     39            <a href="{{ entry.url_for_self(request.urlgen) }}">
     40            <img src="{{ request.app.public_store.file_url(
     41                             entry['media_files']['thumb']) }}" /></a>
     42            </div>
     43       
     44        {% if col_number == col_counter + 1 or num_items == item_counter + 1 %}
     45        </div>
     46        {% set row_counter = row_counter + 1 %}
     47        {% endif %}
     48       
     49        {% set item_counter = item_counter + 1 %}
     50        {% set col_counter = col_counter + 1 %}
     51        {% if col_counter == col_number %}
     52            {% set col_counter = 0 %}
     53        {% endif %}
     54    {% endfor %}
     55    </div>
     56{%- endmacro %}
     57
    2158{% block object_gallery_content -%}
    2259  {% if media_entries and media_entries.count() %}
    23     {% for entry in media_entries %}
    24       <div class="media_thumbnail">
    25         <a href="{{ entry.url_for_self(request.urlgen) }}">
    26         <img src="{{ request.app.public_store.file_url(
    27                          entry['media_files']['thumb']) }}" /></a>
    28       </div>
    29     {% endfor %}
     60    {{ media_grid(media_entries) }}
    3061    <div class="clear"></div>
    3162    {% if pagination_base_url %}
    3263      {# different url, so set that and don't keep the get params #}