def event_overview(request, event_pk): event = get_object_or_404(Event, pk=event_pk) total = sum_attendee_payment_status(event.attendees) # returns a set of dictionaries with {'state': x, 'is_new': y, 'count': z} status = Attend.objects.filter(event=event).values('state', 'is_new').annotate(count=Count('pk')) status_flat = {} for item in status: status_flat['%s_new' % item['state'] if item['is_new'] else item['state']] = item['count'] for item in status: if item['is_new']: status_flat.setdefault(item['state'], 0) status_flat[item['state']] += item['count'] return render(request, 'sadmin2/event/overview.html', { 'sadmin2_menu_main_active': 'events', 'sadmin2_breadcrumbs_active': 'event', 'sadmin2_menu_tab': menu.sadmin2_menu_tab_event, 'sadmin2_menu_tab_active': 'overview', 'event': event, 'total': total, 'status': status_flat })
def format(self): if not hasattr(self, 'cleaned_data'): self.cleaned_data = {} # Defaults attendee_filter_label = self.FILTER_ATTENDED_CHOICES[0][1] attendee_filter = self.cleaned_data.get('filter_attended', 'attended_or_paid') # set attendee label for line in self.FILTER_ATTENDED_CHOICES: if attendee_filter == line[0]: attendee_filter_label = line[1] # filter invoice if attendee_filter == 'only_attended': self.attendees = self.attendees.filter(state=AttendState.attended) elif attendee_filter == 'not_attended': self.attendees = self.attendees.exclude(state=AttendState.attended) elif attendee_filter == 'attended_or_paid': self.attendees = self.attendees.filter(Q(state=AttendState.attended) | Q(paid__gt=0)) elif attendee_filter == 'all': pass else: raise ValueError show_each_user = self.cleaned_data.get('show_each_user', 'over_and_under') if show_each_user == 'over_and_under': show_regular_attendees = False show_irregular_attendees = True elif show_each_user == 'all': show_regular_attendees = True show_irregular_attendees = True elif show_each_user == 'none': show_regular_attendees = False show_irregular_attendees = False else: raise ValueError # Initialize empty line groups line_groups = OrderedDict() excluded_options = self.cleaned_data.get('exclude_lines', []) for option in self.options: if unicode(option.pk) in excluded_options: continue line_groups[option.pk] = self.LineGroup(option.name, option.price) for suboption in option.suboptions: line_groups['%s-%s' % (option.pk, suboption.pk)] = self.LineGroup('%s (%s)' % ( option.name, suboption.name ), option.price + suboption.price if suboption.price is not None else 0) pks = [attendee.pk for attendee in self.attendees.all()] for selection in Selection.objects.filter(attendee__pk__in=pks).select_related('option', 'attendee'): if selection.option.pk in line_groups: if selection.suboption is None: line_groups[selection.option.pk].add(selection.attendee) else: line_groups['%s-%s' % (selection.option.pk, selection.suboption.pk)].add(selection.attendee) total = sum_attendee_payment_status(self.attendees) return self.attendees, line_groups.values(), total, \ show_regular_attendees, show_irregular_attendees, attendee_filter_label