Пример #1
0
def actual_labour_signup_view(request, event, alternative_form_slug):
    vars = page_wizard_vars(request)

    signup = event.labour_event_meta.get_signup_for_person(request.user.person)

    if alternative_form_slug is not None:
        # Alternative signup form specified via URL

        alternative_signup_form = get_object_or_404(AlternativeSignupForm, event=event, slug=alternative_form_slug)

        if (
            signup.alternative_signup_form_used is not None and \
            signup.alternative_signup_form_used.pk != alternative_signup_form.pk
        ):
            messages.error(request, u'Hakemusta ei ole tehty käyttäen tätä lomaketta.')
            return redirect('core_event_view', event.slug)
    elif signup.pk is not None and signup.alternative_signup_form_used is not None:
        # Alternative signup form used to sign up
        alternative_signup_form = signup.alternative_signup_form_used
    else:
        # Use default signup form
        alternative_signup_form = None

    if alternative_signup_form is not None:
        # Using an alternative signup form

        if not alternative_signup_form.is_active:
            messages.error(request, u'Pyytämäsi ilmoittautumislomake ei ole käytössä.')
            return redirect('core_event_view', event.slug)

        if alternative_signup_form.signup_message:
            messages.warning(request, alternative_signup_form.signup_message)

        SignupFormClass = alternative_signup_form.signup_form_class
        SignupExtraFormClass = alternative_signup_form.signup_extra_form_class
    else:
        # Using default signup form

        if not event.labour_event_meta.is_registration_open:
            messages.error(request, u'Ilmoittautuminen tähän tapahtumaan ei ole avoinna.')
            return redirect('core_event_view', event.slug)

        if event.labour_event_meta.signup_message:
            messages.warning(request, event.labour_event_meta.signup_message)

        SignupFormClass = None
        SignupExtraFormClass = None

    if signup.is_processed:
        messages.error(request,
            u'Hakemuksesi on jo käsitelty, joten et voi enää muokata sitä. '
            u'Tarvittaessa ota yhteyttä työvoimatiimiin.'
        )
        return redirect('core_event_view', event.slug)

    if signup.pk is not None:
        old_state = signup.state
        submit_text = 'Tallenna muutokset'
    else:
        old_state = None
        submit_text = 'Lähetä ilmoittautuminen'

    signup_extra = signup.signup_extra
    signup_form, signup_extra_form = initialize_signup_forms(request, event, signup,
        SignupFormClass=SignupFormClass,
        SignupExtraFormClass=SignupExtraFormClass,
    )

    if request.method == 'POST':
        if signup_form.is_valid() and signup_extra_form.is_valid():
            if signup.pk is None:
                message = u'Kiitos ilmoittautumisestasi!'
            else:
                message = u'Ilmoittautumisesi on päivitetty.'

            if alternative_signup_form is not None:
                signup.alternative_signup_form_used = alternative_signup_form

                set_attrs(signup, **signup_form.get_excluded_field_defaults())
                set_attrs(signup_extra, **signup_extra_form.get_excluded_field_defaults())

            signup = signup_form.save()

            signup_extra.signup = signup
            signup_extra = signup_extra_form.save()

            if alternative_signup_form is not None:
                # Save m2m field defaults
                for obj, form in [
                    (signup, signup_form),
                    (signup_extra, signup_extra_form),
                ]:
                    defaults = form.get_excluded_m2m_field_defaults()
                    if defaults:
                        set_attrs(obj, **defaults)
                        obj.save()

            signup.apply_state()

            messages.success(request, message)
            return redirect('core_event_view', event.slug)
        else:
            messages.error(request, u'Ole hyvä ja korjaa virheelliset kentät.')

    all_job_cats = JobCategory.objects.filter(event=event)
    job_cats = JobCategory.objects.filter(event=event, public=True)

    # FIXME use id and data attr instead of category name
    non_qualified_category_names = [
        jc.name for jc in job_cats
        if not jc.is_person_qualified(request.user.person)
    ]

    vars.update(
        event=event,
        signup_form=signup_form,
        signup_extra_form=signup_extra_form,
        submit_text=submit_text,
        alternative_signup_form=alternative_signup_form,

        # XXX HACK descriptions injected using javascript
        job_descriptions_json=json.dumps(dict((cat.pk, cat.description) for cat in all_job_cats)),
        non_qualified_category_names_json=json.dumps(non_qualified_category_names),
    )

    return render(request, 'labour_signup_view.jade', vars)
