def import_regional_geolevels(self, force):
        """
        Map geolevels to regions.

        @param force: Should the Regional GeoLevel settings be written if the model already exist?
        @returns: A flag indicating if the import was successful.
        """
        regions = self.store.filter_regions()
        for region in regions:
            regional_geolevels = self.store.filter_regional_geolevel(region)

            # Get the zoom level of the largest geolevel (last one in the regional_geolevels list)
            zero_geolevel_config = self.store.get_geolevel(regional_geolevels[len(regional_geolevels)-1].get('ref'))
            # store this zoom level, and use it as an offset for the geolevels in this region
            zero_zoom = int(zero_geolevel_config.get('min_zoom'))

            for geolevel in regional_geolevels:
                try:
                    geolevel_obj = Geolevel.objects.get(name=geolevel.get('ref'))
                except:
                    logger.debug("Base geolevel %s for %s not found in the database.  Import base geolevels before regional geolevels", name, region.get('name'))
                    return

                attributes = {
                    'name': '%s_%s' % (region.get('name'), geolevel.get('ref')),
                    'min_zoom': geolevel_obj.min_zoom - zero_zoom,
                    'tolerance': geolevel_obj.tolerance
                }
                obj, created, changed, message = check_and_update(Geolevel, overwrite=force, **attributes)

                for locale in [l[0] for l in settings.LANGUAGES]:
                    po = self.poutils[locale]
                    po.add_or_update(
                        msgid=u'%s short label' % attributes['name'],
                        msgstr=geolevel.get('name') or '',
                        occurs=[(os.path.abspath(self.store.datafile), geolevel.sourceline,)]
                    )
                    po.add_or_update(
                        msgid=u'%s label' % attributes['name'],
                        msgstr=geolevel.get('label') or '',
                        occurs=[(os.path.abspath(self.store.datafile), geolevel.sourceline,)]
                    )
                    po.add_or_update(
                        msgid=u'%s long description' % attributes['name'],
                        msgstr='',
                        occurs=[(os.path.abspath(self.store.datafile), geolevel.sourceline,)]
                    )

                if changed and not force:
                    logger.info(message)
                else:
                    logger.debug(message)


        # Use the Region nodes to link bodies and geolevels
        for region in regions:

            # Map the imported geolevel to a legislative body
            lbodies = self.store.filter_regional_legislative_bodies(region)
            for lbody in lbodies:
                legislative_body = LegislativeBody.objects.get(name=lbody.get('ref')[:256])
                
                # Add a mapping for the subjects in this GL/LB combo.
                sconfig = self.store.get_legislative_body_default_subject(lbody)
                if not sconfig.get('aliasfor') is None:
                    # dereference any subject alias
                    sconfig = self.store.get_subject(sconfig.get('aliasfor'))
                subject = Subject.objects.get(name=sconfig.get('id').lower()[:50])

                def add_legislative_level_for_geolevel(node, body, subject, parent):
                    """
                    Helper method to recursively add LegislativeLevel mappings from Region configs
                    """
                    geolevel_node = self.store.get_geolevel(node.get('ref'))
                    geolevel_name = "%s_%s" % (region.get('id'), geolevel_node.get('id'))
                    geolevel = Geolevel.objects.get(name=geolevel_name)
                    obj, created = LegislativeLevel.objects.get_or_create(
                        legislative_body=body,
                        geolevel=geolevel,
                        subject=subject, 
                        parent=parent)

                    if created:
                        logger.debug('Created LegislativeBody/GeoLevel mapping "%s/%s"', legislative_body.name, geolevel.name)
                    else:
                        logger.debug('LegislativeBody/GeoLevel mapping "%s/%s" already exists', legislative_body.name, geolevel.name)

                    if len(node) > 0:
                        add_legislative_level_for_geolevel(node[0], body, subject, obj)

                parentless = self.store.get_top_regional_geolevel(region)
                if parentless is not None:
                    add_legislative_level_for_geolevel(parentless, legislative_body, subject, None)

        return True
dataset/ETHPy150Open PublicMapping/DistrictBuilder/django/publicmapping/redistricting/config.py/ConfigImporter.import_regional_geolevels/original