예제 #1
0
def validate_non_overlapping_sitting(action, data, context, container,
                                     *fields):
    start = data.get('start_date')
    end = data.get('end_date', None)

    if not fields:
        fields = "start_date", "end_date"

    session = Session()
    group_id = container.__parent__.group_id
    group = session.query(domain.Group).get(group_id)
    sittings = group.sittings

    for sitting in queries.get_sittings_between(sittings, start, end):
        if context != sitting:
            return [
                interface.Invalid(
                    _(
                        u"One or more events would be scheduled for $F, which "
                        "overlaps with an existing sitting",
                        mapping={'F': datetimedict.fromdatetime(start)}),
                    *fields)
            ]

    return []
예제 #2
0
def validate_non_overlapping_sitting(action, data, context, container, *fields):
    start = data.get("start_date")
    end = data.get("end_date", None)

    if not fields:
        fields = "start_date", "end_date"

    session = Session()
    group_id = container.__parent__.group_id
    group = session.query(domain.Group).get(group_id)
    sittings = group.sittings

    for sitting in queries.get_sittings_between(sittings, start, end):
        if context != sitting:
            return [
                interface.Invalid(
                    _(
                        u"One or more events would be scheduled for $F, which " "overlaps with an existing sitting",
                        mapping={"F": datetimedict.fromdatetime(start)},
                    ),
                    *fields
                )
            ]

    return []