def same_group(model, identity):
    """ Returns True, if the given model is in the same user group/municipality
    as the given identy.

    """
    if hasattr(model, 'group_id'):
        if model.group_id and identity.groupid:
            return model.group_id.hex == identity.groupid
    elif hasattr(model, 'municipality_id'):
        if model.municipality_id and identity.groupid:
            return model.municipality_id.hex == identity.groupid
    return False