Ejemplo n.º 1
0
    def done(self, form_list, form_dict, **kwargs):
        if self.request.user.is_authenticated:
            user = self.request.user
        else:
            uid = form_dict['user'].save()
            user = User.objects.get(pk=uid)

        form_dict['info'].instance.event = self.request.event
        form_dict['info'].save()
        form_dict['info'].instance.speakers.add(user)
        sub = form_dict['info'].instance
        form_dict['profile'].user = user
        form_dict['profile'].save()
        if 'questions' in form_dict:
            for k, value in form_dict['questions'].cleaned_data.items():
                qid = k.split('_')[1]
                question = self.request.event.questions.get(pk=qid)
                answer = Answer(question=question, submission=sub)

                if question.variant == QuestionVariant.MULTIPLE:
                    answstr = ", ".join([str(o) for o in value])
                    answer.save()
                    answer.answer = answstr
                    answer.options.add(*value)
                elif question.variant == QuestionVariant.CHOICES:
                    answer.save()
                    answer.options.add(value)
                    answer.answer = value.answer
                else:
                    answer.answer = value
                answer.save()

        try:
            sub.event.ack_template.to_mail(
                user=user,
                event=self.request.event,
                context=template_context_from_submission(sub),
                skip_queue=True,
                locale=user.locale)
            if self.request.event.settings.mail_on_new_submission:
                MailTemplate(
                    event=self.request.event,
                    subject=_('[{event}] New submission!').format(
                        event=self.request.event.slug),
                    text=self.request.event.settings.mail_text_new_submission,
                ).to_mail(user=user,
                          event=self.request.event,
                          context=template_context_from_submission(sub),
                          skip_queue=True,
                          locale=self.request.event.locale)
        except SendMailException as e:
            logging.getLogger('').warning(str(e))
            messages.warning(self.request, phrases.cfp.submission_email_fail)

        sub.log_action('pretalx.submission.create', person=user)
        messages.success(self.request, phrases.cfp.submission_success)
        login(self.request, user)
        return redirect(
            reverse('cfp:event.user.submissions',
                    kwargs={'event': self.request.event.slug}))
Ejemplo n.º 2
0
    def done(self, form_list, **kwargs):
        form_dict = kwargs.get('form_dict')
        if self.request.user.is_authenticated:
            user = self.request.user
        else:
            uid = form_dict['user'].save()
            user = User.objects.filter(pk=uid).first()
        if not user:
            raise ValidationError(
                _(
                    'There was an error with your user account. Please contact the organiser for further help.'
                )
            )

        form_dict['info'].instance.event = self.request.event
        form_dict['info'].save()
        form_dict['info'].instance.speakers.add(user)
        sub = form_dict['info'].instance
        form_dict['profile'].user = user
        form_dict['profile'].save()
        if 'questions' in form_dict:
            for k, value in form_dict['questions'].cleaned_data.items():
                qid = k.split('_')[1]
                self._handle_question_answer(sub, qid, value, user=user)

        try:
            sub.event.ack_template.to_mail(
                user=user,
                event=self.request.event,
                context=template_context_from_submission(sub),
                skip_queue=True,
                locale=user.locale,
            )
            if self.request.event.settings.mail_on_new_submission:
                MailTemplate(
                    event=self.request.event,
                    subject=_('New submission!').format(event=self.request.event.slug),
                    text=self.request.event.settings.mail_text_new_submission,
                ).to_mail(
                    user=self.request.event.email,
                    event=self.request.event,
                    context=template_context_from_submission(sub),
                    skip_queue=True,
                    locale=self.request.event.locale,
                )
        except SendMailException as exception:
            logging.getLogger('').warning(str(exception))
            messages.warning(self.request, phrases.cfp.submission_email_fail)

        sub.log_action('pretalx.submission.create', person=user)
        messages.success(self.request, phrases.cfp.submission_success)
        login(self.request, user, backend='django.contrib.auth.backends.ModelBackend')
        return redirect(
            reverse(
                'cfp:event.user.submissions', kwargs={'event': self.request.event.slug}
            )
        )
