diff --git a/uber/site_sections/other_reports.py b/uber/site_sections/other_reports.py index 3e3403570..078873812 100644 --- a/uber/site_sections/other_reports.py +++ b/uber/site_sections/other_reports.py @@ -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 @@ -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 {