'Returns a list containing ancestors of the requested feature.
If the caller already has the location row, including path and
parent fields, they can supply it via feature to avoid a db lookup.
If ids_only is false, each element in the list is a gluon.sql.Row
containing the gis_location record of an ancestor of the specified
location.
If ids_only is true, just returns a list of ids of the parents.
This avoids a db lookup for the parents if the specified feature
has a path.
List elements are in the opposite order as the location path and
exclude the specified location itself, i.e. element 0 is the parent
and the last element is the most distant ancestor.
Assists lazy update of a database without location paths by calling
update_location_tree to get the path.
Note that during prepopulate, update_location_tree is disabled,
in which case this will only return the immediate parent.'

@staticmethod
def get_parents(feature_id, feature=None, ids_only=False):

    if ((not feature) or ('path' not in feature) or ('parent' not in feature)):
        feature = GIS._lookup_parent_path(feature_id)
    if (feature and (feature.path or feature.parent)):
        if feature.path:
            path = feature.path
        else:
            path = GIS.update_location_tree(feature)
        if path:
            path_list = map(int, path.split('/'))
            if (len(path_list) == 1):
                return None
            path_list = path_list[:(-1)]
            path_list.reverse()
        elif feature.parent:
            path_list = [feature.parent]
        else:
            return None
        if ids_only:
            return path_list
        s3db = current.s3db
        table = s3db.gis_location
        query = table.id.belongs(path_list)
        fields = [table.id, table.name, table.level, table.lat, table.lon]
        unordered_parents = current.db(query).select(cache=s3db.cache, *fields)
        unordered_ids = [row.id for row in unordered_parents]
        parents = [unordered_parents[unordered_ids.index(path_id)] for path_id in path_list if (path_id in unordered_ids)]
        return parents
    else:
        return None
