def validate_party_membership(action, data, context, container):
    errors = []
    parent_id = getattr(container.__parent__, "parent_group_id", None)
    if interfaces.IPartyMember.providedBy(context):
        party_member = context
        user_id = context.user_id
    else:
        party_member = None
        user_id = data["user_id"]
    if data.get("start_date", None):
        for r in queries.validate_membership_in_interval(
            party_member, AllPartyMemberships, data["start_date"], user_id, parent_id=parent_id, with_parent=True
        ):
            overlaps = r.short_name
            errors.append(interface.Invalid(_("The person is a member in (%s) at that date") % overlaps, "start_date"))
    if data.get("end_date", None):
        for r in queries.validate_membership_in_interval(
            party_member, AllPartyMemberships, data["end_date"], user_id, parent_id=parent_id, with_parent=True
        ):
            overlaps = r.short_name
            errors.append(interface.Invalid(_("The person is a member in (%s) at that date") % overlaps, "end_date"))
    for r in queries.validate_open_membership(
        party_member, AllPartyMemberships, user_id, parent_id=parent_id, with_parent=True
    ):
        overlaps = r.short_name
        errors.append(interface.Invalid(_("The person is a member in (%s) at that date") % overlaps, "end_date"))
    return errors
def validate_group_membership_dates(action, data, context, container):
    """ A User must be member of a group only once at a time """
    errors = []
    group_id = container.__parent__.group_id
    if interfaces.IBungeniGroupMembership.providedBy(context):
        group_membership = context
    else:
        group_membership = None
    #!(murithi, apr-2011) VALIDATION - this may be improved
    user_id = data.get("user_id", None)
    if user_id is None:
        return errors
    session = Session()
    if data["start_date"]:
        for r in queries.validate_membership_in_interval(
            group_membership, domain.GroupMembership, data["start_date"], user_id, group_id
        ):
            overlaps = r.group.short_name
            errors.append(
                interface.Invalid(_("The person is a member in (%s) at that date") % overlaps, "start_date", "user_id")
            )
    if data["end_date"]:
        for r in queries.validate_membership_in_interval(
            group_membership, domain.GroupMembership, data["end_date"], user_id, group_id
        ):
            overlaps = r.group.short_name
            errors.append(
                interface.Invalid(_("The person is a member in (%s) at that date") % overlaps, "end_date", "user_id")
            )
    for r in queries.validate_open_membership(group_membership, domain.GroupMembership, user_id, group_id):
        overlaps = r.group.short_name
        errors.append(
            interface.Invalid(_("The person is a member in (%s) at that date") % overlaps, "end_date", "user_id")
        )
    return errors
Beispiel #3
0
def validate_political_group_membership(action, data, context, container):
    errors = []
    parent_id = getattr(container.__parent__, "parent_group_id", None)
    user_id = data.get("user_id")
    start_date = data.get("start_date")
    end_date = data.get("end_date")
    if interfaces.IPoliticalGroupMember.providedBy(context):
        political_group_member = context
        user_id = context.user_id
    else:
        political_group_member = None
    if start_date:
        for r in queries.validate_membership_in_interval(
                political_group_member,
                AllPoliticalGroupMemberships,
                start_date,
                user_id,
                parent_id=parent_id,
                with_parent=True):
            overlaps = r.short_name
            errors.append(
                Invalid(
                    _("The person is a member in (%s) at that date") %
                    overlaps, "start_date"))
    if end_date:
        for r in queries.validate_membership_in_interval(
                political_group_member,
                AllPoliticalGroupMemberships,
                end_date,
                user_id,
                parent_id=parent_id,
                with_parent=True):
            overlaps = r.short_name
            errors.append(
                Invalid(
                    _("The person is a member in (%s) at that date") %
                    overlaps, "end_date"))
    for r in queries.validate_open_membership(political_group_member,
                                              AllPoliticalGroupMemberships,
                                              user_id,
                                              parent_id=parent_id,
                                              with_parent=True):
        overlaps = r.short_name
        errors.append(
            Invalid(
                _("The person is a member in (%s) at that date") % overlaps,
                "end_date"))
    return logged_errors(errors, "validate_political_group_membership")
