def index(self, session, department_id=None, message='', time=None): redirect_to_allowed_dept(session, department_id, 'index') department_id = None if department_id == 'All' else department_id department = session.query(Department).get( department_id) if department_id else None jobs = session.jobs(department_id).all() by_start = defaultdict(list) for job in jobs: if job.type == c.REGULAR: by_start[job.start_time_local].append(job) times = [c.EPOCH + timedelta(hours=i) for i in range(c.CON_LENGTH)] return { 'department_id': department_id, 'department': department, 'setup': [j for j in jobs if j.type == c.SETUP], 'teardown': [j for j in jobs if j.type == c.TEARDOWN], 'normal': [j for j in jobs if j.type != c.SETUP and j.type != c.TEARDOWN], 'checklist': department_id and session.checklist_status('creating_shifts', department_id), 'times': [(t, t + timedelta(hours=1), by_start[t]) for i, t in enumerate(times)], 'jobs': jobs, 'message': message, }
def placeholders(self, session, department_id=None): redirect_to_allowed_dept(session, department_id, 'placeholders') if department_id == 'All': department_id = None dept_filter = [] if not department_id else [ Attendee.dept_memberships.any(department_id=department_id) ] placeholders = session.query(Attendee).filter( Attendee.placeholder == True, Attendee.staffing == True, Attendee.badge_status.in_([c.NEW_STATUS, c.COMPLETED_STATUS]), *dept_filter).order_by(Attendee.full_name).all() # noqa: E712 try: checklist = session.checklist_status('placeholders', department_id) except ValueError: checklist = {'conf': None, 'relevant': False, 'completed': None} return { 'department_id': department_id, 'dept_name': session.query(Department).get(department_id).name if department_id else 'All', 'checklist': checklist, 'placeholders': placeholders }
def hotel_requests(self, session, department_id=None): redirect_to_allowed_dept(session, department_id, 'index') if department_id == 'All': department_id = None dept_filter = [] if not department_id \ else [Attendee.dept_memberships.any(department_id=department_id)] requests = session.query(HotelRequests) \ .join(HotelRequests.attendee) \ .options(joinedload(HotelRequests.attendee)) \ .filter( Attendee.badge_status.in_([c.NEW_STATUS, c.COMPLETED_STATUS]), *dept_filter) \ .order_by(Attendee.full_name).all() attendee = session.admin_attendee() return { 'admin_has_room_access': c.HAS_HOTEL_ADMIN_ACCESS, 'attendee': attendee, 'requests': requests, 'department_id': department_id, 'department_name': c.DEPARTMENTS.get(department_id, 'All'), 'declined_count': len([r for r in requests if r.nights == '']), 'checklist': session.checklist_status( 'approve_setup_teardown', department_id), 'staffer_count': session.query(Attendee).filter( Attendee.hotel_eligible == True, *dept_filter).count() # noqa: E712 }
def signups(self, session, department_id=None, message='', toggle_filter=''): if not toggle_filter: redirect_to_allowed_dept(session, department_id, 'signups') department_id = None if department_id == 'All' or department_id == 'None' else department_id cherrypy.session['prev_department_id'] = department_id if toggle_filter: cherrypy.session[toggle_filter] = not cherrypy.session.get( toggle_filter) show_past_shifts = cherrypy.session.get('signups_show_past_shifts', True) show_restricted = cherrypy.session.get('signups_show_restricted', True) show_nonpublic = cherrypy.session.get('signups_show_nonpublic', True) job_filters = [Job.department_id == department_id ] if department_id else [] if not show_past_shifts: job_filters.append( Job.start_time > localized_now() - timedelta(hours=2)) if not show_restricted: job_filters.append(Job.restricted == False) # noqa: E712 if not show_nonpublic: job_filters.append( Job.department_id.in_( select([Department.id]).where( Department.solicits_volunteers == True))) # noqa: E712 jobs = session.jobs().filter(*job_filters) return { 'message': message, 'department_id': department_id, 'show_past_shifts': show_past_shifts, 'show_restricted': show_restricted, 'show_nonpublic': show_nonpublic, 'hide_filled': cherrypy.session.get('signups_hide_filled'), 'attendees': session.staffers_for_dropdown(), 'jobs': [job_dict(job) for job in jobs], 'checklist': department_id and session.checklist_status('postcon_hours', department_id) }
def hotel_eligible(self, session, department_id=None): redirect_to_allowed_dept(session, department_id, 'hotel_eligible') if department_id == 'All': department_id = None return { 'department_id': department_id, 'department_name': c.DEPARTMENTS.get(department_id, 'All'), 'checklist': session.checklist_status('hotel_eligible', department_id), 'attendees': session.query(Attendee).filter( Attendee.hotel_eligible == True, Attendee.badge_status.in_([c.NEW_STATUS, c.COMPLETED_STATUS]), Attendee.dept_memberships.any(department_id=department_id) ).order_by(Attendee.full_name).all() } # noqa: E712
def unfilled_shifts(self, session, department_id=None, message='', toggle_filter=''): """ This page is very similar to the signups view, but this is for STOPS to assign on-call volunteers to shifts onsite, so all the default values need to be the exact opposite. We also don't want the filters to interfere with the signups view so we store them separately. """ if not toggle_filter: redirect_to_allowed_dept(session, department_id, 'unfilled_shifts') department_id = None if department_id == 'All' or department_id == 'None' else department_id if toggle_filter: cherrypy.session[toggle_filter] = not cherrypy.session.get( toggle_filter) show_past_shifts = cherrypy.session.get('unfilled_show_past_shifts') show_restricted = cherrypy.session.get('unfilled_show_restricted') show_nonpublic = cherrypy.session.get('unfilled_show_nonpublic') job_filters = [Job.department_id == department_id ] if department_id else [] if not show_past_shifts: job_filters.append( Job.start_time > localized_now() - timedelta(hours=2)) if not show_restricted: job_filters.append(Job.restricted == False) # noqa: E712 if not show_nonpublic: job_filters.append( Job.department_id.in_( select([Department.id]).where( Department.solicits_volunteers == True))) # noqa: E712 jobs = session.jobs().filter(*job_filters) return { 'message': message, 'department_id': department_id, 'show_past_shifts': show_past_shifts, 'show_restricted': show_restricted, 'show_nonpublic': show_nonpublic, 'attendees': session.staffers_for_dropdown(), 'jobs': [job_dict(job) for job in jobs], }
def staffers(self, session, department_id=None, message=''): redirect_to_allowed_dept(session, department_id, 'staffers') department_id = None if department_id == 'All' else department_id if department_id: department = session.query(Department).filter_by( id=department_id).first() if not department: department_id = None dept_filter = [] if not department_id \ else [Attendee.dept_memberships.any(department_id=department_id)] attendees = session.staffers(pending=True).filter(*dept_filter).all() for attendee in attendees: if session.admin_has_staffer_access(attendee) or department_id: attendee.is_dept_head_here = attendee.is_dept_head_of(department_id) if department_id \ else attendee.is_dept_head attendee.trusted_here = attendee.trusted_in(department_id) if department_id \ else attendee.has_role_somewhere attendee.hours_here = attendee.weighted_hours_in(department_id) else: attendees.remove(attendee) counts = defaultdict(int) for job in session.jobs(department_id): update_counts(job, counts) return { 'counts': counts, 'department_id': department_id, 'attendees': attendees, 'emails': ','.join(a.email for a in attendees), 'emails_with_shifts': ','.join([ a.email for a in attendees if department_id and a.hours_here ]), 'checklist': session.checklist_status('assigned_volunteers', department_id), 'message': message, }
def signups(self, session, department_id=None, message=''): redirect_to_allowed_dept(session, department_id, 'signups') department_id = None if department_id == 'All' else department_id cherrypy.session['prev_department_id'] = department_id return { 'message': message, 'department_id': department_id, 'attendees': session.staffers_for_dropdown(), 'jobs': [job_dict(job) for job in session.jobs(department_id)], 'checklist': department_id and session.checklist_status('postcon_hours', department_id) }