Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move extra questions to info and profile pages #107

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions src/pretalx/cfp/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand, what is the point of re-attaching instance to form under another name?

This line is

form.submission = form.instance

form.save()

submission.speakers.add(request.user)
if draft:
submission.state = SubmissionStates.DRAFT
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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,
)
Expand Down
22 changes: 22 additions & 0 deletions src/pretalx/cfp/templates/cfp/event/submission_info.html
Original file line number Diff line number Diff line change
@@ -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 %}
<div class="d-flex">
<h2>{{ title }}</h2>
{% 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 %}
</div>
<p>
{{ text|rich_text }}
</p>
SUBMISSION INFO
{% for field in form %}
{% bootstrap_field field layout='event' %}
{% endfor %}
{% if questions_form %}{% bootstrap_form questions_form layout='event' %}{% endif %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ <h2>{{ title }}</h2>

{% 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 %}
<script defer src="{% static "vendored/moment-with-locales.js" %}"></script>
Expand Down
10 changes: 10 additions & 0 deletions src/pretalx/cfp/views/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
Loading