From 97d55b8876f941deda6ed11e19dc093d0d6b3631 Mon Sep 17 00:00:00 2001 From: Tobias Date: Thu, 27 Sep 2018 20:55:26 +1200 Subject: [PATCH] Use sensible date format in symposion schedule upload --- vendor/symposion/schedule/forms.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/vendor/symposion/schedule/forms.py b/vendor/symposion/schedule/forms.py index 4acbc8c9..e2dffedb 100644 --- a/vendor/symposion/schedule/forms.py +++ b/vendor/symposion/schedule/forms.py @@ -10,7 +10,7 @@ from django.db import IntegrityError, transaction from django.db.models import Q from symposion.schedule.models import (Day, Presentation, Room, SlotKind, Slot, - SlotRoom) + SlotRoom, ProposalBase) class SlotEditForm(forms.Form): @@ -58,6 +58,8 @@ class ScheduleSectionForm(forms.Form): DATE_KEY = 'date' START_KEY = 'time_start' END_KEY = 'time_end' + EXCLUSIVE = 'exclusive' + PROPOSAL = 'proposal_id' KIND = 'kind' filename = forms.FileField( @@ -103,6 +105,7 @@ class ScheduleSectionForm(forms.Form): room = Room.objects.create( schedule=self.schedule, name=room, order=i ) + created = True if created: created_rooms.append(room) return created_rooms @@ -113,7 +116,7 @@ class ScheduleSectionForm(forms.Form): days = set([x[self.DATE_KEY] for x in data]) for day in days: try: - date = datetime.strptime(day, "%m/%d/%Y") + date = datetime.strptime(day, "%Y-%m-%d") except ValueError: [x.delete() for x in created_days] return messages.ERROR, u'Malformed data found: %s.' % day @@ -138,7 +141,7 @@ class ScheduleSectionForm(forms.Form): room = Room.objects.get( schedule=self.schedule, name=row[self.ROOM_KEY] ) - date = datetime.strptime(row[self.DATE_KEY], "%m/%d/%Y") + date = datetime.strptime(row[self.DATE_KEY], "%Y-%m-%d") day = Day.objects.get(schedule=self.schedule, date=date) start, end = self._get_start_end_times(row) slot_kind, created = SlotKind.objects.get_or_create( @@ -148,13 +151,13 @@ class ScheduleSectionForm(forms.Form): created_items.append(slot_kind) if row[self.KIND] == 'plenary': slot, created = Slot.objects.get_or_create( - kind=slot_kind, day=day, start=start, end=end + kind=slot_kind, day=day, start=start, end=end, exclusive=bool(int(row[self.EXCLUSIVE])) ) if created: created_items.append(slot) else: slot = Slot.objects.create( - kind=slot_kind, day=day, start=start, end=end + kind=slot_kind, day=day, start=start, end=end, exclusive=bool(int(row[self.EXCLUSIVE])) ) created_items.append(slot) try: @@ -165,6 +168,18 @@ class ScheduleSectionForm(forms.Form): for x in created_items: x.delete() return messages.ERROR, u'An overlap occurred; the import was cancelled.' + + if row[self.PROPOSAL]: + proposal = ProposalBase.objects.get(id=row[self.PROPOSAL]) + Presentation.objects.get_or_create( + slot=slot, + section_id=1, + proposal_base=proposal, + speaker=proposal.speaker, + title=proposal.title, + abstract=proposal.abstract + ) + return messages.SUCCESS, u'Your schedule has been imported.' def delete_schedule(self):