def validate_parliament_dates(action, data, context, container):
    """Parliaments must not overlap."""
    errors = []
    if interfaces.IParliament.providedBy(context):
        parliament = context
    else:
        parliament = None
    results = queries.validate_date_in_interval(parliament, domain.Parliament, data["start_date"])
    for result in results:
        overlaps = result.short_name
        errors.append(interface.Invalid(_("The start date overlaps with (%s)") % overlaps, "start_date"))
    if data["end_date"]:
        results = queries.validate_date_in_interval(parliament, domain.Parliament, data["start_date"])
        for result in results:
            overlaps = result.short_name
            errors.append(interface.Invalid(_("The end date overlaps with (%s)") % overlaps, "end_date"))

    results = queries.validate_date_in_interval(parliament, domain.Parliament, data["election_date"])
    for result in results:
        overlaps = result.short_name
        errors.append(interface.Invalid(_("The election date overlaps with (%s)") % overlaps, "election_date"))

    if parliament is None:
        results = queries.validate_open_interval(parliament, domain.Parliament)
        for result in results:
            overlaps = result.short_name
            errors.append(
                interface.Invalid(_("Another parliament is not yet dissolved (%s)") % overlaps, "election_date")
            )

    return errors
Beispiel #2
0
def validate_chamber_dates(action, data, context, container):
    """Chambers start must be after start of the Legislature. 
    The start and end date of *chambers of same type* may not overlap.
    """
    errors = []
    start_date = data["start_date"]
    end_date = data.get("end_date")
    parliament_type = data["parliament_type"]
    if interfaces.IParliament.providedBy(context):
        chamber = context
    else:
        chamber = None

    # whether uni- or bicameral, chamber dates may NOT overlap with those of
    # another chamber of the SAME TYPE

    def get_others_overlapping_date(chamber, date):
        return [
            result for result in queries.validate_date_in_interval(
                chamber, domain.Parliament, date)
            if result.parliament_type == parliament_type
        ]

    legislature = capi.legislature
    if start_date:
        for res in get_others_overlapping_date(chamber, start_date):
            errors.append(
                Invalid(
                    _("Start date overlaps with (%s)") % res.short_name,
                    "start_date"))
        if start_date < legislature.start_date:
            errors.append(
                Invalid(
                    _("Start date preceeds legislature start (%s)") %
                    (legislature.start_date), "start_date"))

    if end_date:
        for res in get_others_overlapping_date(chamber, end_date):
            errors.append(
                Invalid(
                    _("End date overlaps with (%s)") % res.short_name,
                    "end_date"))
        if legislature.end_date:
            if end_date > legislature.end_date:
                errors.append(
                    Invalid(
                        _("End date later legislature end (%s)") %
                        (legislature.end_date), "end_date"))

    if chamber is None:
        results = queries.validate_open_interval(chamber, domain.Parliament)
        for result in results:
            if result.parliament_type == parliament_type:
                errors.append(
                    Invalid(
                        _("Another chamber is not yet dissolved (%s)") %
                        (result.short_name), "election_date"))

    return logged_errors(errors, "validate_chamber_dates")
Beispiel #3
0
def validate_chamber_dates(action, data, context, container):
    """Chambers start must be after start of the Legislature. 
    The start and end date of *chambers of same type* may not overlap.
    """
    errors = []
    start_date = data["start_date"]
    end_date = data.get("end_date")
    parliament_type = data["parliament_type"]
    if interfaces.IParliament.providedBy(context):
        chamber = context
    else:
        chamber = None
    
    # whether uni- or bicameral, chamber dates may NOT overlap with those of 
    # another chamber of the SAME TYPE
    
    def get_others_overlapping_date(chamber, date):
        return [ result for result in 
            queries.validate_date_in_interval(chamber, domain.Parliament, date)
            if result.parliament_type == parliament_type ]
    
    legislature = capi.legislature
    if start_date:
        for res in get_others_overlapping_date(chamber, start_date):
            errors.append(Invalid(
                    _("Start date overlaps with (%s)") % res.short_name, 
                    "start_date"))
        if start_date < legislature.start_date:
            errors.append(Invalid(
                    _("Start date preceeds legislature start (%s)") % (
                        legislature.start_date), 
                    "start_date"))
    
    if end_date:
        for res in get_others_overlapping_date(chamber, end_date):
            errors.append(
                Invalid(_("End date overlaps with (%s)") % res.short_name, 
                    "end_date"))
        if legislature.end_date:
            if end_date > legislature.end_date:
                errors.append(Invalid(
                        _("End date later legislature end (%s)") % (
                            legislature.end_date), 
                        "end_date"))
    
    if chamber is None:
        results = queries.validate_open_interval(chamber, domain.Parliament)
        for result in results:
            if result.parliament_type == parliament_type:
                errors.append(Invalid(
                        _("Another chamber is not yet dissolved (%s)") % (
                            result.short_name),
                        "election_date"))
    
    return logged_errors(errors, "validate_chamber_dates")
