Add functionality to batch the meetings list

Created and export, to jinja2, a batch_meetings fuction that will pivot
the sorted list of meetings into a number of colums.  This can be used
in a jinja template like:

  {% for column in batch_meetings(meetings, 4)|batch(4) %}

So the list:
     [A, B, C, D, E, F , G, H]

Dsisplays as:
    A C E G
    B D F H

Rather than:
    A B C D
    E F G H

Change-Id: I9d7c6ad9c14a9d6ec3d402a67b73fafae575d369
This commit is contained in:
Tony Breeds 2016-02-03 11:52:57 +11:00
parent faabbec1a6
commit 3dd31a4f91
2 changed files with 18 additions and 0 deletions

View File

@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import division
import datetime
import jinja2
import logging
@ -17,6 +19,20 @@ import os
import os.path
def batch_meetings(meetings, batch_size):
col_length = len(meetings) // batch_size
new_meetings = [None] * len(meetings)
src = 0
for row in range(batch_size):
for col in range(col_length):
dest = col * batch_size + row
new_meetings[dest] = meetings[src]
src += 1
return new_meetings
def convert_meetings_to_index(meetings, template, output_file):
"""Creates index file from list of meetings.
@ -30,6 +46,7 @@ def convert_meetings_to_index(meetings, template, output_file):
loader = jinja2.FileSystemLoader(template_dir)
env = jinja2.environment.Environment(trim_blocks=True, loader=loader)
template = env.get_template(template_file)
template.globals['batch_meetings'] = batch_meetings
with open(output_file, "w") as out:
out.write(template.render(meetings=meetings,

View File

@ -176,6 +176,7 @@ def load_meetings(yaml_source):
raise ValueError("No .yaml file, directory containing .yaml files, "
"or YAML data found.")
else:
meetings.sort(key=lambda x: x.project)
return meetings