Пример #2
0
def actual_labour_signup_view(request, event, alternative_form_slug):
    vars = page_wizard_vars(request)

    signup = event.labour_event_meta.get_signup_for_person(request.user.person)

    if alternative_form_slug is not None:
        # Alternative signup form specified via URL

        alternative_signup_form = get_object_or_404(AlternativeSignupForm, event=event, slug=alternative_form_slug)

        if (
            signup.alternative_signup_form_used is not None and \
            signup.alternative_signup_form_used.pk != alternative_signup_form.pk
        ):
            messages.error(request, _('Your application has not been submitted using this form.'))
            return redirect('core_event_view', event.slug)
    elif signup.pk is not None and signup.alternative_signup_form_used is not None:
        # Alternative signup form used to sign up
        alternative_signup_form = signup.alternative_signup_form_used
    else:
        # Use default signup form
        alternative_signup_form = None

    if alternative_signup_form is not None:
        # Using an alternative signup form

        if not alternative_signup_form.is_active:
            messages.error(request, _('The signup form you have requested is not currently active.'))
            return redirect('core_event_view', event.slug)

        if alternative_signup_form.signup_message:
            messages.warning(request, alternative_signup_form.signup_message)

        SignupFormClass = alternative_signup_form.signup_form_class
        SignupExtraFormClass = alternative_signup_form.signup_extra_form_class
    else:
        # Using default signup form

        if not event.labour_event_meta.is_registration_open:
            messages.error(request, _('This event is not currently accepting applications.'))
            return redirect('core_event_view', event.slug)

        if event.labour_event_meta.signup_message:
            messages.warning(request, event.labour_event_meta.signup_message)

        SignupFormClass = None
        SignupExtraFormClass = None

    if signup.is_processed:
        messages.error(request, _(
            'Your application has already been processed, so you can no longer edit it. '
            'Please contact the volunteer coordinator for any further changes.'
        ))
        return redirect('core_event_view', event.slug)

    if signup.pk is not None:
        old_state = signup.state
        submit_text = _('Update application')
    else:
        old_state = None
        submit_text = _('Submit application')

    signup_extra = signup.signup_extra
    signup_form, signup_extra_form = initialize_signup_forms(request, event, signup,
        SignupFormClass=SignupFormClass,
        SignupExtraFormClass=SignupExtraFormClass,
    )

    if request.method == 'POST':
        if signup_form.is_valid() and signup_extra_form.is_valid():
            if signup.pk is None:
                message = _('Thank you for your application!')
            else:
                message = _('Your application has been updated.')

            if alternative_signup_form is not None:
                signup.alternative_signup_form_used = alternative_signup_form

                set_attrs(signup, **signup_form.get_excluded_field_defaults())
                set_attrs(signup_extra, **signup_extra_form.get_excluded_field_defaults())

            with transaction.atomic():
                signup = signup_form.save()

                signup_extra.signup = signup
                signup_extra = signup_extra_form.save()

                if alternative_signup_form is not None:
                    # Save m2m field defaults
                    for obj, form in [
                        (signup, signup_form),
                        (signup_extra, signup_extra_form),
                    ]:
                        defaults = form.get_excluded_m2m_field_defaults()
                        if defaults:
                            set_attrs(obj, **defaults)
                            obj.save()

            signup.apply_state()

            messages.success(request, message)
            return redirect('core_event_view', event.slug)
        else:
            messages.error(request, _('Please check the form.'))

    available_job_categories = signup_form.get_job_categories(event=event)
    all_job_categories = JobCategory.objects.filter(event=event)

    # FIXME use id and data attr instead of category name
    non_qualified_category_names = [
        jc.name for jc in available_job_categories
        if not jc.is_person_qualified(request.user.person)
    ]

    vars.update(
        alternative_signup_form=alternative_signup_form,
        event=event,
        signup_extra_form=signup_extra_form,
        signup_form=signup_form,
        signup=signup,
        submit_text=submit_text,

        # XXX HACK descriptions injected using javascript
        job_descriptions_json=json.dumps(dict((cat.pk, cat.description) for cat in all_job_categories)),
        non_qualified_category_names_json=json.dumps(non_qualified_category_names),
    )

    return render(request, 'labour_signup_view.jade', vars)
