Exemplo n.º 1
0
def _create_talk(*, talk, room, event):
    date = talk.find('date').text
    start = parse(date + ' ' + talk.find('start').text)
    hours, minutes = talk.find('duration').text.split(':')
    duration = timedelta(hours=int(hours), minutes=int(minutes))
    duration_in_minutes = duration.total_seconds() / 60
    try:
        end = parse(date + ' ' + talk.find('end').text)
    except AttributeError:
        end = start + duration
    sub_type = SubmissionType.objects.filter(
        event=event,
        name=talk.find('type').text,
        default_duration=duration_in_minutes).first()

    if not sub_type:
        sub_type = SubmissionType.objects.create(
            name=talk.find('type').text or 'default',
            event=event,
            default_duration=duration_in_minutes,
        )

    track = Track.objects.filter(event=event,
                                 name=talk.find('track').text).first()

    if not track:
        track = Track.objects.create(name=talk.find('track').text or 'default',
                                     event=event)

    optout = False
    with suppress(AttributeError):
        optout = talk.find('recording').find('optout').text == 'true'

    code = None
    if (Submission.objects.filter(code__iexact=talk.attrib['id'],
                                  event=event).exists()
            or not Submission.objects.filter(
                code__iexact=talk.attrib['id']).exists()):
        code = talk.attrib['id']
    elif (Submission.objects.filter(code__iexact=talk.attrib['guid'][:16],
                                    event=event).exists()
          or not Submission.objects.filter(
              code__iexact=talk.attrib['guid'][:16]).exists()):
        code = talk.attrib['guid'][:16]

    sub, _ = Submission.objects.get_or_create(
        event=event, code=code, defaults={'submission_type': sub_type})
    sub.submission_type = sub_type
    sub.track = track
    sub.title = talk.find('title').text
    sub.description = talk.find('description').text
    if talk.find('subtitle').text:
        sub.description = talk.find('subtitle').text + '\n' + (sub.description
                                                               or '')
    sub.abstract = talk.find('abstract').text
    sub.content_locale = talk.find('language').text or 'en'
    sub.do_not_record = optout
    sub.state = SubmissionStates.CONFIRMED
    sub.save()

    for person in talk.find('persons').findall('person'):
        user = User.objects.filter(name=person.text[:60]).first()
        if not user:
            user = User(name=person.text, email=f'{person.text}@localhost')
            user.save()
            SpeakerProfile.objects.create(user=user, event=event)
        sub.speakers.add(user)

    slot, _ = TalkSlot.objects.get_or_create(submission=sub,
                                             schedule=event.wip_schedule,
                                             is_visible=True)
    slot.room = room
    slot.is_visible = True
    slot.start = start
    slot.end = end
    slot.save()
Exemplo n.º 2
0
def _create_talk(*, talk, room, event):
    changes = dict()
    date = talk.find('date').text
    start = parse(date + ' ' + talk.find('start').text)
    hours, minutes = talk.find('duration').text.split(':')
    duration = timedelta(hours=int(hours), minutes=int(minutes))
    duration_in_minutes = duration.total_seconds() / 60
    try:
        end = parse(date + ' ' + talk.find('end').text)
    except AttributeError:
        end = start + duration
    sub_type = SubmissionType.objects.filter(
        event=event, name=talk.find('type').text, default_duration=duration_in_minutes
    ).first()

    if not sub_type:
        sub_type = SubmissionType.objects.create(
            name=talk.find('type').text or 'default',
            event=event,
            default_duration=duration_in_minutes,
        )

    tracks = Track.objects.filter(
        event=event, name__icontains=talk.find('track').text,
    )
    track = [t for t in tracks if str(t.name) == talk.find('track').text]

    if not track:
        track = Track.objects.create(
            name=talk.find('track').text or 'default',
            event=event,
        )
    else:
        track = track[0]

    optout = False
    with suppress(AttributeError):
        optout = talk.find('recording').find('optout').text == 'true'

    code = None
    if (
        Submission.objects.filter(code__iexact=talk.attrib['id'], event=event).exists()
        or not Submission.objects.filter(code__iexact=talk.attrib['id']).exists()
    ):
        code = talk.attrib['id']
    elif (
        Submission.objects.filter(
            code__iexact=talk.attrib['guid'][:16], event=event
        ).exists()
        or not Submission.objects.filter(code__iexact=talk.attrib['guid'][:16]).exists()
    ):
        code = talk.attrib['guid'][:16]

    sub, created = Submission.objects.get_or_create(
        event=event, code=code, defaults={'submission_type': sub_type}
    )
    sub.submission_type = sub_type
    sub.track = track

    change_tracking_data = {
        'title': talk.find('title').text,
        'description': talk.find('description').text,
        'abstract': talk.find('abstract').text,
        'content_locale': talk.find('language').text or 'en',
        'do_not_record': optout,
    }
    if talk.find('subtitle').text:
        change_tracking_data['description'] = (
            talk.find('subtitle').text
            + '\n'
            + (change_tracking_data['description'] or '')
        )

    for key, value in change_tracking_data.items():
        if not getattr(sub, key) == value:
            changes[key] = {'old': getattr(sub, key), 'new': value}
            setattr(sub, key, value)

    sub.save()

    for person in talk.find('persons').findall('person'):
        user = User.objects.filter(name=person.text[:60]).first()
        if not user:
            user = User(name=person.text, email=f'{person.text}@localhost')
            user.save()
            SpeakerProfile.objects.create(user=user, event=event)
        sub.speakers.add(user)

    slot, _ = TalkSlot.objects.get_or_create(
            submission=sub, schedule=event.wip_schedule, defaults={'is_visible': True}
    )
    slot.room = room
    slot.is_visible = True
    slot.start = start
    slot.end = end
    slot.save()
    if not created and changes:
        return {sub.code: changes}
    return dict()
