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 enrollment_admin_view(request, vars, event): enrollments = (Enrollment.objects.filter( event=event).select_related('person').order_by('person__surname', 'person__first_name')) state_filters = Filter(request, 'state').add_choices('state', STATE_CHOICES) enrollments = state_filters.filter_queryset(enrollments) vars.update( enrollments=enrollments, num_enrolled=enrollments.count(), num_total_enrolled=enrollments.count(), state_filters=state_filters, ) return render(request, 'enrollment_admin_view.pug', vars)
def enrollment_admin_view(request, vars, event): enrollments = ( Enrollment.objects.filter(event=event) .select_related('person') .order_by('person__surname', 'person__first_name') ) state_filters = Filter(request, 'state').add_choices('state', STATE_CHOICES) enrollments = state_filters.filter_queryset(enrollments) vars.update( enrollments=enrollments, num_enrolled=enrollments.count(), num_total_enrolled=enrollments.count(), state_filters=state_filters, ) return render(request, 'enrollment_admin_view.pug', vars)
def actual_special_view( request, event, include_unpublished=False, template='programme_special_view.jade', vars=None, show_programme_actions=False, ): criteria = dict(include_unpublished=include_unpublished) category_slug = request.GET.get('category') if category_slug: criteria.update(category__slug=category_slug) programmes = event.programme_event_meta.get_special_programmes( **criteria).order_by('start_time') categories_criteria = dict(event=event) if not include_unpublished: categories_criteria.update(public=True) categories = Category.objects.filter(**categories_criteria) category_filters = Filter(request, 'category').add_objects('category__slug', categories) programmes = category_filters.filter_queryset(programmes) programmes_by_start_time = group_programmes_by_start_time(programmes) if vars is None: vars = dict() vars.update( category_filters=category_filters, event=event, programmes_by_start_time=programmes_by_start_time, show_programme_actions=show_programme_actions, tabs=get_timetable_tabs(request, event), ) return render(request, template, vars)
def actual_special_view( request, event, include_unpublished=False, template='programme_special_view.jade', vars=None, show_programme_actions=False, ): criteria = dict(include_unpublished=include_unpublished) category_slug = request.GET.get('category') if category_slug: criteria.update(category__slug=category_slug) programmes = event.programme_event_meta.get_special_programmes(**criteria).order_by('start_time') categories_criteria = dict(event=event) if not include_unpublished: categories_criteria.update(public=True) categories = Category.objects.filter(**categories_criteria) category_filters = Filter(request, 'category').add_objects('category__slug', categories) programmes = category_filters.filter_queryset(programmes) programmes_by_start_time = group_programmes_by_start_time(programmes) if vars is None: vars = dict() vars.update( category_filters=category_filters, event=event, programmes_by_start_time=programmes_by_start_time, show_programme_actions=show_programme_actions, tabs=get_timetable_tabs(request, event), ) return render(request, template, vars)
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 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 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', )
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 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 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)