Beispiel #4
0
def validate_government_dates(action, data, context, container):
    errors = []
    start_date = data.get("start_date")
    end_date = data.get("end_date")
    if interfaces.IGovernment.providedBy(context):
        government = context
    else:
        government = None
    if container.__parent__.end_date is not None and start_date:
        if start_date > container.__parent__.end_date:
            errors.append(
                Invalid(
                    "%s %s" %
                    (_("Start date cannot be after the parliaments"
                       " dissolution"), container.__parent__.end_date),
                    "start_date"))
    if start_date and container.__parent__.start_date > start_date:
        errors.append(
            Invalid(
                "%s %s" %
                (_("Start date must start after the swearing in of the"
                   " parliament"), container.__parent__.start_date),
                "start_date"))
    if start_date:
        results = queries.validate_date_in_interval(government,
                                                    domain.Government,
                                                    start_date)
        for result in results:
            overlaps = result.short_name
            errors.append(
                Invalid(
                    _("The start date overlaps with (%s)") % overlaps,
                    "start_date"))
    if end_date:
        results = queries.validate_date_in_interval(government,
                                                    domain.Government,
                                                    end_date)
        for result in results:
            overlaps = result.short_name
            errors.append(
                Invalid(
                    _("The end date overlaps with (%s)") % overlaps,
                    "end_date"))
    if government is None:
        results = queries.validate_open_interval(government, domain.Government)
        for result in results:
            overlaps = result.short_name
            errors.append(
                Invalid(
                    _("Another government is not yet dissolved (%s)") %
                    overlaps, "start_date"))

    return logged_errors(errors, "validate_government_dates")
def validate_parliament_dates(action, data, context, container):
    """Parliaments must not overlap."""
    errors = []
    start_date = data.get("start_date")
    end_date = data.get("end_date")
    election_date = data.get("election_date")
    if interfaces.IParliament.providedBy(context):
        parliament = context
    else:
        parliament = None
    if start_date:
        results = queries.validate_date_in_interval(parliament,
                                                    domain.Parliament,
                                                    start_date)
        for result in results:
            overlaps = result.short_name
            errors.append(
                Invalid(
                    _("The start date overlaps with (%s)") % overlaps,
                    "start_date"))
    if end_date:
        results = queries.validate_date_in_interval(parliament,
                                                    domain.Parliament,
                                                    end_date)
        for result in results:
            overlaps = result.short_name
            errors.append(
                Invalid(
                    _("The end date overlaps with (%s)") % overlaps,
                    "end_date"))
    if election_date:
        results = queries.validate_date_in_interval(parliament,
                                                    domain.Parliament,
                                                    election_date)
        for result in results:
            overlaps = result.short_name
            errors.append(
                Invalid(
                    _("The election date overlaps with (%s)") % overlaps,
                    "election_date"))
    if parliament is None:
        results = queries.validate_open_interval(parliament, domain.Parliament)
        for result in results:
            overlaps = result.short_name
            errors.append(
                Invalid(
                    _("Another parliament is not yet dissolved (%s)") %
                    overlaps, "election_date"))
    return logged_errors(errors, "validate_parliament_dates")
