'Returns country code or L0 location id versus name for all countries.
The lookup is cached in the session
If key_type is "code", these are returned as an OrderedDict with
country code as the key.  If key_type is "id", then the location id
is the key.  In all cases, the value is the name.'

@staticmethod
def get_countries(key_type='id'):

    session = current.session
    if ('gis' not in session):
        session.gis = Storage()
    gis = session.gis
    if gis.countries_by_id:
        cached = True
    else:
        cached = False
    if (not cached):
        s3db = current.s3db
        table = s3db.gis_location
        ttable = s3db.gis_location_tag
        query = (((table.level == 'L0') & (ttable.tag == 'ISO2')) & (ttable.location_id == table.id))
        countries = current.db(query).select(table.id, table.name, ttable.value, orderby=table.name)
        if (not countries):
            return []
        countries_by_id = OrderedDict()
        countries_by_code = OrderedDict()
        for row in countries:
            location = row['gis_location']
            countries_by_id[location.id] = location.name
            countries_by_code[row['gis_location_tag'].value] = location.name
        gis.countries_by_id = countries_by_id
        gis.countries_by_code = countries_by_code
        if (key_type == 'id'):
            return countries_by_id
        else:
            return countries_by_code
    elif (key_type == 'id'):
        return gis.countries_by_id
    else:
        return gis.countries_by_code
