Skip to content

Commit

Permalink
Improves the volunteer checklists summary page, adds CSV download
Browse files Browse the repository at this point in the history
  • Loading branch information
RobRuana committed Aug 10, 2018
1 parent f76057b commit fe7b67c
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 34 deletions.
76 changes: 50 additions & 26 deletions uber/site_sections/summary.py
Expand Up @@ -30,6 +30,45 @@ def generate_staff_badges(start_badge, end_badge, out, session):
badge_type_name='Staff').run(out, session)


def volunteer_checklists(session):
attendees = session.query(Attendee) \
.filter(
Attendee.staffing == True,
Attendee.badge_status.in_([c.NEW_STATUS, c.COMPLETED_STATUS])) \
.order_by(Attendee.full_name, Attendee.id).all()

checklist_items = OrderedDict()
for item_template in c.VOLUNTEER_CHECKLIST:
item_name = os.path.splitext(os.path.basename(item_template))[0]
if item_name.endswith('_item'):
item_name = item_name[:-5]
item_name = item_name.replace('_', ' ').title()
checklist_items[item_name] = item_template

re_checkbox = re.compile(r'<img src="\.\./static/images/checkbox_.*?/>')
for attendee in attendees:
attendee.checklist_items = OrderedDict()
for item_name, item_template in checklist_items.items():
html = render(item_template, {'attendee': attendee}, encoding=None)
match = re_checkbox.search(html)
is_complete = False
is_applicable = False
if match:
is_applicable = True
checkbox_html = match.group(0)
if 'checkbox_checked' in checkbox_html:
is_complete = True
attendee.checklist_items[item_name] = {
'is_applicable': is_applicable,
'is_complete': is_complete,
}

return {
'checklist_items': checklist_items,
'attendees': attendees,
}


@all_renderable(c.STATS)
class Root:
def index(self, session):
Expand Down Expand Up @@ -513,33 +552,18 @@ def is_unrefunded(a):
)]
}

def volunteer_checklists(self, session):
attendees = session.query(Attendee) \
.filter(
Attendee.staffing == True,
Attendee.badge_status.in_([c.NEW_STATUS, c.COMPLETED_STATUS])) \
.order_by(Attendee.full_name, Attendee.id).all()

checklist_items = OrderedDict()
for item_template in c.VOLUNTEER_CHECKLIST:
item_name = os.path.splitext(os.path.basename(item_template))[0]
if item_name.endswith('_item'):
item_name = item_name[:-5]
item_name = item_name.replace('_', ' ').title()
checklist_items[item_name] = item_template

re_checkbox = re.compile(r'<img src="\.\./static/images/checkbox_.*?/>')
for attendee in attendees:
attendee.checklist_items = OrderedDict()
for item_name, item_template in checklist_items.items():
html = render(item_template, {'attendee': attendee}, encoding=None)
match = re_checkbox.search(html)
attendee.checklist_items[item_name] = match.group(0) if match else '<span>N/A</span>'
@csv_file
def volunteer_checklist_csv(self, out, session):
checklists = volunteer_checklists(session)
out.writerow(['Volunteer', 'Email'] + [s for s in checklists['checklist_items'].keys()])
for attendee in checklists['attendees']:
checklist_items = []
for item in attendee.checklist_items.values():
checklist_items.append('Yes' if item['is_complete'] else 'No' if item['is_applicable'] else 'N/A')
out.writerow([attendee.full_name, attendee.email] + checklist_items)

return {
'checklist_items': checklist_items,
'attendees': attendees,
}
def volunteer_checklists(self, session):
return volunteer_checklists(session)

@csv_file
@site_mappable
Expand Down
42 changes: 34 additions & 8 deletions uber/templates/summary/volunteer_checklists.html
Expand Up @@ -2,30 +2,56 @@
{% block title %}Volunteer Checklists{% endblock %}
{% block content %}

<h1>Volunteer Checklists</h1>
<style type="text/css">

.table .glyphicon {
font-size: 2em;
vertical-align: -25%;
display: inline-block;
}

.glyphicon-check {
color: #0c0;
}

.glyphicon-unchecked {
color: #808080;
}

</style>

<h1>Volunteer Checklists <small><a href="volunteer_checklist_csv">Download CSV</a></h1>

<div class="table-responsive">
<table
class="table table-hover datatable"
data-page-length="-1"
data-searching="false"
data-paging="false"
data-info="false"
data-auto-width="true">
data-paging="true"
data-info="false">
<thead>
<tr>
<th>Volunteer</th>
{% for item_name in checklist_items.keys() %}
<th>{{ item_name }}</th>
<th data-searchable="false">{{ item_name }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for attendee in attendees %}
<tr>
<td>{{ attendee|form_link }}</td>
{% for item_name, checkbox in attendee.checklist_items.items() %}
<td title="{{ item_name }}">{{ checkbox|safe }}</td>
{% for item_name, status in attendee.checklist_items.items() %}
<td data-order="{{ (0 if status.is_complete else (2 if status.is_applicable else 1)) }}">
<div title="{{ item_name }}">
{% if status.is_complete %}
<span class="glyphicon glyphicon-check"></span>
{% elif status.is_applicable %}
<span class="glyphicon glyphicon-unchecked"></span>
{% else %}
<span>N/A</span>
{% endif %}
</div>
</td>
{% endfor %}
</tr>
{% endfor %}
Expand Down

0 comments on commit fe7b67c

Please sign in to comment.