diff options
author | Sebastian Spaeth <Sebastian@SSpaeth.de> | 2012-12-04 17:28:53 +0100 |
---|---|---|
committer | Sebastian Spaeth <Sebastian@SSpaeth.de> | 2012-12-04 17:31:12 +0100 |
commit | 2222278dcdf70a1dbcba0e5955344259d0697752 (patch) | |
tree | 07bb040b495c37ca389e3c6153e54c9759cbebbe /mediagoblin | |
parent | 1244ffc8f5c3617bab98b560dcd57d51bc5afbd4 (diff) | |
download | mediagoblin-2222278dcdf70a1dbcba0e5955344259d0697752.tar.lz mediagoblin-2222278dcdf70a1dbcba0e5955344259d0697752.tar.xz mediagoblin-2222278dcdf70a1dbcba0e5955344259d0697752.zip |
Remove gridify_*
We injected a gridify_list and gridify_cursor function into each jinja2
template that we render. This was used to split the list of media_entries
into batches of 5 for nicer table columns. However, jinja2 has a nice |batch
filter built in that does the job for us just as well with less code (on our side)
Less code=good
so let's merge this one.
Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Diffstat (limited to 'mediagoblin')
-rw-r--r-- | mediagoblin/templates/mediagoblin/utils/collection_gallery.html | 2 | ||||
-rw-r--r-- | mediagoblin/templates/mediagoblin/utils/object_gallery.html | 2 | ||||
-rw-r--r-- | mediagoblin/tools/template.py | 31 |
3 files changed, 2 insertions, 33 deletions
diff --git a/mediagoblin/templates/mediagoblin/utils/collection_gallery.html b/mediagoblin/templates/mediagoblin/utils/collection_gallery.html index 25def418..af332537 100644 --- a/mediagoblin/templates/mediagoblin/utils/collection_gallery.html +++ b/mediagoblin/templates/mediagoblin/utils/collection_gallery.html @@ -20,7 +20,7 @@ {% macro media_grid(request, collection_items, col_number=5) %} <table class="thumb_gallery"> - {% for row in gridify_cursor(collection_items, col_number) %} + {% for row in collection_items|batch(col_number) %} <tr class="thumb_row {%- if loop.first %} thumb_row_first {%- elif loop.last %} thumb_row_last{% endif %}"> diff --git a/mediagoblin/templates/mediagoblin/utils/object_gallery.html b/mediagoblin/templates/mediagoblin/utils/object_gallery.html index b4da5bc1..0cd8cdab 100644 --- a/mediagoblin/templates/mediagoblin/utils/object_gallery.html +++ b/mediagoblin/templates/mediagoblin/utils/object_gallery.html @@ -20,7 +20,7 @@ {% macro media_grid(request, media_entries, col_number=5) %} <table class="thumb_gallery"> - {% for row in gridify_cursor(media_entries, col_number) %} + {% for row in media_entries|batch(col_number) %} <tr class="thumb_row {%- if loop.first %} thumb_row_first {%- elif loop.last %} thumb_row_last{% endif %}"> diff --git a/mediagoblin/tools/template.py b/mediagoblin/tools/template.py index cb556e4c..d9c6e654 100644 --- a/mediagoblin/tools/template.py +++ b/mediagoblin/tools/template.py @@ -59,8 +59,6 @@ def get_jinja_env(template_loader, locale): # ... construct a grid of thumbnails or other media # ... have access to the global and app config template_env.globals['fetch_messages'] = messages.fetch_messages - template_env.globals['gridify_list'] = gridify_list - template_env.globals['gridify_cursor'] = gridify_cursor template_env.globals['app_config'] = mg_globals.app_config template_env.globals['global_config'] = mg_globals.global_config @@ -100,32 +98,3 @@ def render_template(request, template_path, context): def clear_test_template_context(): global TEMPLATE_TEST_CONTEXT TEMPLATE_TEST_CONTEXT = {} - - -def gridify_list(this_list, num_cols=5): - """ - Generates a list of lists where each sub-list's length depends on - the number of columns in the list - """ - grid = [] - - # Figure out how many rows we should have - num_rows = int(ceil(float(len(this_list)) / num_cols)) - - for row_num in range(num_rows): - slice_min = row_num * num_cols - slice_max = (row_num + 1) * num_cols - - row = this_list[slice_min:slice_max] - - grid.append(row) - - return grid - - -def gridify_cursor(this_cursor, num_cols=5): - """ - Generates a list of lists where each sub-list's length depends on - the number of columns in the list - """ - return gridify_list(list(this_cursor), num_cols) |