def get_locality_codes():
    """ Return a dictionary containing the valid locality codes.

        We return a dictionary mapping each locality code (in uppercase) to the
        Location record ID used for that locality code.  The locality code
        dictionary is automatically recalculated if it isn't in the cache.
    """
    locality_codes = dataCache.get("locality_codes")

    if locality_codes == None:
        locality_codes = {}
        for loc in Location.objects.filter(level=Location.LEVEL_LOCALITY):
            locality_codes[loc.code.upper()] = loc.id
        dataCache.set("locality_codes", locality_codes)

    return locality_codes
def get_zip_codes():
    """ Return a dictionary containing the valid zip codes.

        We return a dictionary mapping each zip code (in uppercase) to the
        Location record ID used for that zip code.  The zip code dictionary is
        automatically recalculated if it isn't in the cache.
    """
    zip_codes = dataCache.get("zip_codes")

    if zip_codes == None:
        zip_codes = {}
        for loc in Location.objects.filter(level=Location.LEVEL_ZIPCODE):
            zip_codes[loc.code.upper()] = loc.id
        dataCache.set("zip_codes", zip_codes)

    return zip_codes
def get_metro_codes():
    """ Return a dictionary containing the valid metro area codes.

        We return a dictionary mapping each metro area code (in uppercase) to
        the Location record ID used for that metro area code.  The metro area
        code dictionary is automatically recalculated if it isn't in the cache.
    """
    metro_codes = dataCache.get("metro_codes")

    if metro_codes == None:
        metro_codes = {}
        for loc in Location.objects.filter(level=Location.LEVEL_METRO):
            metro_codes[loc.code.upper()] = loc.id
        dataCache.set("metro_codes", metro_codes)

    return metro_codes
def get_region_codes():
    """ Return a dictionary containing the valid region codes.

        We return a dictionary mapping each region code (in uppercase) to the
        Location record ID used for that region code.  The region code
        dictionary is automatically recalculated if it isn't in the cache.
    """
    region_codes = dataCache.get("region_codes")

    if region_codes == None:
        region_codes = {}
        for loc in Location.objects.filter(level=Location.LEVEL_REGION):
            region_codes[loc.code.upper()] = loc.id
        dataCache.set("region_codes", region_codes)

    return region_codes
def get_state_codes():
    """ Return a dictionary containing the valid state codes.

        We return a dictionary mapping each state code (in uppercase) to the
        Location record ID used for that state code.  The state code dictionary
        is automatically recalculated if it isn't in the cache.
    """
    state_codes = dataCache.get("state_codes")

    if state_codes == None:
        state_codes = {}
        for loc in Location.objects.filter(level=Location.LEVEL_STATE):
            state_codes[loc.code.upper()] = loc.id
        dataCache.set("state_codes", state_codes)

    return state_codes
def get_country_codes():
    """ Return a dictionary containing the valid country codes.

        We return a dictionary mapping each country code (in uppercase) to the
        Location record ID used for that country code.  The country code
        dictionary is automatically recalculated if it isn't in the cache.
    """
    country_codes = dataCache.get("country_codes")

    if country_codes == None:
        country_codes = {}
        for loc in Location.objects.filter(level=Location.LEVEL_COUNTRY):
            country_codes[loc.code.upper()] = loc.id
        dataCache.set("country_codes", country_codes)

    return country_codes
def get_category_codes():
    """ Return a dictionary containing the valid category codes.

        We return a dictionary mapping each category code (in uppercase) to the
        Category record ID used for that category code.  The category code
        dictionary is automatically recalculated if it isn't in the cache.
    """
    category_codes = dataCache.get("category_codes")

    if category_codes == None:
        category_codes = {}
        for category in Category.objects.all():
            category_codes[category.code.upper()] = category.id
        dataCache.set("category_codes", category_codes)

    return category_codes
def get_source_codes():
    """ Return a dictionary containing the valid source codes.

        We return a dictionary mapping each source code (in uppercase) to the
        Source record ID used for that source code.  The source code dictionary
        is automatically recalculated if it isn't in the cache.
    """
    source_codes = dataCache.get("source_codes")

    if source_codes == None:
        source_codes = {}
        for source in Source.objects.all():
            source_codes[source.code.upper()] = source.id
        dataCache.set("source_codes", source_codes)

    return source_codes
def get_category_groups():
    """ Return dictionary mapping category code to category group record ID.

        We return a dictionary mapping each category code (in uppercase) to the
        CategoryGroup record ID used for that category code.  The category
        group dictionary is automatically recalculated if it isn't in the
        cache.
    """
    category_groups = dataCache.get("category_groups")

    if category_groups == None:
        category_groups = {}
        for category in Category.objects.all():
            category_groups[category.code.upper()] = category.group.id
        dataCache.set("category_groups", category_groups)

    return category_groups