Beispiel #4
0
def validate_party_membership(action, data, context, container):
    errors = []
    parent_id = getattr(container.__parent__, 'parent_group_id', None)
    if interfaces.IPartyMember.providedBy(context):
        party_member = context
        user_id = context.user_id
    else:
        party_member = None
        user_id = data['user_id']
    if data.get('start_date', None):
        for r in queries.validate_membership_in_interval(party_member,
                                                         AllPartyMemberships,
                                                         data['start_date'],
                                                         user_id,
                                                         parent_id=parent_id,
                                                         with_parent=True):
            overlaps = r.short_name
            errors.append(
                interface.Invalid(
                    _("The person is a member in (%s) at that date") %
                    overlaps, "start_date"))
    if data.get('end_date', None):
        for r in queries.validate_membership_in_interval(party_member,
                                                         AllPartyMemberships,
                                                         data['end_date'],
                                                         user_id,
                                                         parent_id=parent_id,
                                                         with_parent=True):
            overlaps = r.short_name
            errors.append(
                interface.Invalid(
                    _("The person is a member in (%s) at that date") %
                    overlaps, "end_date"))
    for r in queries.validate_open_membership(party_member,
                                              AllPartyMemberships,
                                              user_id,
                                              parent_id=parent_id,
                                              with_parent=True):
        overlaps = r.short_name
        errors.append(
            interface.Invalid(
                _("The person is a member in (%s) at that date") % overlaps,
                "end_date"))
    return errors
Beispiel #5
0
def validate_group_membership_dates(action, data, context, container):
    """A User must be member of a group only once at a time.
    """
    group_id = container.__parent__.group_id
    user_id = data.get("user_id")
    start_date = data.get("start_date")
    end_date = data.get("end_date")
    # !+ADD actions means context is categorically None
    if interfaces.IBungeniGroupMembership.providedBy(context):
        group_membership = context
    else:
        group_membership = None
    #!+IMPROVE(murithi, apr-2011) VALIDATION
    if user_id is None:
        return []
    errors = []
    if start_date:
        for r in queries.validate_membership_in_interval(
                group_membership, domain.GroupMembership, start_date, user_id,
                group_id):
            overlaps = r.group.short_name
            errors.append(
                Invalid(
                    _("The person is a member in (%s) at that date") %
                    overlaps, "start_date", "user_id"))
    if end_date:
        for r in queries.validate_membership_in_interval(
                group_membership, domain.GroupMembership, end_date, user_id,
                group_id):
            overlaps = r.group.short_name
            errors.append(
                Invalid(
                    _("The person is a member in (%s) at that date") %
                    overlaps, "end_date", "user_id"))
    for r in queries.validate_open_membership(group_membership,
                                              domain.GroupMembership, user_id,
                                              group_id):
        overlaps = r.group.short_name
        errors.append(
            Invalid(
                _("The person is a member in (%s) at that date") % overlaps,
                "end_date", "user_id"))
    return logged_errors(errors, "validate_group_membership_dates")
def validate_political_group_membership(action, data, context, container):
    errors = []
    parent_id = getattr(container.__parent__, "parent_group_id", None)
    user_id = data.get("user_id")
    start_date = data.get("start_date")
    end_date = data.get("end_date")
    if interfaces.IPoliticalGroupMember.providedBy(context):
        political_group_member = context
        user_id = context.user_id
    else:
        political_group_member = None
    if start_date:
        for r in queries.validate_membership_in_interval(political_group_member, 
                    AllPoliticalGroupMemberships, 
                    start_date,
                    user_id,
                    parent_id=parent_id,
                    with_parent=True):
            overlaps = r.short_name
            errors.append(Invalid(
                    _("The person is a member in (%s) at that date") % overlaps, 
                    "start_date"))
    if end_date:
        for r in queries.validate_membership_in_interval(political_group_member, 
                    AllPoliticalGroupMemberships, 
                    end_date,
                    user_id,
                    parent_id=parent_id,
                    with_parent=True):
            overlaps = r.short_name
            errors.append(Invalid(
                    _("The person is a member in (%s) at that date") % overlaps, 
                    "end_date"))
    for r in queries.validate_open_membership(political_group_member, 
            AllPoliticalGroupMemberships, 
            user_id, 
            parent_id=parent_id, 
            with_parent=True):
        overlaps = r.short_name
        errors.append(Invalid(
                _("The person is a member in (%s) at that date") % overlaps, 
                "end_date")) 
    return logged_errors(errors, "validate_political_group_membership")