Exemplo n.º 3
0
def _create_talk(*, talk, room, event):
    date = talk.find("date").text
    start = parse(date + " " + talk.find("start").text)
    hours, minutes = talk.find("duration").text.split(":")
    duration = dt.timedelta(hours=int(hours), minutes=int(minutes))
    duration_in_minutes = duration.total_seconds() / 60
    try:
        end = parse(date + " " + talk.find("end").text)
    except AttributeError:
        end = start + duration
    sub_type = SubmissionType.objects.filter(
        event=event, name=talk.find("type").text, default_duration=duration_in_minutes
    ).first()

    if not sub_type:
        sub_type = SubmissionType.objects.create(
            name=talk.find("type").text or "default",
            event=event,
            default_duration=duration_in_minutes,
        )

    track = Track.objects.filter(event=event, name=talk.find("track").text).first()

    if not track:
        track = Track.objects.create(
            name=talk.find("track").text or "default", event=event
        )

    optout = False
    with suppress(AttributeError):
        optout = talk.find("recording").find("optout").text == "true"

    code = None
    if (
        Submission.objects.filter(code__iexact=talk.attrib["id"], event=event).exists()
        or not Submission.objects.filter(code__iexact=talk.attrib["id"]).exists()
    ):
        code = talk.attrib["id"]
    elif (
        Submission.objects.filter(
            code__iexact=talk.attrib["guid"][:16], event=event
        ).exists()
        or not Submission.objects.filter(code__iexact=talk.attrib["guid"][:16]).exists()
    ):
        code = talk.attrib["guid"][:16]

    sub, _ = Submission.objects.get_or_create(
        event=event, code=code, defaults={"submission_type": sub_type}
    )
    sub.submission_type = sub_type
    sub.track = track
    sub.title = talk.find("title").text
    sub.description = talk.find("description").text
    if talk.find("subtitle").text:
        sub.description = talk.find("subtitle").text + "\n" + (sub.description or "")
    sub.abstract = talk.find("abstract").text
    sub.content_locale = talk.find("language").text or "en"
    sub.do_not_record = optout
    sub.state = SubmissionStates.CONFIRMED
    sub.save()

    for person in talk.find("persons").findall("person"):
        user = User.objects.filter(name=person.text[:60]).first()
        if not user:
            user = User(name=person.text, email=f"{person.text}@localhost")
            user.save()
            SpeakerProfile.objects.create(user=user, event=event)
        sub.speakers.add(user)

    slot, _ = TalkSlot.objects.get_or_create(
        submission=sub, schedule=event.wip_schedule, is_visible=True
    )
    slot.room = room
    slot.is_visible = True
    slot.start = start
    slot.end = end
    slot.save()
Exemplo n.º 4
0
    def handle(self, *args, **options):
        path = options.get('path')
        tree = ET.parse(path)
        root = tree.getroot()

        event_data = root.find('conference')
        event = Event(
            name=event_data.find('title').text,
            slug=event_data.find('acronym').text,
            date_from=datetime.strptime(
                event_data.find('start').text, '%Y-%m-%d').date(),
            date_to=datetime.strptime(event_data.find('end').text,
                                      '%Y-%m-%d').date(),
        )
        event.save()
        for user in User.objects.filter(is_superuser=True):
            EventPermission.objects.create(event=event,
                                           user=user,
                                           is_orga=True)

        for day in root.findall('day'):
            for rm in day.findall('room'):
                room, _ = Room.objects.get_or_create(event=event,
                                                     name=rm.attrib['name'])
                for talk in rm.findall('event'):
                    date = talk.find('date').text
                    start = parse(date + ' ' + talk.find('start').text)
                    try:
                        end = parse(date + ' ' + talk.find('end').text)
                    except AttributeError:
                        hours, minutes = talk.find('duration').text.split(':')
                        duration = timedelta(hours=int(hours),
                                             minutes=int(minutes))
                        end = start + duration
                    sub_type = SubmissionType.objects.filter(
                        event=event, name=talk.find('type').text).first()

                    if not sub_type:
                        sub_type = SubmissionType(name=talk.find('type').text
                                                  or 'default',
                                                  event=event)
                        sub_type.save()

                    sub = Submission.objects.create(
                        event=event,
                        code=talk.attrib['id'],
                        submission_type=sub_type,
                        title=talk.find('title').text,
                        description=talk.find('description').text,
                        abstract=talk.find('abstract').text,
                        content_locale=talk.find('language').text or 'en',
                        do_not_record=talk.find('recording').find(
                            'optout').text == 'true',
                        state=SubmissionStates.CONFIRMED,
                    )
                    for person in talk.find('persons').findall('person'):
                        user = User.objects.filter(nick=person.text).first()
                        if not user:
                            user = User(nick=person.text,
                                        name=person.text,
                                        email=f'{person.text}@localhost')
                            user.save()
                            SpeakerProfile.objects.create(user=user,
                                                          event=event)
                        sub.speakers.add(user)

                    TalkSlot.objects.create(submission=sub,
                                            schedule=event.wip_schedule,
                                            room=room,
                                            is_visible=True,
                                            start=start,
                                            end=end)

        schedule_version = root.find('version').text
        event.wip_schedule.freeze(schedule_version)
        event.schedules.get(version=schedule_version).talks.update(
            is_visible=True)