Пример #1
0
    def post(self, request):
        form = ContactForm(request.POST)

        if form.is_valid():
            form.save()

            return redirect(reverse('form') + "?ok")
Пример #2
0
    def post(self, request, *args, **kwargs):
        context = self.get_context_data()

        if CONTACT_FORM_PREFIX in request.POST:
            contact_form = ContactForm(request.POST,
                                       prefix=CONTACT_FORM_PREFIX)
            context.update({'contact_form': contact_form})

            if contact_form.is_valid() and self.activity:
                contact = contact_form.save(self.activity)

                if contact:
                    messages.success(
                        request, _('Your message has been sent. Thank you.'))
                    context.update({
                        'contact_form':
                        ContactForm(prefix=CONTACT_FORM_PREFIX)
                    })

                    return super(HackathonView,
                                 self).render_to_response(context)

            messages.error(request,
                           _('Your message could not be sent. Try again.'))

        if SPEAKER_APPLICATION_FORM_PREFIX in request.POST:
            speaker_application_form = SpeakerApplicationForm(
                request.POST,
                request.FILES,
                prefix=SPEAKER_APPLICATION_FORM_PREFIX)
            context.update(
                {'speaker_application_form': speaker_application_form})

            if speaker_application_form.is_valid() and self.activity:
                speaker_application, created = speaker_application_form.save(
                    self.activity)

                if speaker_application:
                    if created:
                        messages.success(
                            request,
                            _('Your application has been sent. Thank you.'))

                        context.update({
                            'speaker_application_form':
                            SpeakerApplicationForm(
                                prefix=SPEAKER_APPLICATION_FORM_PREFIX)
                        })
                    else:
                        messages.error(request,
                                       _('Your application already exists!'))

                    return super(HackathonView,
                                 self).render_to_response(context)

            messages.error(request,
                           _('Your application could not be sent. Try again.'))

        return super(HackathonView, self).render_to_response(context)