diff --git a/src/pretalx/cfp/flow.py b/src/pretalx/cfp/flow.py index 1ff293c50..1632a2d80 100644 --- a/src/pretalx/cfp/flow.py +++ b/src/pretalx/cfp/flow.py @@ -19,6 +19,9 @@ from django.utils.translation import gettext from django.utils.translation import gettext_lazy as _ from django.views.generic.base import TemplateResponseMixin + +from django_context_decorator import context + from i18nfield.strings import LazyI18nString from i18nfield.utils import I18nJSONEncoder @@ -306,6 +309,7 @@ class InfoStep(GenericFlowStep, FormFlowStep): identifier = "info" icon = "paper-plane" form_class = InfoForm + template_name = "cfp/event/submission_info.html" priority = 0 @property @@ -339,12 +343,26 @@ def get_form_initial(self): result[field] = obj return result + @context + def questions_form(self): + return QuestionsForm( + data=self.request.POST if self.request.method == "POST" else None, + files=self.request.FILES if self.request.method == "POST" else None, + event=self.request.event, + speaker=self.request.user, + target="submission", + ) + def done(self, request, draft=False): self.request = request form = self.get_form(from_storage=True) + form.speaker = request.user form.instance.event = self.event - form.save() + form.is_valid() submission = form.instance + form.submission = submission + form.save() + submission.speakers.add(request.user) if draft: submission.state = SubmissionStates.DRAFT @@ -383,6 +401,12 @@ def done(self, request, draft=False): access_code.save() request.submission = submission + self.request = request + + qform = self.questions_form() + if qform.is_valid(): + qform.submission = self.request.submission + qform.save() class QuestionsStep(GenericFlowStep, FormFlowStep): @@ -537,16 +561,31 @@ def get_context_data(self, **kwargs): result["gravatar_parameter"] = User(email=email).gravatar_parameter return result + @context + def questions_form(self): + return QuestionsForm( + data=self.request.POST if self.request.method == "POST" else None, + files=self.request.FILES if self.request.method == "POST" else None, + event=self.request.event, + speaker=self.request.user, + target="speaker", + ) + def done(self, request, draft=False): form = self.get_form(from_storage=True) form.is_valid() form.user = request.user form.save() + self.request = request + + qform = self.questions_form() + if qform.is_valid(): + qform.submission = self.request.submission + qform.save() DEFAULT_STEPS = ( InfoStep, - QuestionsStep, UserStep, ProfileStep, ) diff --git a/src/pretalx/cfp/templates/cfp/event/submission_info.html b/src/pretalx/cfp/templates/cfp/event/submission_info.html new file mode 100644 index 000000000..a4b56d0cb --- /dev/null +++ b/src/pretalx/cfp/templates/cfp/event/submission_info.html @@ -0,0 +1,22 @@ +{% extends "cfp/event/submission_base.html" %} +{% load bootstrap4 %} +{% load i18n %} +{% load orga_edit_link %} +{% load rich_text %} +{% load rules %} + +{% block inner %} +
+

{{ title }}

+ {% has_perm 'orga.edit_cfp' request.user request.event as can_edit_cfp %} + {% if can_edit_cfp %}{% orga_edit_link request.event.cfp.urls.editor %}{% endif %} +
+

+ {{ text|rich_text }} +

+ SUBMISSION INFO + {% for field in form %} + {% bootstrap_field field layout='event' %} + {% endfor %} + {% if questions_form %}{% bootstrap_form questions_form layout='event' %}{% endif %} +{% endblock %} diff --git a/src/pretalx/cfp/templates/cfp/event/submission_profile.html b/src/pretalx/cfp/templates/cfp/event/submission_profile.html index 7141633a4..f17ea9930 100644 --- a/src/pretalx/cfp/templates/cfp/event/submission_profile.html +++ b/src/pretalx/cfp/templates/cfp/event/submission_profile.html @@ -24,6 +24,7 @@

{{ title }}

{% bootstrap_field form.name layout='event' %} {% if form.biography %}{% bootstrap_field form.biography layout='event' %}{% endif %} + {% if questions_form %}{% bootstrap_form questions_form layout='event' %}{% endif %} {% if form.availabilities %} {% compress js %} diff --git a/src/pretalx/cfp/views/wizard.py b/src/pretalx/cfp/views/wizard.py index ffa5603cd..3fce40c8f 100644 --- a/src/pretalx/cfp/views/wizard.py +++ b/src/pretalx/cfp/views/wizard.py @@ -33,6 +33,7 @@ def get(request, *args, **kwargs): @method_decorator(csp_update(IMG_SRC="https://www.gravatar.com"), name="dispatch") class SubmitWizard(EventPageMixin, View): + reqs = {} @transaction.atomic def dispatch(self, request, *args, **kwargs): self.event = self.request.event @@ -60,6 +61,9 @@ def dispatch(self, request, *args, **kwargs): handler = getattr(step, request.method.lower(), self.http_method_not_allowed) result = handler(request) + if request.method == "POST" and not self.reqs.get(step.identifier): + self.reqs[step.identifier] = request + if request.method == "POST" and request.POST.get("action", "submit") == "draft": return self.done( request, @@ -93,8 +97,14 @@ def done(self, request, draft=False, steps=None): request.event.cfp_flow.steps_dict["user"].done(request) for step in valid_steps: if not step.identifier == "user": + req = self.reqs.get(step.identifier) + if getattr(request, "submission", False): + req.submission = request.submission + request = req step.done(request, draft=draft) + self.reqs = {} + if not draft: try: request.submission.send_initial_mails(person=request.user)