Beispiel #1
0
def membership_admin_member_view(request, vars, organization, person_id):
    membership = get_object_or_404(Membership,
                                   organization=organization,
                                   person=int(person_id))
    read_only = membership.person.user is not None
    member_form = initialize_form(MemberForm,
                                  request,
                                  instance=membership.person,
                                  readonly=read_only,
                                  prefix='member')
    membership_form = initialize_form(MembershipForm,
                                      request,
                                      instance=membership,
                                      prefix='membership')

    forms = [membership_form] if read_only else [membership_form, member_form]

    if request.method == 'POST':
        action = request.POST['action']

        if action in ['save-edit', 'save-return']:
            if all(form.is_valid() for form in forms):
                for form in forms:
                    form.save()

                membership.apply_state()

                messages.success(request, 'Jäsenen tiedot tallennettiin.')

                if action == 'save-return':
                    return redirect('membership_admin_members_view',
                                    organization.slug)

            else:
                messages.error(request, 'Tarkista lomakkeen tiedot.')
        else:
            raise NotImplementedError(action)

    previous_membership, next_membership = membership.get_previous_and_next()

    tabs = [
        Tab('membership-admin-person-tab', 'Jäsenen tiedot', active=True),
        Tab('membership-admin-state-tab', 'Jäsenyyden tila'),
        # Tab('membership-admin-events-tab', 'Jäsenyyteen liittyvät tapahtumat'),
        # Tab('membership-admin-payments-tab', 'Jäsenmaksut'),
    ]

    vars.update(
        member=membership.person,
        member_form=member_form,
        membership=membership,
        membership_form=membership_form,
        next_membership=next_membership,
        previous_membership=previous_membership,
        read_only=read_only,
        tabs=tabs,
    )

    return render(request, 'membership_admin_member_view.jade', vars)
Beispiel #2
0
def get_schedule_tabs(request, event):
    schedule_url = url('programme:schedule_view', event.slug)
    schedule_active = request.path == schedule_url
    schedule_text = 'Ohjelmakartta'

    special_url = url('programme:special_view', event.slug)
    special_active = request.path == special_url
    special_text = 'Ohjelmakartan ulkopuolinen ohjelma'

    return [
        Tab(schedule_url, schedule_text, schedule_active, 0),
        Tab(special_url, special_text, special_active, 0),
    ]
Beispiel #3
0
def get_timetable_tabs(request, event):
    timetable_url = url('programme_timetable_view', event.slug)
    timetable_active = request.path == timetable_url
    timetable_text = 'Ohjelmakartta'

    special_url = url('programme_special_view', event.slug)
    special_active = request.path == special_url
    special_text = 'Ohjelmakartan ulkopuolinen ohjelma'

    return [
        Tab(timetable_url, timetable_text, timetable_active, 0),
        Tab(special_url, special_text, special_active, 0),
    ]
