Esempio n. 1
0
def test_find_latest_entry_end_dt_valid_day(dummy_event, event_start_dt,
                                            event_end_dt, day, valid):
    dummy_event.start_dt = event_start_dt
    dummy_event.end_dt = event_end_dt
    if not valid:
        with pytest.raises(ValueError):
            find_latest_entry_end_dt(obj=dummy_event, day=day)
Esempio n. 2
0
def move_timetable_entry(entry, parent=None, day=None):
    """Move the `entry` to another session or top-level timetable

    :param entry: `TimetableEntry` to be moved
    :param parent: If specified then the entry will be set as a child
                         of parent
    :param day: If specified then the entry will be moved to the
                        top-level timetable on this day
    """
    if bool(parent) + bool(day) != 1:
        raise TypeError("Wrong number of arguments")

    from indico.modules.events.contributions.operations import update_contribution

    updates = {}
    contrib_update_data = {}
    if day:
        new_start_dt = entry.start_dt.replace(day=day.day, month=day.month)
        updates['start_dt'] = new_start_dt
        updates['parent'] = None
        contrib_update_data = {'session_id': None, 'session_block_id': None}
    elif parent:
        new_start_dt = find_latest_entry_end_dt(
            parent.object) or parent.start_dt
        tz = entry.event.tzinfo
        if (new_start_dt + entry.duration
            ).astimezone(tz).date() != parent.start_dt.astimezone(tz).date():
            raise UserValueError(
                _('Session block cannot span more than one day'))
        updates['parent'] = parent
        updates['start_dt'] = new_start_dt
        contrib_update_data = {
            'session': parent.session_block.session,
            'session_block': parent.session_block
        }

    update_timetable_entry(entry, updates)
    if entry.type == TimetableEntryType.CONTRIBUTION:
        update_contribution(entry.object, contrib_update_data)
    if parent and entry.end_dt > parent.end_dt:
        duration = parent.object.duration + (entry.end_dt - parent.end_dt)
        update_session_block(parent.object, {'duration': duration})
Esempio n. 3
0
def move_timetable_entry(entry, parent=None, day=None):
    """Move the `entry` to another session or top-level timetable

    :param entry: `TimetableEntry` to be moved
    :param parent: If specified then the entry will be set as a child
                         of parent
    :param day: If specified then the entry will be moved to the
                        top-level timetable on this day
    """
    if bool(parent) + bool(day) != 1:
        raise TypeError("Wrong number of arguments")

    from indico.modules.events.contributions.operations import update_contribution

    updates = {}
    contrib_update_data = {}
    if day:
        new_start_dt = entry.start_dt.replace(day=day.day, month=day.month)
        updates["start_dt"] = new_start_dt
        updates["parent"] = None
        contrib_update_data = {"session_id": None, "session_block_id": None}
    elif parent:
        new_start_dt = find_latest_entry_end_dt(parent.object) or parent.start_dt
        tz = entry.event_new.tzinfo
        if (new_start_dt + entry.duration).astimezone(tz).date() != parent.start_dt.astimezone(tz).date():
            raise UserValueError(_("Session block cannot span more than one day"))
        updates["parent"] = parent
        updates["start_dt"] = new_start_dt
        contrib_update_data = {"session": parent.session_block.session, "session_block": parent.session_block}

    update_timetable_entry(entry, updates)
    if entry.type == TimetableEntryType.CONTRIBUTION:
        update_contribution(entry.object, contrib_update_data)
    if parent and entry.end_dt > parent.end_dt:
        duration = parent.object.duration + (entry.end_dt - parent.end_dt)
        update_session_block(parent.object, {"duration": duration})
def _find_latest_entry_end_dt(event, day):
    dt = find_latest_entry_end_dt(event, day)
    if dt:
        return dt.astimezone(event.tzinfo)
Esempio n. 5
0
def test_find_latest_entry_end_dt_valid_day(dummy_event_new, event_start_dt, event_end_dt, day, valid):
    dummy_event_new.start_dt = event_start_dt
    dummy_event_new.end_dt = event_end_dt
    if not valid:
        with pytest.raises(ValueError):
            find_latest_entry_end_dt(obj=dummy_event_new, day=day)