Пример #3
0
def programme_offer_form_view(request, event, form_slug):
    meta = event.programme_event_meta
    alternative_programme_forms = AlternativeProgrammeForm.objects.filter(
        event=event)

    if not alternative_programme_forms.exists() and form_slug == 'default':
        # implicit default form
        alternative_programme_form = None
        FormClass = ProgrammeOfferForm
        num_extra_invites = DEFAULT_NUM_EXTRA_INVITES

        if not meta.is_accepting_cold_offers:
            messages.error(
                request,
                _('This event is not currently accepting offers via this site. Please contact '
                  'the programme managers directly.'))
            return redirect('core_event_view', event.slug)
    else:
        alternative_programme_form = get_object_or_404(
            alternative_programme_forms, slug=form_slug)
        num_extra_invites = alternative_programme_form.num_extra_invites
        FormClass = alternative_programme_form.programme_form_class

        if not alternative_programme_form.is_active:
            messages.error(
                request,
                _('The form you specified is not currently open for cold offers. Please contact '
                  'the programme managers directly.'))
            return redirect('core_event_view', event.slug)

    form = initialize_form(
        FormClass,
        request,
        event=event,
        prefix='needs',
    )

    sired_invitation_formset = get_sired_invitation_formset(
        request, num_extra_invites=num_extra_invites)

    forms = [form, sired_invitation_formset]

    SignupExtra = event.programme_event_meta.signup_extra_model
    if SignupExtra.supports_programme:
        SignupExtraForm = SignupExtra.get_programme_form_class()
        signup_extra = SignupExtra.for_event_and_person(
            event, request.user.person)
        signup_extra_form = initialize_form(
            SignupExtraForm,
            request,
            instance=signup_extra,
            prefix='extra',
        )
        forms.append(signup_extra_form)
    else:
        signup_extra = None
        signup_extra_form = None

    if request.method == 'POST':
        if all(the_form.is_valid() for the_form in forms):
            with transaction.atomic():
                programme = form.save(commit=False)
                programme.state = 'offered'
                programme.form = alternative_programme_form

                if alternative_programme_form:
                    set_attrs(programme, **form.get_excluded_field_defaults())
                    programme.form_used = alternative_programme_form

                programme.save()
                form.save_m2m()

                if alternative_programme_form:
                    set_attrs(programme,
                              **form.get_excluded_m2m_field_defaults())
                    programme.save()

                programme_role = ProgrammeRole(
                    person=request.user.person,
                    programme=programme,
                    role=meta.default_role,
                )
                programme_role.save()

                if signup_extra_form:
                    signup_extra = signup_extra_form.process(signup_extra)

                for extra_invite in sired_invitation_formset.save(
                        commit=False):
                    extra_invite.programme = programme
                    extra_invite.created_by = request.user
                    extra_invite.role = programme_role.role
                    extra_invite.sire = programme_role
                    extra_invite.save()
                    extra_invite.send(request)

            programme.apply_state()

            messages.success(
                request,
                _('Thank you for offering your programme. The programme managers will be in touch.'
                  ))

            return redirect('programme_profile_detail_view', programme.pk)
        else:
            messages.error(request, _('Please check the form.'))

    vars = dict(
        alternative_programme_form=alternative_programme_form,
        event=event,
        form=form,
        freeform_organizers=FreeformOrganizer.objects.none(),
        invitations=Invitation.objects.none(),
        num_extra_invites=num_extra_invites,
        programme_roles=ProgrammeRole.objects.none(),
        signup_extra_form=signup_extra_form,
        sired_invitation_formset=sired_invitation_formset,
    )

    return render(request, 'programme_offer_form_view.jade', vars)
