Changeset - ed21bc03359b
[Not reviewed]
0 1 0
Clinton Roy - 5 years ago 2019-10-19 01:38:29
clintonr@ansto.gov.au
mandate both csv files, so that we can always get room order. actually finding/creating objects
1 file changed with 60 insertions and 29 deletions:
0 comments (0 inline, 0 general)
pinaxcon/registrasion/management/commands/update_schedule.py
Show inline comments
 
from django.core.management.base import BaseCommand
 

	
 
from symposion.conference.models import Section, current_conference, Conference
 

	
 

	
 
from symposion.schedule.models import Day, Schedule, Session
 

	
 
from symposion.schedule.models import (Day, Presentation, Room, SlotKind, Slot,
 
                                       SlotRoom, ProposalBase)
 

	
 
from dateutil.parser import parse
 

	
 
from collections import  Counter
...
 
@@ -20,13 +28,23 @@ class Command(BaseCommand):
 

	
 
    def add_arguments(self, parser):
 
        parser.add_argument(self.SLOTS, type=Path)
 
        parser.add_argument(self.TALKS, nargs="?", type=Path, default=None)
 
        parser.add_argument(self.TALKS, type=Path)
 

	
 
    def handle(self, *args, **options):
 
        all_kinds, all_rooms = set(), set()
 
        date_strs = set()
 
        slotkind_names = set()
 
        room_names = set()
 
        slot = {}
 
        slot_type_count = Counter()
 

	
 
        conf = current_conference()
 
        section = Section.objects.filter(conference=conf, slug="main").all().first()
 
        schedule, _created = Schedule.objects.get_or_create(section=section)
 

	
 
        print('conf', conf)
 
        print('section', section)
 
        print('schedule', schedule)
 

	
 
        with open(options[self.SLOTS]) as csv_file:
 
            csv_reader = csv.reader(csv_file)
 

	
...
 
@@ -38,10 +56,11 @@ class Command(BaseCommand):
 
                assert len(row) == len(self.known_headers)
 

	
 
                rowdate, start_time, end_time, kind, rooms = row
 
                all_kinds.add(kind)
 
                slotkind_names.add(kind)
 

	
 
                if rowdate:
 
                    date = rowdate
 
                    date_strs.add(date)
 

	
 
                assert kind, "kind cannot be blank"
 

	
...
 
@@ -50,47 +69,59 @@ class Command(BaseCommand):
 

	
 
                for room in rooms.split(';'):
 
                    room = room.strip()
 
                    all_rooms.add(room)
 
                    room_names.add(room)
 

	
 
                    slot[(date, slot_name, room)] = self.find_or_create_slot(
 
                        date, start_time, end_time, room)
 

	
 
        print(slot.keys())
 
        with open(options[self.TALKS]) as csv_file:
 
            csv_reader = csv.reader(csv_file)
 

	
 
            used_rooms = next(csv_reader)
 

	
 
        if options[self.TALKS]:
 
            with open(options[self.TALKS]) as csv_file:
 
                csv_reader = csv.reader(csv_file)
 
            assert used_rooms[0] == '', "Cell (1, 1) must be empty"
 

	
 
                used_rooms = next(csv_reader)
 
            for room in used_rooms[1:]:
 
                assert room in room_names, f"Unknown room: {room}"
 

	
 
            for row in csv_reader:
 
                cell = row[0]
 

	
 
                assert used_rooms[0] == '', "Cell (1, 1) must be empty"
 
                if cell.rsplit(' ', 1)[0] in slotkind_names:
 
                    kind = cell
 

	
 
                for room in used_rooms[1:]:
 
                    assert room in all_rooms, f"Unknown room: {room}"
 
                    for i, room in enumerate(used_rooms[1:], 1):
 
                        talk_id = row[i]
 

	
 
                for row in csv_reader:
 
                    cell = row[0]
 
                        if not talk_id:
 
                            continue
 

	
 
                    if cell.rsplit(' ', 1)[0] in all_kinds:
 
                        kind = cell
 
                        assert (date, kind, room) in slot, f"Slot ({date}, '{kind}', '{room}') not found"
 

	
 
                        print('used_rooms', used_rooms)
 
                        # TODO set the talk slot to the associated talk
 
                        # place_talk(slot[(date, slot_name)].talk = int(talk_id)
 

	
 
                        for i, room in enumerate(used_rooms[1:], 1):
 
                            talk_id = row[i]
 
                else:
 
                    assert parse(row[0]), "Not a date: {row[0]}"
 

	
 
                            if not talk_id:
 
                                continue
 
                    date = row[0]
 

	
 
                            assert (date, kind, room) in slot, f"Slot ({date}, '{kind}', '{room}') not found"
 
                    for col in row[1:]:
 
                        assert col == '', f"All other columns must be empty: {date}"
 

	
 
                            # TODO set the talk slot to the associated talk
 
                            # place_talk(slot[(date, slot_name)].talk = int(talk_id)
 
        days = {}
 
        for date in date_strs:
 
            print('schedule', type(schedule))
 
            day, _created = Day.objects.get_or_create(
 
                schedule=schedule, date=date)
 
            days['date'] = day
 

	
 
                    else:
 
                        assert parse(row[0]), "Not a date: {row[0]}"
 
        rooms = {}
 
        for room_name in room_names:
 
            room, _created = Room.objects.get_or_create(
 
                schedule=schedule, name=room_name, order=used_rooms.index(room_name))
 

	
 
                        date = row[0]
 
        slotkind = {}
 
        for slotkind_name in slotkind_names:
 
            slotkind, _created = SlotKind.objects.get_or_create(schedule=schedule, label=slotkind_name)
 

	
 
                        for col in row[1:]:
 
                            assert col == '', f"All other columns must be empty: {date}"
0 comments (0 inline, 0 general)