Skip to content

Commit

Permalink
Update food eligible report
Browse files Browse the repository at this point in the history
The old XML report is now a CSV that you can actually use.
  • Loading branch information
kitsuta committed Jun 3, 2024
1 parent 3c5b3c4 commit 1e68ad9
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions uber/site_sections/other_reports.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import cherrypy

from sqlalchemy import or_
from uber.config import c
from uber.decorators import all_renderable, csv_file, render, site_mappable
from uber.models import Attendee, FoodRestrictions, GuestCharity
Expand All @@ -22,24 +21,38 @@ def food_restrictions(self, session):
c.FOOD_RESTRICTIONS[getattr(c, category)]: len([fr for fr in all_fr if getattr(fr, category)])
for category in c.FOOD_RESTRICTION_VARS
},
'sandwich_prefs': {
'sandwich_prefs': {~
desc: len([fr for fr in all_fr if val in fr.sandwich_pref_ints])
for val, desc in c.SANDWICH_OPTS
}
}

@csv_file
@site_mappable(download=True)
def food_eligible(self, session):
cherrypy.response.headers['Content-Type'] = 'application/xml'
eligible = {
a: {attr.lower(): getattr(a.food_restrictions, attr, False) for attr in c.FOOD_RESTRICTION_VARS}
for a in session.staffers().all() + session.query(Attendee).filter_by(badge_type=c.GUEST_BADGE).all()
if not a.is_unassigned and (
a.badge_type in (c.STAFF_BADGE, c.GUEST_BADGE)
or c.VOLUNTEER_RIBBON in a.ribbon_ints
and a.weighted_hours >= 12)
}
return render('other_reports/food_eligible.xml', {'attendees': eligible})
def food_eligible(self, out, session):
header = ['Name', 'Badge Type', 'Badge #', 'Eligible']
ordered_food_restrictions = []
for val, label in c.FOOD_RESTRICTIONS.items():
ordered_food_restrictions.append(val)
header.append(label)

header.append('Notes')
out.writerow(header)

base_query = session.attendees_with_badges().filter(Attendee.is_unassigned == False)

guests = base_query.filter_by(badge_type=c.GUEST_BADGE).all()
volunteers = [a for a in base_query.filter_by(staffing=True).all() if a.badge_type == c.STAFF_BADGE
or a.weighted_hours or not a.takes_shifts]

for a in volunteers + guests:
row = [a.full_name, a.badge_type_label, a.badge_num,
'Yes' if a.badge_type in [c.STAFF_BADGE, c.GUEST_BADGE] or (
a.weighted_hours > c.HOURS_FOR_FOOD and a.worked_hours) else 'No']
for key in ordered_food_restrictions:
row.append("Yes" if a.food_restrictions and key in a.food_restrictions.standard else "No")
row.append(a.food_restrictions.freeform if a.food_restrictions else "")
out.writerow(row)

def guest_donations(self, session):
return {
Expand Down

0 comments on commit 1e68ad9

Please sign in to comment.