Пример #4
0
def actual_labour_signup_view(request, event, alternative_form_slug):
    vars = page_wizard_vars(request)

    signup = event.labour_event_meta.get_signup_for_person(request.user.person)

    if alternative_form_slug is not None:
        # Alternative signup form specified via URL

        alternative_signup_form = get_object_or_404(AlternativeSignupForm, event=event, slug=alternative_form_slug)

        if (
            signup.alternative_signup_form_used is not None and \
            signup.alternative_signup_form_used.pk != alternative_signup_form.pk
        ):
            messages.error(request, _('Your application has not been submitted using this form.'))
            return redirect('core_event_view', event.slug)
    elif signup.pk is not None and signup.alternative_signup_form_used is not None:
        # Alternative signup form used to sign up
        alternative_signup_form = signup.alternative_signup_form_used
    else:
        # Use default signup form
        alternative_signup_form = None

    if alternative_signup_form is not None:
        # Using an alternative signup form

        if not alternative_signup_form.is_active:
            messages.error(request, _('The signup form you have requested is not currently active.'))
            return redirect('core_event_view', event.slug)

        if alternative_signup_form.signup_message:
            messages.warning(request, alternative_signup_form.signup_message)

        SignupFormClass = alternative_signup_form.signup_form_class
        SignupExtraFormClass = alternative_signup_form.signup_extra_form_class
    else:
        # Using default signup form

        if not event.labour_event_meta.is_registration_open:
            messages.error(request, _('This event is not currently accepting applications.'))
            return redirect('core_event_view', event.slug)

        if event.labour_event_meta.signup_message:
            messages.warning(request, event.labour_event_meta.signup_message)

        SignupFormClass = None
        SignupExtraFormClass = None

    if signup.is_processed:
        messages.error(request, _(
            'Your application has already been processed, so you can no longer edit it. '
            'Please contact the volunteer coordinator for any further changes.'
        ))
        return redirect('core_event_view', event.slug)

    if signup.pk is not None:
        old_state = signup.state
        submit_text = _('Update application')
    else:
        old_state = None
        submit_text = _('Submit application')

    signup_extra = signup.signup_extra
    signup_form, signup_extra_form = initialize_signup_forms(request, event, signup,
        SignupFormClass=SignupFormClass,
        SignupExtraFormClass=SignupExtraFormClass,
    )

    if request.method == 'POST':
        if signup_form.is_valid() and signup_extra_form.is_valid():
            if signup.pk is None:
                message = _('Thank you for your application!')
                event_type = 'labour.signup.created'
            else:
                message = _('Your application has been updated.')
                event_type = 'labour.signup.updated'

            if alternative_signup_form is not None:
                signup.alternative_signup_form_used = alternative_signup_form

                set_attrs(signup, **signup_form.get_excluded_field_defaults())
                set_attrs(signup_extra, **signup_extra_form.get_excluded_field_defaults())

            with transaction.atomic():
                signup = signup_form.save()

                signup_extra.signup = signup
                signup_extra = signup_extra_form.save()

                if alternative_signup_form is not None:
                    # Save m2m field defaults
                    for obj, form in [
                        (signup, signup_form),
                        (signup_extra, signup_extra_form),
                    ]:
                        defaults = form.get_excluded_m2m_field_defaults() or {}
                        for key, values in defaults.items():
                            getattr(obj, key).set(values)

            emit(event_type, request=request, person=request.user.person, event=event)

            signup.apply_state()

            messages.success(request, message)
            return redirect('core_event_view', event.slug)
        else:
            messages.error(request, _('Please check the form.'))

    available_job_categories = signup_form.get_job_categories(event=event)
    all_job_categories = JobCategory.objects.filter(event=event)

    # FIXME use id and data attr instead of category name
    non_qualified_category_names = [
        jc.name for jc in available_job_categories
        if not jc.is_person_qualified(request.user.person)
    ]

    vars.update(
        alternative_signup_form=alternative_signup_form,
        event=event,
        signup_extra_form=signup_extra_form,
        signup_form=signup_form,
        signup=signup,
        submit_text=submit_text,

        # XXX HACK descriptions injected using javascript
        job_descriptions_json=json.dumps(dict((cat.pk, cat.description) for cat in all_job_categories)),
        non_qualified_category_names_json=json.dumps(non_qualified_category_names),
    )

    return render(request, 'labour_signup_view.pug', vars)