Ejemplo n.º 3
0
    def done(self, request):
        # We are done, or at least we finished the last step. Time to check results.
        valid_steps = []
        for step in request.event.cfp_flow.steps:
            if step.is_applicable(request):
                if not step.is_completed(request):
                    return redirect(step.get_step_url(request))
                valid_steps.append(step)

        # We are done, or at least the data checks out. Time to save results.
        request.event.cfp_flow.steps_dict["user"].done(request)
        for step in valid_steps:
            if not step.identifier == "user":
                step.done(request)

        try:
            request.event.ack_template.to_mail(
                user=request.user,
                event=request.event,
                context_kwargs={
                    "user": request.user,
                    "submission": request.submission
                },
                skip_queue=True,
                locale=request.submission.get_email_locale(
                    request.user.locale),
                full_submission_content=True,
            )
            if request.event.settings.mail_on_new_submission:
                MailTemplate(
                    event=request.event,
                    subject=str(_("New proposal: {title}")).format(
                        title=request.submission.title),
                    text=request.event.settings.mail_text_new_submission,
                ).to_mail(
                    user=request.event.email,
                    event=request.event,
                    context_kwargs={
                        "user": request.user,
                        "submission": request.submission,
                    },
                    context={
                        "orga_url": request.submission.orga_urls.base.full()
                    },
                    skip_queue=True,
                    locale=request.event.locale,
                )
        except SendMailException as exception:
            logging.getLogger("").warning(str(exception))
            messages.warning(request, phrases.cfp.submission_email_fail)

        return redirect(
            reverse("cfp:event.user.submissions",
                    kwargs={"event": request.event.slug}))
Ejemplo n.º 4
0
    def done(self, form_list, **kwargs):
        form_dict = kwargs.get('form_dict')
        if self.request.user.is_authenticated:
            user = self.request.user
        else:
            uid = form_dict['user'].save()
            user = User.objects.filter(pk=uid).first()
        if not user or not user.is_active:
            raise ValidationError(
                _('There was an error when logging in. Please contact the organiser for further help.'
                  ), )

        form_dict['info'].instance.event = self.request.event
        form_dict['info'].save()
        form_dict['info'].instance.speakers.add(user)
        sub = form_dict['info'].instance
        form_dict['profile'].user = user
        form_dict['profile'].save()
        if 'questions' in form_dict:
            form_dict['questions'].speaker = user
            form_dict['questions'].submission = form_dict['info'].instance
            form_dict['questions'].save()

        try:
            sub.event.ack_template.to_mail(
                user=user,
                event=self.request.event,
                context=template_context_from_submission(sub),
                skip_queue=True,
                locale=user.locale,
                submission=sub,
                full_submission_content=True,
            )
            if self.request.event.settings.mail_on_new_submission:
                MailTemplate(
                    event=self.request.event,
                    subject=_('New submission!').format(
                        event=self.request.event.slug),
                    text=self.request.event.settings.mail_text_new_submission,
                ).to_mail(
                    user=self.request.event.email,
                    event=self.request.event,
                    context=template_context_from_submission(sub),
                    skip_queue=True,
                    locale=self.request.event.locale,
                )
            additional_speaker = form_dict['info'].cleaned_data.get(
                'additional_speaker').strip()
            if additional_speaker:
                sub.send_invite(to=[additional_speaker], _from=user)
        except SendMailException as exception:
            logging.getLogger('').warning(str(exception))
            messages.warning(self.request, phrases.cfp.submission_email_fail)

        if self.access_code:
            sub.access_code = self.access_code
            sub.save()
            self.access_code.redeemed += 1
            self.access_code.save()

        sub.log_action('pretalx.submission.create', person=user)
        messages.success(self.request, phrases.cfp.submission_success)
        login(self.request,
              user,
              backend='django.contrib.auth.backends.ModelBackend')
        return redirect(
            reverse('cfp:event.user.submissions',
                    kwargs={'event': self.request.event.slug}))