Fix proposal submission.

This commit is contained in:
Víðir Valberg Guðmundsson 2018-08-19 18:21:04 +02:00
parent 52d3e827c8
commit b871613d24
2 changed files with 25 additions and 27 deletions

View file

@ -1,6 +1,7 @@
import logging import logging
from django import forms from django import forms
from django.core.exceptions import ImproperlyConfigured
from .models import SpeakerProposal, EventProposal, EventTrack, Url, UrlType from .models import SpeakerProposal, EventProposal, EventTrack, Url, UrlType
@ -178,18 +179,25 @@ class EventProposalForm(forms.ModelForm):
# TODO: make sure the track is part of the current camp, needs camp as form kwarg to verify # TODO: make sure the track is part of the current camp, needs camp as form kwarg to verify
return track return track
def save(self, user, event_type, commit=True): def save(self, commit=True, user=None, event_type=None):
self.instance.user = user eventproposal = super().save(commit=False)
self.instance.event_type = event_type if user:
super().save(commit=True) eventproposal.user = user
if self.cleaned_data.get('slides_url') and (self.instance.event_type.name == 'Talk' or self.instance.event_type.name == 'Lightning Talk'): if event_type:
eventproposal.event_type = event_type
eventproposal.save()
if self.cleaned_data.get('slides_url') and event_type.name in ['Talk', 'Lightning Talk']:
url = self.cleaned_data.get('slides_url')
if not eventproposal.urls.filter(url=url).exists():
slides_url = Url() slides_url = Url()
slides_url.eventproposal = self.instance slides_url.eventproposal = eventproposal
slides_url.url = self.cleaned_data['slides_url'] slides_url.url = url
slides_url.urltype = UrlType.objects.get(name="Slides") slides_url.urltype = UrlType.objects.get(name="Slides")
slides_url.save() slides_url.save()
return self.instance
return eventproposal
def __init__(self, camp, eventtype=None, *args, **kwargs): def __init__(self, camp, eventtype=None, *args, **kwargs):
# initialise form # initialise form
@ -274,7 +282,7 @@ class EventProposalForm(forms.ModelForm):
self.fields['submission_notes'].label = 'Talk Notes' self.fields['submission_notes'].label = 'Talk Notes'
self.fields['submission_notes'].help_text = 'Private notes regarding this talk. Only visible to yourself and the BornHack organisers.' self.fields['submission_notes'].help_text = 'Private notes regarding this talk. Only visible to yourself and the BornHack organisers.'
if eventtype.name == "Lightning Talk": if self.fields.get('slides_url') and eventtype.name == "Lightning Talk":
self.fields['slides_url'].help_text += " You will only get assigned a slot if you have provided slides (a title slide is enough if you don't use slides for the talk). You can add an URL later if need be." self.fields['slides_url'].help_text += " You will only get assigned a slot if you have provided slides (a title slide is enough if you don't use slides for the talk). You can add an URL later if need be."
# no duration for talks # no duration for talks

View file

@ -1,11 +1,9 @@
import logging import logging
import os
from collections import OrderedDict from collections import OrderedDict
from django.views.generic import ListView, TemplateView, DetailView, View from django.views.generic import ListView, TemplateView, DetailView, View
from django.views.generic.edit import CreateView, UpdateView, DeleteView, FormView from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.conf import settings from django.conf import settings
from django.views.decorators.http import require_safe
from django.http import Http404, HttpResponse from django.http import Http404, HttpResponse
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.contrib.admin.views.decorators import staff_member_required from django.contrib.admin.views.decorators import staff_member_required
@ -14,14 +12,13 @@ from django.contrib import messages
from django.urls import reverse, reverse_lazy from django.urls import reverse, reverse_lazy
from django.template import Engine, Context from django.template import Engine, Context
from django.shortcuts import redirect from django.shortcuts import redirect
from django.core.exceptions import ImproperlyConfigured
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from betterforms.multiform import MultiModelForm from betterforms.multiform import MultiModelForm
import icalendar import icalendar
from camps.mixins import CampViewMixin from camps.mixins import CampViewMixin
from program.models import Url, UrlType
from .mixins import ( from .mixins import (
EnsureUnapprovedProposalMixin,
EnsureUserOwnsProposalMixin, EnsureUserOwnsProposalMixin,
EnsureWritableCampMixin, EnsureWritableCampMixin,
EnsureCFPOpenMixin, EnsureCFPOpenMixin,
@ -417,11 +414,7 @@ class EventProposalCreateView(LoginRequiredMixin, CampViewMixin, EnsureWritableC
def form_valid(self, form): def form_valid(self, form):
# set camp and user for this eventproposal # set camp and user for this eventproposal
eventproposal = form.save( eventproposal = form.save(user=self.request.user, event_type=self.event_type)
user=self.request.user,
event_type=self.event_type,
commit=True,
)
# add the speakerproposal to the eventproposal # add the speakerproposal to the eventproposal
eventproposal.speakers.add(self.speakerproposal) eventproposal.speakers.add(self.speakerproposal)
@ -569,10 +562,7 @@ class CombinedProposalSubmitView(LoginRequiredMixin, CampViewMixin, CreateView):
Save the object(s) here before redirecting Save the object(s) here before redirecting
""" """
if hasattr(self, 'speakerproposal'): if hasattr(self, 'speakerproposal'):
eventproposal = form.save(commit=False) eventproposal = form.save(user=self.request.user, event_type=self.eventtype)
eventproposal.user = self.request.user
eventproposal.event_type = self.eventtype
eventproposal.save()
eventproposal.speakers.add(self.speakerproposal) eventproposal.speakers.add(self.speakerproposal)
else: else:
# first save the SpeakerProposal # first save the SpeakerProposal
@ -584,7 +574,7 @@ class CombinedProposalSubmitView(LoginRequiredMixin, CampViewMixin, CreateView):
speakerproposal.save() speakerproposal.save()
# then save the eventproposal # then save the eventproposal
eventproposal = form['eventproposal'].save(commit=False) eventproposal = form['eventproposal'].save(user=self.request.user, event_type=self.eventtype)
eventproposal.user = self.request.user eventproposal.user = self.request.user
eventproposal.event_type = self.eventtype eventproposal.event_type = self.eventtype
eventproposal.save() eventproposal.save()