Beispiel #4
0
def labour_admin_signup_view(request, vars, event, person_id):
    person = get_object_or_404(Person, pk=int(person_id))
    signup = get_object_or_404(Signup, person=person, event=event)

    old_state_flags = signup._state_flags

    signup_form, signup_extra_form, signup_admin_form = initialize_signup_forms(
        request, event, signup, admin=True)
    person_form = initialize_form(
        AdminPersonForm,
        request,
        instance=signup.person,
        prefix='person',
        readonly=True,
        event=event,
    )

    if request.method == 'POST':
        # XXX Need to update state before validation to catch accepting people without accepted job categories
        for state_name in signup.next_states:
            command_name = 'set-state-{state_name}'.format(
                state_name=state_name)
            if command_name in request.POST:
                old_state_flags = signup._state_flags
                signup.state = state_name
                break

        if signup_form.is_valid() and signup_extra_form.is_valid(
        ) and signup_admin_form.is_valid():
            signup_form.save()
            signup_extra_form.save()
            signup_admin_form.save()

            signup.apply_state()
            messages.success(request, 'Tiedot tallennettiin.')

            if 'save-return' in request.POST:
                return redirect('labour_admin_signups_view', event.slug)
            else:
                return redirect('labour_admin_signup_view', event.slug,
                                person.pk)
        else:
            # XXX Restore state just for shows, suboptimal but
            signup._state_flags = old_state_flags

            messages.error(request, 'Ole hyvä ja tarkista lomake.')

    non_qualified_category_names = [
        jc.name for jc in JobCategory.objects.filter(event=event)
        if not jc.is_person_qualified(signup.person)
    ]

    non_applied_categories = list(JobCategory.objects.filter(event=event))
    for applied_category in signup.job_categories.all():
        non_applied_categories.remove(applied_category)
    non_applied_category_names = [cat.name for cat in non_applied_categories]

    previous_signup, next_signup = signup.get_previous_and_next_signup()

    historic_signups = Signup.objects.filter(person=signup.person).exclude(
        event=event).order_by('-event__start_time')
    if not person.allow_work_history_sharing:
        # The user has elected to not share their full work history between organizations.
        # Only show work history for the current organization.
        historic_signups = historic_signups.filter(
            event__organization=event.organization)

    tabs = [
        Tab('labour-admin-signup-state-tab', 'Hakemuksen tila', active=True),
        Tab('labour-admin-signup-person-tab', 'Hakijan tiedot'),
        Tab('labour-admin-signup-application-tab', 'Hakemuksen tiedot'),
        Tab('labour-admin-signup-messages-tab',
            'Työvoimaviestit',
            notifications=signup.person_messages.count()),
        Tab('labour-admin-signup-shifts-tab', 'Työvuorot'),
        Tab('labour-admin-signup-history-tab',
            'Työskentelyhistoria',
            notifications=historic_signups.count()),
    ]

    vars.update(
        historic_signups=historic_signups,
        next_signup=next_signup,
        person_form=person_form,
        previous_signup=previous_signup,
        signup=signup,
        signup_admin_form=signup_admin_form,
        signup_extra_form=signup_extra_form,
        signup_form=signup_form,
        tabs=tabs,
        total_hours=signup.shifts.all().aggregate(Sum('hours'))['hours__sum'],

        # XXX hack: widget customization is very difficult, so apply styles via JS
        non_applied_category_names_json=json.dumps(non_applied_category_names),
        non_qualified_category_names_json=json.dumps(
            non_qualified_category_names),
    )

    person.log_view(request, event=event)

    return render(request, 'labour_admin_signup_view.jade', vars)
