Add a slides field to talk and lightning talk forms.

This commit is contained in:
Víðir Valberg Guðmundsson 2018-08-18 20:43:10 +02:00
parent 24cc84dcd1
commit b50f368dea
3 changed files with 36 additions and 11 deletions

View file

@ -1,12 +1,8 @@
import logging import logging
from betterforms.multiform import MultiModelForm
from collections import OrderedDict
from django import forms 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__) 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. 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: class Meta:
model = EventProposal 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): def clean_duration(self):
duration = self.cleaned_data['duration'] 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 # 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):
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): def __init__(self, camp, eventtype=None, *args, **kwargs):
# initialise form # initialise form
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@ -186,6 +202,10 @@ class EventProposalForm(forms.ModelForm):
# make sure video_recording checkbox defaults to checked # make sure video_recording checkbox defaults to checked
self.fields['allow_video_recording'].initial = True 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': if eventtype.name == 'Debate':
# fix label and help_text for the title field # fix label and help_text for the title field
self.fields['title'].label = 'Title of debate' 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'].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":
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
del(self.fields['duration']) del(self.fields['duration'])

View file

@ -17,7 +17,8 @@
<tr> <tr>
<td><span class="h4">{{ eventproposal.title }}</span></td> <td><span class="h4">{{ eventproposal.title }}</span></td>
<td><i class="fas fa-{{ eventproposal.event_type.icon }} fa-lg" style="color: {{ eventproposal.event_type.color }};"></i><span class="h4"> {{ eventproposal.event_type }}</span></td> <td><i class="fas fa-{{ eventproposal.event_type.icon }} fa-lg" style="color: {{ eventproposal.event_type.color }};"></i><span class="h4"> {{ eventproposal.event_type }}</span></td>
<td><span class="h4">{% for url in eventproposal.urls.all %}<a href="{{ url.url }}" target="_blank"><i class="{{ url.urltype.icon }}" data-toggle="tooltip" title="{{ url.urltype.name }}"></i></a> {% empty %}N/A{% endfor %}</span></td> <td><span class="h4">{% for url in eventproposal.urls.all %}<a href="{{ url.url }}" target="_blank">
<i class="{{ url.urltype.icon }}" data-toggle="tooltip" title="{{ url.urltype.name }}"></i></a> {% empty %}N/A{% endfor %}</span></td>
<td><span class="h4"> <td><span class="h4">
{% for person in eventproposal.speakers.all %} {% for person in eventproposal.speakers.all %}
{% if request.resolver_match.app_name == "program" %} {% if request.resolver_match.app_name == "program" %}

View file

@ -417,10 +417,11 @@ 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(commit=False) eventproposal = form.save(
eventproposal.user = self.request.user user=self.request.user,
eventproposal.event_type = self.event_type event_type=self.event_type,
eventproposal.save() commit=True,
)
# add the speakerproposal to the eventproposal # add the speakerproposal to the eventproposal
eventproposal.speakers.add(self.speakerproposal) eventproposal.speakers.add(self.speakerproposal)