def save_questions(self, k, v): """Receives a key and value from cleaned_data.""" from pretalx.submission.models import Answer, QuestionTarget field = self.fields[k] if field.answer: # We already have a cached answer object, so we don't # have to create a new one if v == "" or v is None: field.answer.delete() else: self._save_to_answer(field, field.answer, v) field.answer.save() elif v != "" and v is not None: answer = Answer( review=self.review if field.question.target == QuestionTarget.REVIEWER else None, submission=self.submission if field.question.target == QuestionTarget.SUBMISSION else None, person=self.speaker if field.question.target == QuestionTarget.SPEAKER else None, question=field.question, ) self._save_to_answer(field, answer, v) answer.save()
def questions_save(self): for k, v in self.qform.cleaned_data.items(): field = self.qform.fields[k] if field.answer: # We already have a cached answer object, so we don't # have to create a new one if v == '': # TODO: Deleting the answer removes the option to have a log here. # Maybe setting the answer to '' is the right way to go. field.answer.delete() else: self._save_to_answer(field, field.answer, v) field.answer.save() elif v != '': answer = Answer( submission=self.object, question=field.question, ) self._save_to_answer(field, answer, v) answer.save()
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}))
def save(self): for k, v in self.cleaned_data.items(): field = self.fields[k] if field.answer: # We already have a cached answer object, so we don't # have to create a new one if v == '' or v is None: field.answer.delete() else: self._save_to_answer(field, field.answer, v) field.answer.save() elif v != '': # Not distinguishing between the external question types helps to make # experiences smoother if orga changes a question type. answer = Answer( review=self.review, submission=self.submission, person=self.speaker, question=field.question, ) self._save_to_answer(field, answer, v) answer.save()
def save(self): for k, v in self.cleaned_data.items(): field = self.fields[k] if field.answer: # We already have a cached answer object, so we don't # have to create a new one if v == '': # TODO: Deleting the answer removes the option to have a log here. # Maybe setting the answer to '' is the right way to go. field.answer.delete() else: self._save_to_answer(field, field.answer, v) field.answer.save() elif v != '': # Not distinguishing between the question types helps to make # experiences smoother if orga changes a question type. answer = Answer( submission=self.submission, person=self.speaker, question=field.question, ) self._save_to_answer(field, answer, v) answer.save()
def save(self): for k, v in self.cleaned_data.items(): field = self.fields[k] if field.answer: # We already have a cached answer object, so we don't # have to create a new one if v == '' or v is None: field.answer.delete() else: self._save_to_answer(field, field.answer, v) field.answer.save() elif v != '' and v is not None: answer = Answer( review=self.review if field.question.target == QuestionTarget.REVIEWER else None, submission=self.submission if field.question.target == QuestionTarget.SUBMISSION else None, person=self.speaker if field.question.target == QuestionTarget.SPEAKER else None, question=field.question, ) self._save_to_answer(field, answer, v) answer.save()
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()
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 }))
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()