From b50f368dea7007fafa510f881d730ae4d65213d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Sat, 18 Aug 2018 20:43:10 +0200 Subject: [PATCH] Add a slides field to talk and lightning talk forms. --- src/program/forms.py | 35 +++++++++++++++---- .../includes/event_proposal_table.html | 3 +- src/program/views.py | 9 ++--- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/program/forms.py b/src/program/forms.py index 6a9a70ee..ece0b23b 100644 --- a/src/program/forms.py +++ b/src/program/forms.py @@ -1,12 +1,8 @@ import logging -from betterforms.multiform import MultiModelForm -from collections import OrderedDict from django import forms -from django.forms.widgets import TextInput -from django.utils.dateparse import parse_duration -from .models import SpeakerProposal, EventProposal, EventTrack +from .models import SpeakerProposal, EventProposal, EventTrack, Url, UrlType logger = logging.getLogger("bornhack.%s" % __name__) @@ -160,9 +156,16 @@ class EventProposalForm(forms.ModelForm): """ The EventProposalForm. Takes an EventType in __init__ and changes fields accordingly. """ + + slides_url = forms.URLField( + label="Slides URL", + help_text="Add a URL to your slides.", + required=False + ) + class Meta: model = EventProposal - fields = ['title', 'abstract', 'allow_video_recording', 'duration', 'submission_notes', 'track'] + fields = ['title', 'abstract', 'allow_video_recording', 'duration', 'slides_url', 'submission_notes', 'track'] def clean_duration(self): duration = self.cleaned_data['duration'] @@ -175,6 +178,19 @@ class EventProposalForm(forms.ModelForm): # TODO: make sure the track is part of the current camp, needs camp as form kwarg to verify return track + def save(self, user, event_type, commit=True): + self.instance.user = user + self.instance.event_type = event_type + super().save(commit=True) + if self.cleaned_data['slides_url'] and (self.instance.event_type.name == 'Talk' or self.instance.event_type.name == 'Lightning Talk'): + slides_url = Url() + slides_url.eventproposal = self.instance + slides_url.url = self.cleaned_data['slides_url'] + slides_url.urltype = UrlType.objects.get(name="Slides") + slides_url.save() + return self.instance + + def __init__(self, camp, eventtype=None, *args, **kwargs): # initialise form super().__init__(*args, **kwargs) @@ -186,6 +202,10 @@ class EventProposalForm(forms.ModelForm): # make sure video_recording checkbox defaults to checked self.fields['allow_video_recording'].initial = True + if not (eventtype.name == 'Talk' or eventtype.name == 'Lightning Talk'): + # Only talk or lightning talk should show the slides_url field + del(self.fields['slides_url']) + if eventtype.name == 'Debate': # fix label and help_text for the title field self.fields['title'].label = 'Title of debate' @@ -254,6 +274,9 @@ class EventProposalForm(forms.ModelForm): 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.' + if 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." + # no duration for talks del(self.fields['duration']) diff --git a/src/program/templates/includes/event_proposal_table.html b/src/program/templates/includes/event_proposal_table.html index cdbdb8ba..531423fa 100644 --- a/src/program/templates/includes/event_proposal_table.html +++ b/src/program/templates/includes/event_proposal_table.html @@ -17,7 +17,8 @@ {{ eventproposal.title }} {{ eventproposal.event_type }} - {% for url in eventproposal.urls.all %} {% empty %}N/A{% endfor %} + {% for url in eventproposal.urls.all %} + {% empty %}N/A{% endfor %} {% for person in eventproposal.speakers.all %} {% if request.resolver_match.app_name == "program" %} diff --git a/src/program/views.py b/src/program/views.py index a4b6219f..d611cca9 100644 --- a/src/program/views.py +++ b/src/program/views.py @@ -417,10 +417,11 @@ class EventProposalCreateView(LoginRequiredMixin, CampViewMixin, EnsureWritableC def form_valid(self, form): # set camp and user for this eventproposal - eventproposal = form.save(commit=False) - eventproposal.user = self.request.user - eventproposal.event_type = self.event_type - eventproposal.save() + eventproposal = form.save( + user=self.request.user, + event_type=self.event_type, + commit=True, + ) # add the speakerproposal to the eventproposal eventproposal.speakers.add(self.speakerproposal)