def validate_group_membership_dates(action, data, context, container):
    """A User must be member of a group only once at a time.
    """
    group_id = container.__parent__.group_id
    user_id = data.get("user_id")
    start_date = data.get("start_date")
    end_date = data.get("end_date")
    # !+ADD actions means context is categorically None 
    if interfaces.IBungeniGroupMembership.providedBy(context):
        group_membership = context
    else:
        group_membership = None
    #!+IMPROVE(murithi, apr-2011) VALIDATION
    if user_id is None:
        return []
    errors = []
    if start_date:
        for r in queries.validate_membership_in_interval(group_membership, 
                    domain.GroupMembership, 
                    start_date,
                    user_id, group_id):
            overlaps = r.group.short_name
            errors.append(Invalid(
                    _("The person is a member in (%s) at that date") % overlaps, 
                    "start_date", "user_id"))
    if end_date:
        for r in queries.validate_membership_in_interval(group_membership, 
                    domain.GroupMembership, 
                    end_date,
                    user_id, group_id):
            overlaps = r.group.short_name
            errors.append(Invalid(
                    _("The person is a member in (%s) at that date") % overlaps, 
                    "end_date", "user_id"))
    for r in queries.validate_open_membership(
        group_membership, domain.GroupMembership, user_id, group_id):
        overlaps = r.group.short_name
        errors.append(Invalid(
                    _("The person is a member in (%s) at that date") % overlaps, 
                    "end_date", "user_id"))
    return logged_errors(errors, "validate_group_membership_dates")
def validate_group_membership_dates(action, data, context, container):
    """ A User must be member of a group only once at a time """
    errors = []
    group_id = container.__parent__.group_id
    if interfaces.IBungeniGroupMembership.providedBy(context):
        group_membership = context
    else:
        group_membership = None
    #!(murithi, apr-2011) VALIDATION - this may be improved
    user_id = data.get('user_id', None)
    if user_id is None:
        return errors
    session = Session()
    if data['start_date']:
        for r in queries.validate_membership_in_interval(
                group_membership, domain.GroupMembership, data['start_date'],
                user_id, group_id):
            overlaps = r.group.short_name
            errors.append(
                interface.Invalid(
                    _("The person is a member in (%s) at that date") %
                    overlaps, "start_date", "user_id"))
    if data['end_date']:
        for r in queries.validate_membership_in_interval(
                group_membership, domain.GroupMembership, data['end_date'],
                user_id, group_id):
            overlaps = r.group.short_name
            errors.append(
                interface.Invalid(
                    _("The person is a member in (%s) at that date") %
                    overlaps, "end_date", "user_id"))
    for r in queries.validate_open_membership(group_membership,
                                              domain.GroupMembership, user_id,
                                              group_id):
        overlaps = r.group.short_name
        errors.append(
            interface.Invalid(
                _("The person is a member in (%s) at that date") % overlaps,
                "end_date", "user_id"))
    return errors
def validate_group_membership_dates(action, data, context, container):
    """ A User must be member of a group only once at a time """
    errors =[]
    group_id = container.__parent__.group_id
    if interfaces.IGroupMembership.providedBy(context):
        group_membership = context
    else:
        group_membership = None
    user_id = data['user_id']
    session = Session()
    if data['start_date']:
        for r in queries.validate_membership_in_interval(group_membership, 
                    domain.GroupMembership, 
                    data['start_date'],
                    user_id, group_id):
            overlaps = r.group.short_name
            errors.append(interface.Invalid(
                _("The person is a member in (%s) at that date") % overlaps, 
                "start_date", "user_id" ))
    if data['end_date']:
        for r in queries.validate_membership_in_interval(group_membership, 
                    domain.GroupMembership, 
                    data['end_date'],
                    user_id, group_id):
            overlaps = r.group.short_name
            errors.append(interface.Invalid(
                _("The person is a member in (%s) at that date") % overlaps, 
                "end_date", "user_id" ))
    for r in queries.validate_open_membership(group_membership, 
                domain.GroupMembership, 
                user_id, group_id):
        overlaps = r.group.short_name
        errors.append(interface.Invalid(
                    _("The person is a member in (%s) at that date") % overlaps, 
                    "end_date", "user_id" )) 
    return errors