Пример #5
0
def programme_offer_form_view(request, event, form_slug):
    meta = event.programme_event_meta
    alternative_programme_forms = AlternativeProgrammeForm.objects.filter(event=event)

    if not alternative_programme_forms.exists() and form_slug == 'default':
        # implicit default form
        alternative_programme_form = None
        role = meta.default_role
        FormClass = ProgrammeOfferForm
        num_extra_invites = DEFAULT_NUM_EXTRA_INVITES

        if not meta.is_accepting_cold_offers:
            messages.error(request, _(
                'This event is not currently accepting offers via this site. Please contact '
                'the programme managers directly.'
            ))
            return redirect('core_event_view', event.slug)
    else:
        alternative_programme_form = get_object_or_404(alternative_programme_forms, slug=form_slug)
        role = alternative_programme_form.role or meta.default_role
        num_extra_invites = alternative_programme_form.num_extra_invites
        FormClass = alternative_programme_form.programme_form_class

        if not alternative_programme_form.is_active:
            messages.error(request, _(
                'The form you specified is not currently open for cold offers. Please contact '
                'the programme managers directly.'
            ))
            return redirect('core_event_view', event.slug)

    form = initialize_form(FormClass, request,
        event=event,
        prefix='needs',
    )

    sired_invitation_formset = get_sired_invitation_formset(request, num_extra_invites=num_extra_invites)

    forms = [form, sired_invitation_formset]

    SignupExtra = event.programme_event_meta.signup_extra_model
    if SignupExtra.supports_programme:
        SignupExtraForm = SignupExtra.get_programme_form_class()
        signup_extra = SignupExtra.for_event_and_person(event, request.user.person)
        signup_extra_form = initialize_form(SignupExtraForm, request,
            instance=signup_extra,
            prefix='extra',
        )
        forms.append(signup_extra_form)
    else:
        signup_extra = None
        signup_extra_form = None

    if request.method == 'POST':
        if all(the_form.is_valid() for the_form in forms):
            with transaction.atomic():
                programme = form.save(commit=False)
                programme.state = 'offered'
                programme.form = alternative_programme_form

                if alternative_programme_form:
                    set_attrs(programme, **form.get_excluded_field_defaults())
                    programme.form_used = alternative_programme_form

                programme.save()
                form.save_m2m()

                if alternative_programme_form:
                    set_attrs(programme, **form.get_excluded_m2m_field_defaults())
                    programme.save()

                programme_role = ProgrammeRole(
                    person=request.user.person,
                    programme=programme,
                    role=role,
                )
                programme_role.save()

                if signup_extra_form:
                    signup_extra = signup_extra_form.process(signup_extra)

                for extra_invite in sired_invitation_formset.save(commit=False):
                    extra_invite.programme = programme
                    extra_invite.created_by = request.user
                    extra_invite.role = programme_role.role
                    extra_invite.sire = programme_role
                    extra_invite.save()
                    extra_invite.send(request)

            programme.apply_state()

            messages.success(request, _(
                'Thank you for offering your programme. The programme managers will be in touch.'
            ))

            return redirect('programme_profile_detail_view', programme.pk)
        else:
            messages.error(request, _('Please check the form.'))

    vars = dict(
        alternative_programme_form=alternative_programme_form,
        event=event,
        form=form,
        freeform_organizers=FreeformOrganizer.objects.none(),
        invitations=Invitation.objects.none(),
        num_extra_invites=num_extra_invites,
        programme_roles=ProgrammeRole.objects.none(),
        signup_extra_form=signup_extra_form,
        sired_invitation_formset=sired_invitation_formset,
    )

    return render(request, 'programme_offer_form_view.pug', vars)