Beispiel #5
0
def programme_admin_detail_view(request, vars, event, programme_id):
    programme = get_object_or_404(ProgrammeManagementProxy, category__event=event, pk=int(programme_id))

    if programme.form_used:
        FormClass = programme.form_used.programme_form_class
    else:
        FormClass = ProgrammeSelfServiceForm

    programme_form = initialize_form(FormClass, request, instance=programme, event=event, prefix='programme')
    internal_form = initialize_form(ProgrammeInternalForm, request, instance=programme, event=event, prefix='internal')
    schedule_form = initialize_form(ScheduleForm, request, instance=programme, event=event, prefix='schedule')
    forms = [programme_form, schedule_form, internal_form]

    invitation_form = initialize_form(InvitationForm, request, event=event, prefix='invitation')
    freeform_organizer_form = initialize_form(FreeformOrganizerForm, request, prefix='freeform')

    SignupExtra = event.programme_event_meta.signup_extra_model
    if SignupExtra.supports_programme:
        SignupExtraForm = SignupExtra.get_programme_form_class()
    else:
        SignupExtraForm = None

    programme_roles = ProgrammeRole.objects.filter(programme=programme)
    forms_per_host = []
    for role in programme_roles:
        change_host_role_form = initialize_form(ChangeHostRoleForm, request, prefix='chr', instance=role, event=event)
        if SignupExtraForm is not None:
            signup_extra_form = initialize_form(SignupExtraForm, request,
                prefix='sex',
                instance=SignupExtra.for_event_and_person(event, role.person)
            )
        else:
            signup_extra_form = None

        forms_per_host.append(PerHostForms(
            change_host_role_form=change_host_role_form,
            signup_extra_form=signup_extra_form,
        ))

    change_invitation_role_forms = [
        initialize_form(ChangeInvitationRoleForm, request, prefix='cir', instance=invitation, event=event)
        for invitation in programme.invitation_set.all()
    ]

    if request.method == 'POST':
        action = request.POST.get('action')

        if action in ('save-edit', 'save-return'):
            if all(form.is_valid() for form in forms):
                for form in forms:
                    form.save()

                programme.apply_state()

                messages.success(request, _('The changes were saved.'))

                if action == 'save-edit':
                    return redirect('programme_admin_detail_view', event.slug, programme_id)
                elif action == 'save-return':
                    return redirect('programme_admin_view', event.slug)
                else:
                    raise NotImplementedError(action)
            else:
                messages.error(request, _('Please check the form.'))

        elif action == 'invite-host':
            if invitation_form.is_valid():
                invitation = invitation_form.save(commit=False)
                invitation.programme = programme
                invitation.created_by = request.user
                invitation.save()

                invitation.send(request)

                messages.success(request, _('The host was successfully invited.'))

                return redirect('programme_admin_detail_view', event.slug, programme_id)
            else:
                messages.error(request, _('Please check the form.'))

        elif action == 'add-freeform-host':
            if freeform_organizer_form.is_valid():
                freeform_organizer_form = freeform_organizer_form.save(commit=False)
                freeform_organizer_form.programme = programme
                freeform_organizer_form.save()

                messages.success(request, _('The freeform organizer was successfully added.'))

                return redirect('programme_admin_detail_view', event.slug, programme_id)
            else:
                messages.error(request, _('Please check the form.'))

        elif (
            action.startswith('remove-host:') or
            action.startswith('remove-freeform-host:') or
            action.startswith('cancel-invitation:')
        ):
            action, id_str = action.split(':', 1)

            try:
                id_int = int(id_str)
            except ValueError:
                messages.error(request, _('Invalid action.'))
            else:
                if action == 'remove-host':
                    programme_role = get_object_or_404(ProgrammeRole, id=id_int, programme=programme)
                    programme_role.delete()

                    programme.apply_state(deleted_programme_roles=[programme_role])

                    messages.success(request, _('The host was removed.'))
                elif action == 'cancel-invitation':
                    invitation = get_object_or_404(Invitation, id=id_int, programme=programme, state='valid')
                    invitation.state = 'revoked'
                    invitation.save()

                    programme.apply_state()

                    messages.success(request, _('The invitation was cancelled.'))
                elif action == 'remove-freeform-host':
                    freeform_organizer = get_object_or_404(FreeformOrganizer, id=id_int, programme=programme)
                    freeform_organizer.delete()

                    programme.apply_state()

                    messages.success(request, _('The host was removed.'))
                else:
                    raise NotImplementedError(action)

                return redirect('programme_admin_detail_view', event.slug, programme_id)
        else:
            messages.error(request, _('Invalid action.'))

    invitations = programme.invitation_set.filter(state='valid')
    feedback = programme.visible_feedback

    tabs = [
        Tab('programme-admin-programme-tab', _('Programme form'), active=True),
        Tab('programme-admin-programme-schedule-tab', _('Schedule information')),
        Tab('programme-admin-programme-internal-tab', _('Internal information')),
        Tab('programme-admin-programme-hosts-tab', _('Programme hosts'), notifications=invitations.count()),
        Tab('programme-admin-programme-feedback-tab', _('Feedback'), notifications=feedback.count()),
    ]

    previous_programme, next_programme = programme.get_previous_and_next_programme()

    vars.update(
        feedback=feedback,
        forms_per_host=forms_per_host,
        change_invitation_role_forms=change_invitation_role_forms,
        freeform_organizer_form=freeform_organizer_form,
        freeform_organizers=FreeformOrganizer.objects.filter(programme=programme),
        internal_form=internal_form,
        invitation_form=invitation_form,
        invitations=invitations,
        next_programme=next_programme,
        overlapping_programmes=programme.get_overlapping_programmes(),
        previous_programme=previous_programme,
        programme=programme,
        programme_roles=programme_roles,
        programme_form=programme_form,
        schedule_form=schedule_form,
        tabs=tabs,
    )

    return render(request, 'programme_admin_detail_view.jade', vars)