def survey_export_view(request, event_slug='', survey_slug='', format='xlsx'): if event_slug: event = get_object_or_404(Event, slug=event_slug) survey = get_object_or_404(EventSurvey, event=event, slug=survey_slug, is_active=True) SurveyResult = EventSurveyResult slug = f'{event.slug}-{survey.slug}' else: event = None survey = get_object_or_404(GlobalSurvey, slug=survey_slug, is_active=True) SurveyResult = GlobalSurveyResult slug = survey.slug if not (request.user.is_superuser or request.user == survey.owner): return HttpResponseForbidden() results = SurveyResult.objects.filter(survey=survey).order_by('created_at') timestamp = now().strftime('%Y%m%d%H%M%S') filename = f'{slug}-results-{timestamp}.{format}' return csv_response(event, SurveyResult, results, filename=filename, dialect=CSV_EXPORT_FORMATS[format], m2m_mode='comma_separated')
def survey_export_view(request, event_slug='', survey_slug='', format='xlsx'): if event_slug: event = get_object_or_404(Event, slug=event_slug) survey = get_object_or_404(EventSurvey, event=event, slug=survey_slug, is_active=True) SurveyResult = EventSurveyResult slug = f'{event.slug}-{survey.slug}' else: event = None survey = get_object_or_404(GlobalSurvey, slug=survey_slug, is_active=True) SurveyResult = GlobalSurveyResult slug = survey.slug if not (request.user.is_superuser or request.user == survey.owner): return HttpResponseForbidden() results = SurveyResult.objects.filter(survey=survey).order_by('created_at') timestamp = now().strftime('%Y%m%d%H%M%S') filename = f'{slug}-results-{timestamp}.{format}' return csv_response( event, SurveyResult, results, filename=filename, dialect=CSV_EXPORT_FORMATS[format], m2m_mode='comma_separated' )
def tickets_admin_export_view(request, vars, event, format='xlsx'): ops = OrderProduct.objects.filter( order__event=event, # Order is confirmed order__confirm_time__isnull=False, # Order is paid order__payment_date__isnull=False, # Order is not cancelled order__cancellation_time__isnull=True, count__gte=1, ).order_by('order__payment_date', 'id') timestamp = now().strftime('%Y%m%d%H%M%S') return csv_response( event, OrderProduct, ops, dialect=next(fmt for fmt in EXPORT_FORMATS if fmt.extension == format).csv_dialect, filename=f'{event.slug}_ticketsales_{timestamp}.{format}', )
def tickets_admin_accommodation_view(request, vars, event, limit_group_id=None): if limit_group_id is not None: limit_group_id = int(limit_group_id) limit_group = get_object_or_404(LimitGroup, id=limit_group_id, event=event) query = Q( # Belongs to the selected night and school limit_groups=limit_group, ) & ( Q( # Accommodation information is manually added order_product__isnull=True ) | Q( # Order is confirmed order_product__order__confirm_time__isnull=False, # Order is paid order_product__order__payment_date__isnull=False, # Order is not cancelled order_product__order__cancellation_time__isnull=True, ) ) accommodees = AccommodationInformation.objects.filter(query).order_by('last_name', 'first_name') active_filter = limit_group else: accommodees = [] active_filter = None format = request.GET.get('format', 'screen') if format in CSV_EXPORT_FORMATS: filename = "{event.slug}-{active_filter}-{timestamp}.{format}".format( event=event, active_filter=slugify(limit_group.description), timestamp=now().strftime('%Y%m%d%H%M%S'), format=format, ) emit('core.person.exported', request=request, event=event) return csv_response(event, AccommodationInformation, accommodees, filename=filename, dialect=CSV_EXPORT_FORMATS[format]) elif format == 'screen': filters = [ (limit_group_id == lg.id, lg) for lg in LimitGroup.objects.filter( event=event, product__requires_accommodation_information=True, ).distinct() ] vars.update( accommodees=accommodees, active_filter=active_filter, filters=filters, ) return render(request, 'tickets_admin_accommodation_view.pug', vars) else: raise NotImplementedError(format)
def programme_admin_organizers_view(request, vars, event, format='screen'): programme_roles = ( ProgrammeRole.objects.filter(programme__category__event=event) .select_related('person') .select_related('programme') .select_related('role') .order_by('person__surname', 'person__first_name', 'programme__title') ) personnel_classes = PersonnelClass.objects.filter( event=event, role__personnel_class__event=event, ) personnel_class_filters = Filter(request, 'personnel_class').add_objects('role__personnel_class__slug', personnel_classes) programme_roles = personnel_class_filters.filter_queryset(programme_roles) active_filters = Filter(request, 'active').add_booleans('is_active') programme_roles = active_filters.filter_queryset(programme_roles) organizers = [] prs_by_organizer = groupby_strict(programme_roles, lambda pr: pr.person) for organizer, prs in prs_by_organizer: organizer.current_event_programme_roles = prs organizers.append(organizer) vars.update( active_filters=active_filters, export_formats=EXPORT_FORMATS, num_organizers=len(organizers), num_total_organizers=Person.objects.filter(programme__category__event=event).distinct().count(), organizers=organizers, personnel_class_filters=personnel_class_filters, ) if format == 'screen': return render(request, 'programme_admin_organizers_view.jade', vars) elif format == 'txt': emails = '\n'.join(programme_roles.order_by('person__email').values_list('person__email', flat=True).distinct()) return HttpResponse(emails, content_type='text/plain') elif format in CSV_EXPORT_FORMATS: filename = "{event.slug}_programme_organizers_{timestamp}.{format}".format( event=event, timestamp=now().strftime('%Y%m%d%H%M%S'), format=format, ) return csv_response(event, ProgrammeRole, programme_roles, dialect=CSV_EXPORT_FORMATS[format], filename=filename, m2m_mode='separate_columns', ) else: raise NotImplementedError(format)
def programme_admin_export_view(request, vars, event): from core.csv_export import csv_response programmes = Programme.objects.filter(category__event=event) filename = "{event.slug}_programmes_{timestamp}.xlsx".format( event=event, timestamp=timezone.now().strftime('%Y%m%d%H%M%S'), ) return csv_response(event, Programme, programmes, m2m_mode='comma_separated', dialect='xlsx', filename=filename, )
def badges_admin_export_view(request, vars, event, batch_id, format='csv'): if format not in CSV_EXPORT_FORMATS: raise NotImplemented(format) batch = get_object_or_404(Batch, pk=int(batch_id), event=event) badges = batch.badges.all() filename = "{event.slug}-badges-batch{batch.pk}.{format}".format( event=event, batch=batch, format=format, ) return csv_response(event, Badge, badges, filename=filename, dialect=CSV_EXPORT_FORMATS[format])
def badges_admin_export_view(request, vars, event, batch_id, format='csv'): if format not in CSV_EXPORT_FORMATS: raise NotImplemented(format) batch = get_object_or_404(Batch, pk=int(batch_id), event=event) badges = batch.badge_set.all() filename = "{event.slug}-badges-batch{batch.pk}.{format}".format( event=event, batch=batch, format=format, ) return csv_response(event, Badge, badges, filename=filename, dialect=CSV_EXPORT_FORMATS[format])
def tracon11_afterparty_participants_view(request, vars, event): assert event.slug == 'tracon11' participants = SignupExtraV2AfterpartyProxy.objects.filter(afterparty_participation=True) filename = "{event.slug}_afterparty_participants_{timestamp}.xlsx".format( event=event, timestamp=now().strftime('%Y%m%d%H%M%S'), format=format, ) return csv_response(event, SignupExtraV2AfterpartyProxy, participants, dialect='xlsx', filename=filename, m2m_mode='separate_columns', )
def tracon2018_afterparty_participants_view(request, vars, event): assert event.slug == 'tracon2018' participants = SignupExtraAfterpartyProxy.objects.filter(afterparty_participation=True) filename = "{event.slug}_afterparty_participants_{timestamp}.xlsx".format( event=event, timestamp=now().strftime('%Y%m%d%H%M%S'), format=format, ) return csv_response(event, SignupExtraAfterpartyProxy, participants, dialect='xlsx', filename=filename, m2m_mode='separate_columns', )
def tickets_admin_shirts_view(request, vars, event, format='screen'): shirt_sizes = ShirtSize.objects.filter(type__event=event).annotate( count=Sum( Case( When(shirt_orders__order__confirm_time__isnull=False, shirt_orders__order__payment_date__isnull=False, shirt_orders__order__cancellation_time__isnull=True, then='shirt_orders__count'), default=0, output_field=IntegerField(), ), )).filter(count__gt=0).order_by('type__id', 'id') shirt_orders = ShirtOrder.objects.filter( order__event=event, order__confirm_time__isnull=False, order__payment_date__isnull=False, order__cancellation_time__isnull=True, ).order_by('order__customer__last_name', 'order__customer__first_name', 'size__type__id', 'size__id') if format == 'screen': vars.update( export_formats=EXPORT_FORMATS, shirt_sizes=shirt_sizes, shirt_sizes_total=shirt_sizes.aggregate(Sum('count'))['count__sum'] or 0, shirt_orders=shirt_orders, shirt_orders_total=shirt_orders.aggregate( Sum('count'))['count__sum'] or 0, ) return render(request, 'tickets_admin_shirts_view.pug', vars) elif format in CSV_EXPORT_FORMATS: filename = "{event.slug}_shirts_{timestamp}.{format}".format( event=event, timestamp=now().strftime('%Y%m%d%H%M%S'), format=format, ) return csv_response( event, ShirtOrder, shirt_orders, dialect=CSV_EXPORT_FORMATS[format], filename=filename, m2m_mode='comma_separated', )
def traconpaidat2019_custom_shirts_view(request, vars, event): assert event.slug == 'traconpaidat2019' shirts = CustomShirtProxy.objects.all() filename = "{event.slug}_nimikoidut_{timestamp}.xlsx".format( event=event, timestamp=now().strftime('%Y%m%d%H%M%S'), format=format, ) emit('core.person.exported', request=request, event=event) return csv_response(event, CustomShirtProxy, shirts, dialect='xlsx', filename=filename, m2m_mode='separate_columns', )
def tickets_admin_shirts_view(request, vars, event, format='screen'): shirt_sizes = ShirtSize.objects.filter(type__event=event).annotate(count=Sum( Case( When( shirt_orders__order__confirm_time__isnull=False, shirt_orders__order__payment_date__isnull=False, shirt_orders__order__cancellation_time__isnull=True, then='shirt_orders__count' ), default=0, output_field=IntegerField(), ), )).filter(count__gt=0).order_by('type__id', 'id') shirt_orders = ShirtOrder.objects.filter( order__event=event, order__confirm_time__isnull=False, order__payment_date__isnull=False, order__cancellation_time__isnull=True, ).order_by('order__customer__last_name', 'order__customer__first_name', 'size__type__id', 'size__id') if format == 'screen': vars.update( export_formats=EXPORT_FORMATS, shirt_sizes=shirt_sizes, shirt_sizes_total=shirt_sizes.aggregate(Sum('count'))['count__sum'] or 0, shirt_orders=shirt_orders, shirt_orders_total=shirt_orders.aggregate(Sum('count'))['count__sum'] or 0, ) return render(request, 'tickets_admin_shirts_view.pug', vars) elif format in CSV_EXPORT_FORMATS: filename = "{event.slug}_shirts_{timestamp}.{format}".format( event=event, timestamp=now().strftime('%Y%m%d%H%M%S'), format=format, ) return csv_response(event, ShirtOrder, shirt_orders, dialect=CSV_EXPORT_FORMATS[format], filename=filename, m2m_mode='comma_separated', )
def traconpaidat2019_custom_shirts_view(request, vars, event): assert event.slug == 'traconpaidat2019' shirts = CustomShirtProxy.objects.all() filename = "{event.slug}_nimikoidut_{timestamp}.xlsx".format( event=event, timestamp=now().strftime('%Y%m%d%H%M%S'), format=format, ) emit('core.person.exported', request=request, event=event) return csv_response( event, CustomShirtProxy, shirts, dialect='xlsx', filename=filename, m2m_mode='separate_columns', )
def labour_admin_export_view(request, vars, event): signup_ids = request.GET.get('signup_ids', None) if signup_ids == "": # fmh signups = [] elif signup_ids is not None: signup_ids = [int(id) for id in signup_ids.split(',')] signups = Signup.objects.filter(event=event, pk__in=signup_ids) else: signups = Signup.objects.filter(event=event) filename="{event.slug}_signups_{timestamp}.xlsx".format( event=event, timestamp=timezone.now().strftime('%Y%m%d%H%M%S'), ) return csv_response(event, Signup, signups, dialect='xlsx', filename=filename, m2m_mode='separate_columns', )
def membership_admin_members_view(request, vars, organization, format='screen'): memberships = organization.memberships.all().select_related('person') num_all_members = memberships.count() state_filters = Filter(request, 'state').add_choices('state', STATE_CHOICES) memberships = state_filters.filter_queryset(memberships) filter_active = any(f.selected_slug != f.default for f in [ state_filters, ]) memberships = memberships.order_by('person__surname', 'person__official_first_names') if request.method == 'POST' and state_filters.selected_slug == 'approval': # PLEASE DON'T: locally cached objects do not get updated and apply_state does not do the needful # memberships.update(state='in_effect') # TODO encap in Membership for membership in memberships: membership.state = 'in_effect' membership.save() membership.apply_state() messages.success(request, 'Hyväksyntää odottavat jäsenhakemukset hyväksyttiin.') return redirect('membership_admin_members_view', organization.slug) export_type = state_filters.selected_slug or 'all' export_type_verbose = EXPORT_TYPE_VERBOSE[export_type] title = '{organization.name} – {export_type_verbose}'.format( organization=organization, export_type_verbose=export_type_verbose, ) vars.update( show_approve_all_button=state_filters.selected_slug == 'approval', memberships=memberships, num_members=memberships.count(), num_all_members=num_all_members, state_filters=state_filters, filter_active=filter_active, css_to_show_filter_panel='in' if filter_active else '', export_formats=EXPORT_FORMATS, now=now(), title=title, ) if format in HTML_TEMPLATES: return render(request, HTML_TEMPLATES[format], vars) elif format in CSV_EXPORT_FORMATS: filename = "{organization.slug}_members_{timestamp}.{format}".format( organization=organization, timestamp=now().strftime('%Y%m%d%H%M%S'), format=format, ) emit('core.person.exported', request=request, organization=organization) return csv_response(organization, Membership, memberships, dialect=format, filename=filename, m2m_mode='separate_columns', ) else: raise NotImplementedError(format)
def badges_admin_badges_view(request, vars, event, personnel_class_slug=None): if request.method == 'POST': form = initialize_form(HiddenBadgeCrouchingForm, request) if form.is_valid(): badge = get_object_or_404(BadgeManagementProxy, pk=form.cleaned_data['badge_id']) if 'revoke-badge' in request.POST: if not badge.can_revoke: messages.error(request, _('This badge cannot be revoked here because it is managed ' 'by either the labour or the programme management system.')) elif badge.is_revoked: messages.warning(request, _('The badge had already been revoked.')) else: badge.revoke(user=request.user) messages.success(request, _('The badge has now been revoked.')) elif 'clear-revoked' in request.POST: if not badge.can_unrevoke: messages.error(request, _('This revoked badge cannot be un-revoked here because it is managed ' 'by either the labour or the programme management system.')) if not badge.is_revoked: message.warning(request, _('The badge was already valid.')) else: badge.unrevoke() messages.success(request, _('The badge has been restored.')) elif 'mark-printed' in request.POST: badge.is_printed_separately = True badge.save() messages.success(request, 'Badge on merkitty erikseen tulostetuksi.') elif 'clear-printed' in request.POST: badge.is_printed_separately = False badge.save() messages.success(request, 'Badgesta on pyyhitty erikseen tulostettu -merkintä.') else: messages.error(request, 'Kelvoton pyyntö.') return redirect(request.path) else: format = request.GET.get('format', 'screen') badge_criteria = dict(personnel_class__event=event) active_filter = None viewing_yoink_list = False template_subtype = 'normal' if personnel_class_slug is not None: if personnel_class_slug == 'yoink': viewing_yoink_list = True active_filter = badges_to_yoink_fake_personnel_class badge_criteria.update(revoked_at__isnull=False) template_subtype = 'yoink' else: active_filter = get_object_or_404(PersonnelClass, event=event, slug=personnel_class_slug) badge_criteria.update(personnel_class=active_filter) # Non-yoink paper lists only show non-revoked badges. # Yoink list only shows revoked badges. if format != 'screen' and personnel_class_slug != 'yoink': badge_criteria.update(revoked_at__isnull=True) badges = BadgeManagementProxy.objects.filter(**badge_criteria).order_by(*BADGE_ORDER) if format in CSV_EXPORT_FORMATS: filename = "{event.slug}-badges-{badge_filter}{timestamp}.{format}".format( event=event, badge_filter="{personnel_class_slug}-".format(personnel_class_slug=personnel_class_slug) if personnel_class_slug is not None else '', timestamp=timezone.now().strftime('%Y%m%d%H%M%S'), format=format, ) return csv_response(event, Badge, badges, filename=filename, dialect=CSV_EXPORT_FORMATS[format]) elif format in BADGE_LIST_TEMPLATES: page_template = BADGE_LIST_TEMPLATES[format][template_subtype] title = "{event.name} – {qualifier}".format( event=event, qualifier=active_filter.name if active_filter else 'Nimilista', ) filters = [ (personnel_class_slug == personnel_class.slug, personnel_class) for personnel_class in PersonnelClass.objects.filter(event=event) ] filters.append( (viewing_yoink_list, badges_to_yoink_fake_personnel_class) ) vars.update( active_filter=active_filter, filters=filters, now=timezone.now(), title=title, should_display_personnel_class=not active_filter or personnel_class_slug == 'yoink', can_manually_add_badge=personnel_class_slug != 'yoink', ) if personnel_class_slug == 'yoink' and format == 'print': badges_by_personnel_class = groupby_strict(badges, lambda badge: badge.personnel_class) vars.update(badges_by_personnel_class=badges_by_personnel_class) else: vars.update(badges=badges) return render(request, page_template, vars) else: raise NotImplementedError(format)
def tickets_admin_accommodation_view(request, vars, event, limit_group_id=None): if limit_group_id is not None: limit_group_id = int(limit_group_id) limit_group = get_object_or_404(LimitGroup, id=limit_group_id, event=event) query = Q( # Belongs to the selected night and school limit_groups=limit_group, ) & ( Q( # Accommodation information is manually added order_product__isnull=True) | Q( # Order is confirmed order_product__order__confirm_time__isnull=False, # Order is paid order_product__order__payment_date__isnull=False, # Order is not cancelled order_product__order__cancellation_time__isnull=True, )) accommodees = AccommodationInformation.objects.filter(query).order_by( 'last_name', 'first_name') active_filter = limit_group else: accommodees = [] active_filter = None limit_group = None format = request.GET.get('format', 'screen') if format in CSV_EXPORT_FORMATS: filename = "{event.slug}-{active_filter}-{timestamp}.{format}".format( event=event, active_filter=slugify(limit_group.description) if limit_group else "tickets", timestamp=now().strftime('%Y%m%d%H%M%S'), format=format, ) emit('core.person.exported', request=request, event=event) return csv_response(event, AccommodationInformation, accommodees, filename=filename, dialect=CSV_EXPORT_FORMATS[format]) elif format == 'screen': filters = [(limit_group_id == lg.id, lg) for lg in LimitGroup.objects.filter( event=event, product__requires_accommodation_information=True, ).distinct()] vars.update( accommodees=accommodees, active_filter=active_filter, filters=filters, ) return render(request, 'tickets_admin_accommodation_view.pug', vars) else: raise NotImplementedError(format)
def labour_admin_shifts_view(request, vars, event, format='screen'): shifts = (Shift.objects.filter( job__job_category__event=event).select_related( 'signup__person').select_related('job__job_category').order_by( 'start_time', 'signup__person__surname', 'signup__person__first_name')) num_total_shifts = shifts.count() job_categories = JobCategory.objects.filter(event=event) job_category_filters = Filter(request, 'category').add_objects( 'job__job_category__slug', job_categories) shifts = job_category_filters.filter_queryset(shifts) sorter = Sorter(request, "sort") sorter.add("name", name='Nimen mukaan', definition=( 'signup__person__surname', 'signup__person__first_name', 'start_time', )) sorter.add("job", name='Tehtävän mukaan', definition=( 'job__job_category__name', 'job__title', 'start_time', 'signup__person__surname', 'signup__person__first_name', )) sorter.add("time", name='Alkuajan mukaan', definition=( 'start_time', 'signup__person__surname', 'signup__person__first_name', )) shifts = sorter.order_queryset(shifts) t = now() active_filter = job_category_filters.selected_definition if active_filter: title = _('{event_name}: Shift list – {job_category_name}').format( event_name=event.name, job_category_name=active_filter.name if active_filter else 'Nimilista', ) else: title = _('{event_name}: Shift list').format(event_name=event.name, ) vars.update( active_filter=active_filter, export_formats=EXPORT_FORMATS, job_category_filters=job_category_filters, now=t, num_total_shifts=num_total_shifts, shifts=shifts, show_actions=(format == 'screen'), sorter=sorter, title=title, ) if format in HTML_TEMPLATES: template = HTML_TEMPLATES[format] return render(request, template, vars) elif format in CSV_EXPORT_FORMATS: filename = "{event.slug}_shifts_{timestamp}.{format}".format( event=event, timestamp=t.strftime('%Y%m%d%H%M%S'), format=format, ) return csv_response( event, Shift, shifts, dialect=CSV_EXPORT_FORMATS[format], filename=filename, m2m_mode='separate_columns', ) else: raise NotImplementedError(format)
def labour_admin_signups_view(request, vars, event, format='screen'): meta = event.labour_event_meta SignupClass = SignupCertificateProxy if format == 'html' else Signup SignupExtra = meta.signup_extra_model signups = SignupClass.objects.filter(event=event) signups = signups.select_related('person').select_related('event') signups = signups.prefetch_related('job_categories').prefetch_related('job_categories_accepted') if format in HTML_TEMPLATES: num_all_signups = signups.count() job_categories = event.jobcategory_set.all() personnel_classes = event.personnelclass_set.filter(app_label='labour') job_category_filters = Filter(request, "job_category").add_objects("job_categories__slug", job_categories) signups = job_category_filters.filter_queryset(signups) job_category_accepted_filters = Filter(request, "job_category_accepted").add_objects("job_categories_accepted__slug", job_categories) signups = job_category_accepted_filters.filter_queryset(signups) personnel_class_filters = Filter(request, "personnel_class").add_objects("personnel_classes__slug", personnel_classes) signups = personnel_class_filters.filter_queryset(signups) state_filter = SignupStateFilter(request, "state") signups = state_filter.filter_queryset(signups) if SignupExtra.get_field('night_work'): night_work_path = '{prefix}{app_label}_signup_extra__night_work'.format( prefix='person__' if SignupExtra.schema_version >= 2 else '', app_label=SignupExtra._meta.app_label ) night_work_filter = Filter(request, 'night_work').add_booleans(night_work_path) signups = night_work_filter.filter_queryset(signups) else: night_work_filter = None sorter = Sorter(request, "sort") sorter.add("name", name='Sukunimi, Etunimi', definition=('person__surname', 'person__first_name')) sorter.add("newest", name='Uusin ensin', definition=('-created_at',)) sorter.add("oldest", name='Vanhin ensin', definition=('created_at',)) signups = sorter.order_queryset(signups) if request.method == 'POST': action = request.POST.get('action', None) if action == 'reject': SignupClass.mass_reject(signups) elif action == 'request_confirmation': SignupClass.mass_request_confirmation(signups) elif action == 'send_shifts': SignupClass.mass_send_shifts(signups) else: messages.error(request, 'Ei semmosta toimintoa oo.') return redirect('labour_admin_signups_view', event.slug) elif format in HTML_TEMPLATES: num_would_mass_reject = signups.filter(**SignupClass.get_state_query_params('new')).count() num_would_mass_request_confirmation = signups.filter(**SignupClass.get_state_query_params('accepted')).count() num_would_send_shifts = SignupClass.filter_signups_for_mass_send_shifts(signups).count() mass_operations = OrderedDict([ ('reject', MassOperation( 'reject', 'labour-admin-mass-reject-modal', 'Hylkää kaikki käsittelemättömät...', num_would_mass_reject, )), ('request_confirmation', MassOperation( 'request_confirmation', 'labour-admin-mass-request-confirmation-modal', 'Vaadi vahvistusta kaikilta hyväksytyiltä...', num_would_mass_request_confirmation, )), ('send_shifts', MassOperation( 'send_shifts', 'labour-admin-mass-send-shifts-modal', 'Lähetä vuorot kaikille vuoroja odottaville, joille ne on määritelty...', num_would_send_shifts, )), ]) vars.update( export_formats=EXPORT_FORMATS, job_category_accepted_filters=job_category_accepted_filters, job_category_filters=job_category_filters, mass_operations=mass_operations, night_work_filter=night_work_filter, num_all_signups=num_all_signups, num_signups=signups.count(), personnel_class_filters=personnel_class_filters, signups=signups, sorter=sorter, state_filter=state_filter, css_to_show_filter_panel='in' if any(f.selected_slug != f.default for f in [ job_category_filters, job_category_accepted_filters, personnel_class_filters, state_filter, sorter, ]) else '', now=now(), ) html_template = HTML_TEMPLATES[format] return render(request, html_template, vars) elif format in CSV_EXPORT_FORMATS: filename = "{event.slug}_signups_{timestamp}.{format}".format( event=event, timestamp=now().strftime('%Y%m%d%H%M%S'), format=format, ) return csv_response(event, SignupClass, signups, dialect=CSV_EXPORT_FORMATS[format], filename=filename, m2m_mode='separate_columns', ) else: raise NotImplementedError(format)
def badges_admin_badges_view(request, vars, event, personnel_class_slug=None): if request.method == 'POST': form = initialize_form(HiddenBadgeCrouchingForm, request) if form.is_valid(): badge = get_object_or_404(BadgeManagementProxy, pk=form.cleaned_data['badge_id']) if 'revoke-badge' in request.POST: if not badge.can_revoke: messages.error( request, _('This badge cannot be revoked here because it is managed ' 'by either the labour or the programme management system.' )) elif badge.is_revoked: messages.warning(request, _('The badge had already been revoked.')) else: badge.revoke(user=request.user) messages.success(request, _('The badge has now been revoked.')) elif 'clear-revoked' in request.POST: if not badge.can_unrevoke: messages.error( request, _('This revoked badge cannot be un-revoked here because it is managed ' 'by either the labour or the programme management system.' )) if not badge.is_revoked: message.warning(request, _('The badge was already valid.')) else: badge.unrevoke() messages.success(request, _('The badge has been restored.')) elif 'mark-printed' in request.POST: badge.is_printed_separately = True badge.save() messages.success(request, 'Badge on merkitty erikseen tulostetuksi.') elif 'clear-printed' in request.POST: badge.is_printed_separately = False badge.save() messages.success( request, 'Badgesta on pyyhitty erikseen tulostettu -merkintä.') else: messages.error(request, 'Kelvoton pyyntö.') return redirect(request.path) else: format = request.GET.get('format', 'screen') badge_criteria = dict(personnel_class__event=event) active_filter = None viewing_yoink_list = False template_subtype = 'normal' if personnel_class_slug is not None: if personnel_class_slug == 'yoink': viewing_yoink_list = True active_filter = badges_to_yoink_fake_personnel_class badge_criteria.update(revoked_at__isnull=False) template_subtype = 'yoink' else: active_filter = get_object_or_404(PersonnelClass, event=event, slug=personnel_class_slug) badge_criteria.update(personnel_class=active_filter) # Non-yoink paper lists only show non-revoked badges. # Yoink list only shows revoked badges. if format != 'screen' and personnel_class_slug != 'yoink': badge_criteria.update(revoked_at__isnull=True) badges = BadgeManagementProxy.objects.filter( **badge_criteria).order_by(*BADGE_ORDER) if format in CSV_EXPORT_FORMATS: filename = "{event.slug}-badges-{badge_filter}{timestamp}.{format}".format( event=event, badge_filter="{personnel_class_slug}-".format( personnel_class_slug=personnel_class_slug) if personnel_class_slug is not None else '', timestamp=timezone.now().strftime('%Y%m%d%H%M%S'), format=format, ) return csv_response(event, Badge, badges, filename=filename, dialect=CSV_EXPORT_FORMATS[format]) elif format in BADGE_LIST_TEMPLATES: page_template = BADGE_LIST_TEMPLATES[format][template_subtype] title = "{event.name} – {qualifier}".format( event=event, qualifier=active_filter.name if active_filter else 'Nimilista', ) filters = [(personnel_class_slug == personnel_class.slug, personnel_class) for personnel_class in PersonnelClass.objects.filter( event=event)] filters.append( (viewing_yoink_list, badges_to_yoink_fake_personnel_class)) vars.update( active_filter=active_filter, filters=filters, now=timezone.now(), title=title, should_display_personnel_class=not active_filter or personnel_class_slug == 'yoink', can_manually_add_badge=personnel_class_slug != 'yoink', ) if personnel_class_slug == 'yoink' and format == 'print': badges_by_personnel_class = groupby_strict( badges, lambda badge: badge.personnel_class) vars.update( badges_by_personnel_class=badges_by_personnel_class) else: vars.update(badges=badges) return render(request, page_template, vars) else: raise NotImplementedError(format)
def labour_admin_signups_view(request, vars, event, format='screen'): meta = event.labour_event_meta SignupClass = SignupCertificateProxy if format == 'html' else Signup SignupExtra = meta.signup_extra_model signups = SignupClass.objects.filter(event=event) signups = signups.select_related('person').select_related('event') signups = signups.prefetch_related('job_categories').prefetch_related( 'job_categories_accepted') if format in HTML_TEMPLATES: num_all_signups = signups.count() job_categories = event.jobcategory_set.all() personnel_classes = event.personnelclass_set.filter(app_label='labour') job_category_filters = Filter(request, "job_category").add_objects( "job_categories__slug", job_categories) signups = job_category_filters.filter_queryset(signups) job_category_accepted_filters = Filter( request, "job_category_accepted").add_objects("job_categories_accepted__slug", job_categories) signups = job_category_accepted_filters.filter_queryset(signups) personnel_class_filters = Filter(request, "personnel_class").add_objects( "personnel_classes__slug", personnel_classes) signups = personnel_class_filters.filter_queryset(signups) state_filter = SignupStateFilter(request, "state") signups = state_filter.filter_queryset(signups) if SignupExtra.get_field('night_work'): night_work_path = '{prefix}{app_label}_signup_extra__night_work'.format( prefix='person__' if SignupExtra.schema_version >= 2 else '', app_label=SignupExtra._meta.app_label) night_work_filter = Filter(request, 'night_work').add_booleans(night_work_path) signups = night_work_filter.filter_queryset(signups) else: night_work_filter = None sorter = Sorter(request, "sort") sorter.add("name", name='Sukunimi, Etunimi', definition=('person__surname', 'person__first_name')) sorter.add("newest", name='Uusin ensin', definition=('-created_at', )) sorter.add("oldest", name='Vanhin ensin', definition=('created_at', )) signups = sorter.order_queryset(signups) if request.method == 'POST': action = request.POST.get('action', None) if action == 'reject': SignupClass.mass_reject(signups) elif action == 'request_confirmation': SignupClass.mass_request_confirmation(signups) elif action == 'send_shifts': SignupClass.mass_send_shifts(signups) else: messages.error(request, 'Ei semmosta toimintoa oo.') return redirect('labour_admin_signups_view', event.slug) elif format in HTML_TEMPLATES: num_would_mass_reject = signups.filter( **SignupClass.get_state_query_params('new')).count() num_would_mass_request_confirmation = signups.filter( **SignupClass.get_state_query_params('accepted')).count() num_would_send_shifts = SignupClass.filter_signups_for_mass_send_shifts( signups).count() mass_operations = OrderedDict([ ('reject', MassOperation( 'reject', 'labour-admin-mass-reject-modal', 'Hylkää kaikki käsittelemättömät...', num_would_mass_reject, )), ('request_confirmation', MassOperation( 'request_confirmation', 'labour-admin-mass-request-confirmation-modal', 'Vaadi vahvistusta kaikilta hyväksytyiltä...', num_would_mass_request_confirmation, )), ('send_shifts', MassOperation( 'send_shifts', 'labour-admin-mass-send-shifts-modal', 'Lähetä vuorot kaikille vuoroja odottaville, joille ne on määritelty...', num_would_send_shifts, )), ]) vars.update( export_formats=EXPORT_FORMATS, job_category_accepted_filters=job_category_accepted_filters, job_category_filters=job_category_filters, mass_operations=mass_operations, night_work_filter=night_work_filter, num_all_signups=num_all_signups, num_signups=signups.count(), personnel_class_filters=personnel_class_filters, signups=signups, sorter=sorter, state_filter=state_filter, css_to_show_filter_panel='in' if any( f.selected_slug != f.default for f in [ job_category_filters, job_category_accepted_filters, personnel_class_filters, state_filter, sorter, ]) else '', now=now(), ) html_template = HTML_TEMPLATES[format] return render(request, html_template, vars) elif format in CSV_EXPORT_FORMATS: filename = "{event.slug}_signups_{timestamp}.{format}".format( event=event, timestamp=now().strftime('%Y%m%d%H%M%S'), format=format, ) emit('core.person.exported', request=request, event=event) return csv_response( event, SignupClass, signups, dialect=CSV_EXPORT_FORMATS[format], filename=filename, m2m_mode='separate_columns', ) else: raise NotImplementedError(format)
def labour_admin_shifts_view(request, vars, event, format='screen'): shifts = ( Shift.objects.filter(job__job_category__event=event) .select_related('signup__person') .select_related('job__job_category') .order_by('start_time', 'signup__person__surname', 'signup__person__first_name') ) num_total_shifts = shifts.count() job_categories = JobCategory.objects.filter(event=event) job_category_filters = Filter(request, 'category').add_objects('job__job_category__slug', job_categories) shifts = job_category_filters.filter_queryset(shifts) sorter = Sorter(request, "sort") sorter.add("name", name='Nimen mukaan', definition=( 'signup__person__surname', 'signup__person__first_name', 'start_time', ) ) sorter.add("job", name='Tehtävän mukaan', definition=( 'job__job_category__name', 'job__title', 'start_time', 'signup__person__surname', 'signup__person__first_name', ) ) sorter.add("time", name='Alkuajan mukaan', definition=( 'start_time', 'signup__person__surname', 'signup__person__first_name', ) ) shifts = sorter.order_queryset(shifts) t = now() active_filter = job_category_filters.selected_definition if active_filter: title = _('{event_name}: Shift list – {job_category_name}').format( event_name=event.name, job_category_name=active_filter.name if active_filter else 'Nimilista', ) else: title = _('{event_name}: Shift list').format( event_name=event.name, ) vars.update( active_filter=active_filter, export_formats=EXPORT_FORMATS, job_category_filters=job_category_filters, now=t, num_total_shifts=num_total_shifts, shifts=shifts, show_actions=(format == 'screen'), sorter=sorter, title=title, ) if format in HTML_TEMPLATES: template = HTML_TEMPLATES[format] return render(request, template, vars) elif format in CSV_EXPORT_FORMATS: filename = "{event.slug}_shifts_{timestamp}.{format}".format( event=event, timestamp=t.strftime('%Y%m%d%H%M%S'), format=format, ) return csv_response(event, Shift, shifts, dialect=CSV_EXPORT_FORMATS[format], filename=filename, m2m_mode='separate_columns', ) else: raise NotImplementedError(format)
def membership_admin_members_view(request, vars, organization, format='screen'): memberships = organization.memberships.all().select_related('person') num_all_members = memberships.count() state_filters = Filter(request, 'state').add_choices('state', STATE_CHOICES) memberships = state_filters.filter_queryset(memberships) filter_active = any(f.selected_slug != f.default for f in [ state_filters, ]) memberships = memberships.order_by('person__surname', 'person__official_first_names') if request.method == 'POST' and state_filters.selected_slug == 'approval': # PLEASE DON'T: locally cached objects do not get updated and apply_state does not do the needful # memberships.update(state='in_effect') # TODO encap in Membership for membership in memberships: membership.state = 'in_effect' membership.save() membership.apply_state() messages.success( request, 'Hyväksyntää odottavat jäsenhakemukset hyväksyttiin.') return redirect('membership_admin_members_view', organization.slug) export_type = state_filters.selected_slug or 'all' export_type_verbose = EXPORT_TYPE_VERBOSE[export_type] title = '{organization.name} – {export_type_verbose}'.format( organization=organization, export_type_verbose=export_type_verbose, ) vars.update( show_approve_all_button=state_filters.selected_slug == 'approval', memberships=memberships, num_members=memberships.count(), num_all_members=num_all_members, state_filters=state_filters, filter_active=filter_active, css_to_show_filter_panel='in' if filter_active else '', export_formats=EXPORT_FORMATS, now=now(), title=title, ) if format in HTML_TEMPLATES: return render(request, HTML_TEMPLATES[format], vars) elif format in CSV_EXPORT_FORMATS: filename = "{organization.slug}_members_{timestamp}.{format}".format( organization=organization, timestamp=now().strftime('%Y%m%d%H%M%S'), format=format, ) emit('core.person.exported', request=request, organization=organization) return csv_response( organization, Membership, memberships, dialect=format, filename=filename, m2m_mode='separate_columns', ) else: raise NotImplementedError(format)
def admin_view(request, vars, event, format='screen'): programmes = ( Programme.objects.filter(category__event=event).select_related( 'category__event').select_related('room') # Does not do the needful due to formatted_organizers operating on the "through" model # .prefetch_related('organizers') ) categories = Category.objects.filter(event=event) category_filters = Filter(request, 'category').add_objects('category__slug', categories) programmes = category_filters.filter_queryset(programmes) rooms = event.rooms.all() room_filters = Filter(request, 'room').add_objects('room__slug', rooms) programmes = room_filters.filter_queryset(programmes) state_filters = Filter(request, 'state').add_choices('state', STATE_CHOICES) state_filters.filter_queryset(programmes) programmes = state_filters.filter_queryset(programmes) video_permission_filters = Filter(request, 'video_permission') video_permission_filters.add_choices('video_permission', VIDEO_PERMISSION_CHOICES) programmes = video_permission_filters.filter_queryset(programmes) photography_filters = Filter(request, 'photography').add_choices( 'photography', PHOTOGRAPHY_CHOICES) programmes = photography_filters.filter_queryset(programmes) forms = AlternativeProgrammeForm.objects.filter(event=event) if forms.exists(): form_filters = Filter(request, 'form_used').add_objects('form_used__slug', forms) programmes = form_filters.filter_queryset(programmes) else: form_filters = None if format != 'html': sorter = Sorter(request, 'sort') sorter.add('title', name='Otsikko', definition=('title', )) sorter.add('start_time', name='Alkuaika', definition=('start_time', 'room')) sorter.add('room', name='Sali', definition=('room', 'start_time')) sorter.add('created_at', name='Uusin ensin', definition=('-created_at', )) programmes = sorter.order_queryset(programmes) if event.slug.startswith('ropecon'): miniworkshop_filters = Filter(request, 'ropecon_miniworkshop') miniworkshopinator = lambda is_miniworkshop: lambda programme: programme.form_used and programme.form_used.slug == 'default' and ( programme.category.slug == 'mini') == is_miniworkshop miniworkshop_filters.add('1', 'Figutyöpajat', miniworkshopinator(True)) miniworkshop_filters.add('0', 'Muu ohjelma, ei figutyöpaja', miniworkshopinator(False)) programmes = miniworkshop_filters.filter_queryset(programmes) else: miniworkshop_filters = None if format == 'screen': vars.update( category_filters=category_filters, export_formats=EXPORT_FORMATS, form_filters=form_filters, miniworkshop_filters=miniworkshop_filters, photography_filters=photography_filters, programmes=programmes, room_filters=room_filters, sorter=sorter, state_filters=state_filters, video_permission_filters=video_permission_filters, ) return render(request, 'programme_admin_view.pug', vars) elif format in CSV_EXPORT_FORMATS: filename = "{event.slug}_programmes_{timestamp}.{format}".format( event=event, timestamp=timezone.now().strftime('%Y%m%d%H%M%S'), format=format, ) return csv_response( event, Programme, programmes, m2m_mode='comma_separated', dialect=CSV_EXPORT_FORMATS[format], filename=filename, ) elif format == 'html': title = "{event_name}: Ohjelma".format(event_name=event.name) if room_filters.selected_slug is not None: room = Room.objects.get(event=event, slug=room_filters.selected_slug) title += ' – {room.name}'.format(room=room) if state_filters.selected_slug is not None: state_name = next(name for (slug, name) in STATE_CHOICES if slug == state_filters.selected_slug) title += ' ({state_name})'.format(state_name=state_name) programmes_by_start_time = group_programmes_by_start_time(programmes) vars.update( title=title, now=timezone.now(), programmes=programmes, programmes_by_start_time=programmes_by_start_time, ) return render(request, 'programme_admin_print_view.pug', vars) else: raise NotImplementedError(format)
def programme_admin_view(request, vars, event, format='screen'): programmes = ( Programme.objects.filter(category__event=event) .select_related('category__event') .select_related('room') # Does not do the needful due to formatted_organizers operating on the "through" model # .prefetch_related('organizers') ) categories = Category.objects.filter(event=event) category_filters = Filter(request, 'category').add_objects('category__slug', categories) programmes = category_filters.filter_queryset(programmes) rooms = Room.get_rooms_for_event(event) room_filters = Filter(request, 'room').add_objects('room__slug', rooms) programmes = room_filters.filter_queryset(programmes) state_filters = Filter(request, 'state').add_choices('state', STATE_CHOICES) state_filters.filter_queryset(programmes) programmes = state_filters.filter_queryset(programmes) video_permission_filters = Filter(request, 'video_permission').add_choices('video_permission', VIDEO_PERMISSION_CHOICES) video_permission_filters.filter_queryset(programmes) programmes = video_permission_filters.filter_queryset(programmes) photography_filters = Filter(request, 'photography').add_choices('photography', PHOTOGRAPHY_CHOICES) photography_filters.filter_queryset(programmes) programmes = photography_filters.filter_queryset(programmes) forms = AlternativeProgrammeForm.objects.filter(event=event) if forms.exists(): form_filters = Filter(request, 'form_used').add_objects('form_used__slug', forms) programmes = form_filters.filter_queryset(programmes) else: form_filters = None if format != 'html': sorter = Sorter(request, 'sort') sorter.add('title', name='Otsikko', definition=('title',)) sorter.add('start_time', name='Alkuaika', definition=('start_time','room')) sorter.add('room', name='Sali', definition=('room','start_time')) sorter.add('created_at', name='Uusin ensin', definition=('-created_at',)) programmes = sorter.order_queryset(programmes) if format == 'screen': vars.update( category_filters=category_filters, export_formats=EXPORT_FORMATS, form_filters=form_filters, photography_filters=photography_filters, programmes=programmes, room_filters=room_filters, sorter=sorter, state_filters=state_filters, video_permission_filters=video_permission_filters, ) return render(request, 'programme_admin_view.jade', vars) elif format in CSV_EXPORT_FORMATS: filename = "{event.slug}_programmes_{timestamp}.xlsx".format( event=event, timestamp=timezone.now().strftime('%Y%m%d%H%M%S'), ) return csv_response(event, Programme, programmes, m2m_mode='comma_separated', dialect='xlsx', filename=filename, ) elif format == 'html': title = "{event_name}: Ohjelma".format(event_name=event.name) if room_filters.selected_slug != None: room = Room.objects.get(slug=room_filters.selected_slug) title += ' – {room.name}'.format(room=room) if state_filters.selected_slug != None: state_name = next(name for (slug, name) in STATE_CHOICES if slug == state_filters.selected_slug) title += ' ({state_name})'.format(state_name=state_name) programmes_by_start_time = group_programmes_by_start_time(programmes) vars.update( title=title, now=timezone.now(), programmes=programmes, programmes_by_start_time=programmes_by_start_time, ) return render(request, 'programme_admin_print_view.jade', vars) else: raise NotImplementedError(format)
def programme_admin_view(request, vars, event, format='screen'): programmes = Programme.objects.filter(category__event=event) categories = Category.objects.filter(event=event) category_filters = Filter(request, 'category').add_objects('category__slug', categories) programmes = category_filters.filter_queryset(programmes) rooms = Room.get_rooms_for_event(event) room_filters = Filter(request, 'room').add_objects('room__slug', rooms) programmes = room_filters.filter_queryset(programmes) state_filters = Filter(request, 'state').add_choices('state', STATE_CHOICES) state_filters.filter_queryset(programmes) programmes = state_filters.filter_queryset(programmes) if format != 'html': sorter = Sorter(request, 'sort') sorter.add('title', name='Otsikko', definition=('title',)) sorter.add('start_time', name='Alkuaika', definition=('start_time','room')) sorter.add('room', name='Sali', definition=('room','start_time')) programmes = sorter.order_queryset(programmes) if format == 'screen': vars.update( category_filters=category_filters, export_formats=EXPORT_FORMATS, programmes=programmes, room_filters=room_filters, sorter=sorter, state_filters=state_filters, ) return render(request, 'programme_admin_view.jade', vars) elif format in CSV_EXPORT_FORMATS: filename = "{event.slug}_programmes_{timestamp}.xlsx".format( event=event, timestamp=timezone.now().strftime('%Y%m%d%H%M%S'), ) return csv_response(event, Programme, programmes, m2m_mode='comma_separated', dialect='xlsx', filename=filename, ) elif format == 'html': title = u"{event_name}: Ohjelma".format(event_name=event.name) if room_filters.selected_slug != None: room = Room.objects.get(slug=room_filters.selected_slug) title += ' – {room.name}'.format(room=room) if state_filters.selected_slug != None: state_name = next(name for (slug, name) in STATE_CHOICES if slug == state_filters.selected_slug) title += ' ({state_name})'.format(state_name=state_name) programmes_by_start_time = group_programmes_by_start_time(programmes) vars.update( title=title, now=timezone.now(), programmes=programmes, programmes_by_start_time=programmes_by_start_time, ) return render(request, 'programme_admin_print_view.jade', vars) else: raise NotImplementedError(format)
def membership_admin_members_view(request, vars, organization, format='screen'): memberships = organization.memberships.all().select_related('person') num_all_members = memberships.count() state_filters = Filter(request, 'state').add_choices('state', STATE_CHOICES) memberships = state_filters.filter_queryset(memberships) filter_active = any(f.selected_slug != f.default for f in [ state_filters, ]) memberships = memberships.order_by('person__surname', 'person__official_first_names') if request.method == 'POST' and state_filters.selected_slug == 'approval': memberships.update(state='in_effect') messages.success(request, u'Hyväksyntää odottavat jäsenhakemukset hyväksyttiin.') return redirect('membership_admin_members_view', organization.slug) export_type = state_filters.selected_slug if export_type == 'approval': export_type_verbose = u'Hyväksyntää odottavat hakemukset' elif export_type == 'discharged': export_type_verbose = u'Erotetut jäsenet' elif export_type == 'declined': export_type_verbose = u'Hylätyt jäsenhakemukset' elif export_type == 'in_effect': export_type_verbose = u'Jäsenluettelo' elif not export_type: export_type = 'all' export_type_verbose = u'Jäsenluettelo' title = u'{organization.name} – {export_type_verbose}'.format( organization=organization, export_type_verbose=export_type_verbose, ) vars.update( show_approve_all_button=state_filters.selected_slug == 'approval', memberships=memberships, num_members=memberships.count(), num_all_members=num_all_members, state_filters=state_filters, filter_active=filter_active, css_to_show_filter_panel='in' if filter_active else '', export_formats=EXPORT_FORMATS, now=now(), title=title, ) if format == 'screen': return render(request, 'membership_admin_members_view.jade', vars) elif format == 'html': return render(request, 'membership_admin_export_html_view.jade', vars) elif format in CSV_EXPORT_FORMATS: filename = "{organization.slug}_members_{timestamp}.{format}".format( organization=organization, timestamp=now().strftime('%Y%m%d%H%M%S'), format=format, ) return csv_response(organization, Membership, memberships, dialect='xlsx', filename=filename, m2m_mode='separate_columns', )