示例#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}))
示例#2
0
    def _handle_question_answer(self, sub, qid, value):
        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()
            if value:
                answer.answer = answstr
                answer.options.add(*value)
        elif question.variant == QuestionVariant.CHOICES:
            answer.save()
            if value:
                answer.options.add(value)
                answer.answer = value.answer
        else:
            answer.answer = value
        answer.save()
示例#3
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()
        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 'questions' in form_dict:
            for k, value in form_dict['questions'].cleaned_data.items():
                qid = k.split('_')[1]
                question = Question.objects.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()

        sub.log_action('pretalx.submission.create', person=user)
        messages.success(self.request, 'Your talk has been submitted successfully!')
        login(self.request, user)
        return redirect(reverse('cfp:event.user.submissions', kwargs={
            'event': self.request.event.slug
        }))
示例#4
0
    def _handle_question_answer(self, sub, qid, value, user=None):
        question = self.request.event.questions.filter(pk=qid).first()
        if not question:
            return
        if question.target == QuestionTarget.SUBMISSION:
            answer = Answer(question=question, submission=sub)
        elif question.target == QuestionTarget.SPEAKER:
            answer = Answer(question=question, person=user)

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