Beispiel #6
0
def validate_government_dates(action, data, context, container):
    errors = []
    if interfaces.IGovernment.providedBy(context):
        government = context
    else:
        government = None

    if container.__parent__.end_date is not None:
        if data['start_date'] > container.__parent__.end_date:
            errors.append(
                interface.Invalid(
                    _("Start date cannot be after the parliaments dissolution (%s)"
                      ) % container.__parent__.end_date, "start_date"))
    if container.__parent__.start_date > data['start_date']:
        errors.append(
            interface.Invalid(
                _("Start date must start after the swearing in of the parliament (%s)"
                  ) % container.__parent__.start_date, "start_date"))
    results = queries.validate_date_in_interval(government, domain.Government,
                                                data['start_date'])
    for result in results:
        overlaps = result.short_name
        errors.append(
            interface.Invalid(
                _("The start date overlaps with (%s)") % overlaps,
                "start_date"))
    if data['end_date']:
        results = queries.validate_date_in_interval(government,
                                                    domain.Government,
                                                    data['start_date'])
        for result in results:
            overlaps = result.short_name
            errors.append(
                interface.Invalid(
                    _("The end date overlaps with (%s)") % overlaps,
                    "end_date"))

    if government is None:
        results = queries.validate_open_interval(government, domain.Government)
        for result in results:
            overlaps = result.short_name
            errors.append(
                interface.Invalid(
                    _("Another government is not yet dissolved (%s)") %
                    overlaps, "start_date"))

    return errors
def validate_government_dates(action, data, context, container):
    errors = []
    if interfaces.IGovernment.providedBy(context):
        government = context
    else:
        government = None
            
    if container.__parent__.end_date is not None:
        if data['start_date'] > container.__parent__.end_date:
            errors.append(  interface.Invalid(
                _("Start date cannot be after the parliaments dissolution (%s)") 
                % container.__parent__.end_date , 
                "start_date") )
    if container.__parent__.start_date > data['start_date']:
        errors.append( interface.Invalid(
            _("Start date must start after the swearing in of the parliament (%s)") 
            % container.__parent__.start_date , 
            "start_date") )
    results = queries.validate_date_in_interval(government, 
                    domain.Government, 
                    data['start_date'])
    for result in results:
        overlaps = result.short_name
        errors.append(interface.Invalid(
            _("The start date overlaps with (%s)") % overlaps, 
            "start_date"))
    if data['end_date']:
        results = queries.validate_date_in_interval(government, 
                    domain.Government, 
                    data['start_date'])
        for result in results:
            overlaps = result.short_name
            errors.append(interface.Invalid(
                _("The end date overlaps with (%s)") % overlaps, 
                "end_date"))

    if government is None:
        results = queries.validate_open_interval(government, domain.Government)
        for result in results:
            overlaps = result.short_name
            errors.append(interface.Invalid(
                _("Another government is not yet dissolved (%s)") % overlaps,
                "start_date"))
        
    return errors
def validate_government_dates(action, data, context, container):
    errors = []
    start_date = data.get("start_date")
    end_date = data.get("end_date")
    if interfaces.IGovernment.providedBy(context):
        government = context
    else:
        government = None
    if container.__parent__.end_date is not None and start_date:
        if start_date > container.__parent__.end_date:
            errors.append(Invalid(
                    "%s %s" % (_("Start date cannot be after the parliaments"
                            " dissolution"), container.__parent__.end_date), 
                    "start_date"))
    if start_date and container.__parent__.start_date > start_date:
        errors.append(Invalid(
                "%s %s" % (
                    _("Start date must start after the swearing in of the"
                        " parliament"), container.__parent__.start_date), 
                "start_date"))
    if start_date:
        results = queries.validate_date_in_interval(government, 
            domain.Government, start_date)
        for result in results:
            overlaps = result.short_name
            errors.append(Invalid(
                    _("The start date overlaps with (%s)") % overlaps, 
                    "start_date"))
    if end_date:
        results = queries.validate_date_in_interval(government, 
                    domain.Government, end_date)
        for result in results:
            overlaps = result.short_name
            errors.append(Invalid(
                    _("The end date overlaps with (%s)") % overlaps, 
                    "end_date"))
    if government is None:
        results = queries.validate_open_interval(government, domain.Government)
        for result in results:
            overlaps = result.short_name
            errors.append(Invalid(
                    _("Another government is not yet dissolved (%s)") % overlaps,
                    "start_date"))
        
    return logged_errors(errors, "validate_government_dates")