$def with (event, classes)

$ date = event.get('date', '')

$def format_time(time):
    $if time is not None:
        $return '{:d}:{:02d}'.format(time//60, time%60)
    $else:
        $return ''

$def format_date(time):
    $if time is not None:
        $return time.strftime('%H:%M:%S')
    $else:
        $return ''

$def format_int(value):
    $return str(value) if value is not None else ''

$def format_voided_legs(legs):
    $ s = []
    $for i in legs:
        $s.append(i[0] + '-' + i[1])
    $return ', '.join(s)


<div id="cls.event">
    <table style="text-align: left">
        <tr>
            <th style="padding-right: 10px">Event name:</th>
            <td>$event.get('name', '')</td>
        </tr>
        <tr>
            <th style="padding-right: 10px">Event date:</th>
            <td>$(date.isoformat() if date != '' else '')</td>
        </tr>
    </table>
</div>

<p/>

<input oninput="w3.filterHTML('#classes_tbody', 'tr', this.value)" placeholder="Search ...">
<p/>

<div>
    <table class="dt" id="cls.table" onclick="cls_highlight(event)">
        <thead>
            <tr class="dt">
                <th class="dt">Name</th>
                <th class="dt">Short name</th>
                <th class="dt">Course</th>
                <th class="dt">Voided legs</th>
                <th class="dt">Type</th>
                <th class="dt">Use start control</th>
                <th class="dt">Apply handicap</th>
                <th class="dt">Mass start</th>
                <th class="dt">Time limit</th>
                <th class="dt">Penalty controls</th>
                <th class="dt">Penalty time limit</th>
            </tr>
        </thead>
        <tbody id="classes_tbody">
        $for class_ in classes:
            <tr class="dt" id="$class_.id">
                <td class="dt">$class_.name</td>
                <td class="dt">$(class_.short_name if class_.short_name is not None else '')</td>
                <td class="dt">$(class_.course if class_.course is not None else '')</td>
                <td class="dt">$format_voided_legs(class_.params.voided_legs)</td>
                <td class="dt">$({'standard': 'Standard', 'net': 'Net', 'score': 'Score'}.get(class_.params.otype, ''))</td>
                <td class="dt">$({'if_punched': 'If punched', 'no': 'No', 'yes': 'Yes'}.get(class_.params.using_start_control, ''))</td>
                <td class="dt">$('Yes' if class_.params.apply_handicap_rule else '')</td>
                <td class="dt" style="text-align:right">$format_date(class_.params.get('mass_start', None))</td>
                <td class="dt" style="text-align:right">$format_time(class_.params.get('time_limit', None))</td>
                <td class="dt" style="text-align:right">$format_int(class_.params.get('penalty_controls', None))</td>
                <td class="dt" style="text-align:right">$format_int(class_.params.get('penalty_overtime', None))</td>
            </tr> 
        </tbody>
    </table>
</div>

