def validate_recurring_sittings(action, data, context, container):
    """Validate recurring sittings.

    This validator determines the sittings that will be created and
    confirms the validity of them.
    """

    start = data.get("start_date")
    end = data.get("end_date")
    weekdays = data.get("weekdays")
    monthly = data.get("monthly")
    repeat = data.get("repeat")
    repeat_until = data.get("repeat_until")
    exceptions = data.get("exceptions", ())
    
    session = Session()
    group_id = container.__parent__.group_id
    group = session.query(domain.Group).get(group_id)
    
    errors = []
    if weekdays or monthly:
        # this should be an invariant, but due to formlib's requirement
        # that invariant methods pertain to a single schema, it's not
        # possible
        if repeat_until is not None and repeat_until < start.date():
            #session.close()
            return [Invalid(
                _(u"If recurrence is limited by date, it "
                  "must lie after the starting date"),
                "repeat_until")]

        # verify that dates do not violate group's end date
        for date in generate_recurring_sitting_dates(
            start.date(), repeat, repeat_until, weekdays, monthly, exceptions):
            if group.end_date is not None and date > group.end_date:
                errors.append(Invalid(
                        _(u"One or more events would be scheduled for $F, which is "
                            "after the scheduling group's end date",
                            mapping={"F":datetimedict.fromdate(date)}),
                        "repeat" if repeat else "repeat_until"))
                break
            event_data = {
                "start_date": datetime.datetime(
                    date.year, date.month, date.day, start.hour, start.minute),
                "end_date": datetime.datetime(
                    date.year, date.month, date.day, end.hour, end.minute),
                }
            errors.extend(validate_non_overlapping_sitting(
                action, event_data, context, container,
                "weekdays" if weekdays else "monthly"))
            if errors:
                break
            errors.extend(validate_venues(
                action, data, context, container))
            if errors:
                break
    return logged_errors(errors, "validate_recurring_sittings")
Example #2
0
def validate_recurring_sittings(action, data, context, container):
    """Validate recurring sittings.

    This validator determines the sittings that will be created and
    confirms the validity of them.
    """

    start = data['start_date']
    end = data['end_date']
    weekdays = data.get('weekdays')
    monthly = data.get('monthly')
    repeat = data.get('repeat')
    repeat_until = data.get('repeat_until')
    exceptions = data.get('exceptions', ())

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

    errors = []

    if weekdays or monthly:
        # this should be an invariant, but due to formlib's requirement
        # that invariant methods pertain to a single schema, it's not
        # possible
        if repeat_until is not None and repeat_until < start.date():
            #session.close()
            return [
                interface.Interface(
                    _(u"If recurrence is limited by date, it "
                      "must lie after the starting date"), "repeat_until")
            ]

        # verify that dates do not violate group's end date
        for date in generate_recurring_sitting_dates(start.date(), repeat,
                                                     repeat_until, weekdays,
                                                     monthly, exceptions):
            if group.end_date is not None and date > group.end_date:
                errors.append(
                    interface.Invalid(
                        _(
                            u"One or more events would be scheduled for $F, which is "
                            "after the scheduling group's end date",
                            mapping={'F': datetimedict.fromdate(date)}),
                        "repeat" if repeat else "repeat_until",
                    ))
                break

            event_data = {
                'start_date':
                datetime.datetime(date.year, date.month, date.day, start.hour,
                                  start.minute),
                'end_date':
                datetime.datetime(date.year, date.month, date.day, end.hour,
                                  end.minute),
            }

            errors.extend(
                validate_non_overlapping_sitting(
                    action, event_data, context, container,
                    "weekdays" if weekdays else "monthly"))

            if errors:
                break

            errors.extend(validate_venues(action, data, context, container))

            if errors:
                break

    return errors