def configure_geoserver(self):
        """
        Configure all the components in Geoserver. This method configures the
        geoserver workspace, datastore, feature types, and styles. All 
        configuration steps get processed through the REST config.

        @returns: A flag indicating if geoserver was configured correctly.
        """
        try:
            srid = Geounit.objects.all()[0].geom.srid
        except:
            srid = 0
            logger.debug('Spatial Reference could not be determined, defaulting to %d', srid)

        # Create our namespace
        namespace_url = '/geoserver/rest/namespaces'
        namespace_obj = { 'namespace': { 'prefix': self.ns, 'uri': self.nshref } }
        if self._check_spatial_resource(namespace_url, self.ns, namespace_obj):
            logger.debug('Created namespace "%s"' % self.ns)
        else:
            logger.warn('Could not create Namespace')
            return

        # Create our DataStore
        if self.store is None:
            logger.warning('Geoserver cannot be fully configured without a stored config.')
            return

        dbconfig = self.store.get_database()

        data_store_url = '/geoserver/rest/workspaces/%s/datastores' % self.ns
        data_store_name = 'PostGIS'

        data_store_obj = {
            'dataStore': {
                'name': data_store_name,
                'connectionParameters': {
                    'host': dbconfig.get('host',self.host),
                    'port': 5432,
                    'database': dbconfig.get('name'),
                    'user': dbconfig.get('user'),
                    'passwd': dbconfig.get('password'),
                    'dbtype': 'postgis',
                    'namespace': self.ns,
                    'schema': dbconfig.get('user')
                }
            }
        }

        if self._check_spatial_resource(data_store_url, data_store_name, data_store_obj):
            logger.debug('Created datastore "%s"' % data_store_name)
        else:
            logger.warn('Could not create Datastore')
            return

        # Create the feature types and their styles

        if self.create_featuretype('identify_geounit'):
            logger.debug('Created feature type "identify_geounit"')
        else:
            logger.warn('Could not create "identify_geounit" feature type')

        for geolevel in Geolevel.objects.all():
            if geolevel.legislativelevel_set.all().count() == 0:
                # Skip 'abstract' geolevels if regions are configured
                continue
            
            if self.create_featuretype('simple_%s' % geolevel.name):
                logger.debug('Created "simple_%s" feature type' % geolevel.name)
            else:
                logger.warn('Could not create "simple_%s" feature type' % geolevel.name)

            if self.create_featuretype('simple_district_%s' % geolevel.name):
                logger.debug('Created "simple_district_%s" feature type' % geolevel.name)
            else:
                logger.warn('Colud not create "simple_district_%s" feature type' % geolevel.name)

            all_subjects = Subject.objects.all().order_by('sort_key') 
            if all_subjects.count() > 0:
                subject = all_subjects[0]

                # Create NONE demographic layer, based on first subject
                featuretype_name = get_featuretype_name(geolevel.name)
                if self.create_featuretype(featuretype_name, alias=get_featuretype_name(geolevel.name, subject.name)):
                    logger.debug('Created "%s" feature type' % featuretype_name)
                else:
                    logger.warn('Could not create "%s" feature type' % featuretype_name)

                if self.create_style(featuretype_name):
                    logger.debug('Created "%s" style' % featuretype_name)
                else:
                    logger.warn('Could not create style for "%s"' % featuretype_name)

                try:
                    sld_content = SpatialUtils.generate_style(geolevel, geolevel.geounit_set.all(), 1, layername='none')

                    self.write_style(geolevel.name + '_none', sld_content)
                except Exception, ex:
                    logger.error(traceback.format_exc())


                if self.set_style(featuretype_name, sld_content):
                    logger.debug('Set "%s" style' % featuretype_name)
                else:
                    logger.warn('Could not set "%s" style' % featuretype_name)

                if self.assign_style(featuretype_name, featuretype_name):
                    logger.debug('Assigned style for "%s"' % featuretype_name)
                else:
                    logger.warn('Could not assign style for "%s"' % featuretype_name)

                # Create boundary layer, based on geographic boundaries
                featuretype_name = '%s_boundaries' % geolevel.name
                if self.create_featuretype(featuretype_name, alias=get_featuretype_name(geolevel.name, subject.name)):
                    logger.debug('Created "%s" feature type' % featuretype_name)
                else:
                    logger.warn('Could not create "%s" feature type' % featuretype_name)

                if self.create_style(featuretype_name):
                    logger.debug('Created "%s" style' % featuretype_name)
                else:
                    logger.warn('Could not create "%s" style' % featuretype_name)

                try:
                    sld_content = SpatialUtils.generate_style(geolevel, geolevel.geounit_set.all(), 1, layername='boundary')

                    self.write_style(geolevel.name + '_boundaries', sld_content)
                except Exception, ex:
                    logger.error(traceback.format_exc())

                if self.set_style(featuretype_name, sld_content):
                    logger.debug(featuretype_name % 'Set "%s" style')
                else:
                    logger.warn('Could not set "%s" style' % featuretype_name)

                if self.assign_style(featuretype_name, featuretype_name):
                    logger.debug('Assigned style for "%s"' % featuretype_name)
                else:
                    logger.warn('Could not assign style for "%s"' % featuretype_name)
            
            for subject in all_subjects:
                featuretype_name = get_featuretype_name(geolevel.name, subject.name)

                if self.create_featuretype(featuretype_name):
                    logger.debug('Created "%s" feature type' % featuretype_name)
                else:
                    logger.warn('Could not create "%s" feature type' % featuretype_name)

                if self.create_style(featuretype_name):
                    logger.debug('Created "%s" style' % featuretype_name)
                else:
                    logger.warn('Could not create "%s" style' % featuretype_name)

                try:
                    sld_content = SpatialUtils.generate_style(geolevel, geolevel.geounit_set.all(), 5, subject=subject)

                    self.write_style(geolevel.name + '_' + subject.name, sld_content)
                except Exception, ex:
                    logger.error(traceback.format_exc())

                if self.set_style(featuretype_name, sld_content):
                    logger.debug('Set "%s" style' % featuretype_name)
                else:
                    logger.warn('Could not set "%s" style' % featuretype_name)

                if self.assign_style(featuretype_name, featuretype_name):
                    logger.debug('Assigned "%s" style' % featuretype_name)
                else:
                    logger.warn('Could not assign "%s" style' % featuretype_name)
            
        # map all the legislative body / geolevels combos
        ngeolevels_map = []
        for lbody in LegislativeBody.objects.all():
            geolevels = lbody.get_geolevels()
            # list by # of geolevels, and the first geolevel
            ngeolevels_map.append((len(geolevels), lbody, geolevels[0],))
        # sorf by the # of geolevels
        ngeolevels_map.sort(lambda x,y:cmp(y[0],x[0]))

        # get the first (most # of geolevels)
        lbody = ngeolevels_map[0][1]
        geolevel = ngeolevels_map[0][2]

        # create simple_district as an alias to the largest geolevel (e.g. counties)
        if self.create_featuretype('simple_district', alias='simple_district_%s' % geolevel.name):
            logger.debug('Created "simple_district" feature type')
        else:
            logger.warn('Could not create "simple_district" feature type')

        if self.assign_style('simple_district', 'polygon'):
            logger.debug('Assigned style "polygon" to feature type')
        else:
            logger.warn('Could not assign "polygon" style to simple_district')

        try:
            # add the district intervals
            intervals = self.store.filter_nodes('//ScoreFunction[@calculator="publicmapping.redistricting.calculators.Interval"]')
            for interval in intervals:
                subject_name = interval.xpath('SubjectArgument')[0].get('ref')
                lbody_name = interval.xpath('LegislativeBody')[0].get('ref')
                interval_avg = float(interval.xpath('Argument[@name="target"]')[0].get('value'))
                interval_bnd1 = float(interval.xpath('Argument[@name="bound1"]')[0].get('value'))
                interval_bnd2 = float(interval.xpath('Argument[@name="bound2"]')[0].get('value'))

                intervals = [
                    (interval_avg + interval_avg * interval_bnd2, None, 
                        _('Far Over Target'), {'fill':'#ebb95e', 'fill-opacity':'0.3'}),
                    (interval_avg + interval_avg * interval_bnd1, interval_avg + interval_avg * interval_bnd2, 
                        _('Over Target'), {'fill':'#ead3a7', 'fill-opacity':'0.3'}),
                    (interval_avg - interval_avg * interval_bnd1, interval_avg + interval_avg * interval_bnd1, 
                        _('Meets Target'), {'fill':'#eeeeee', 'fill-opacity':'0.1'}),
                    (interval_avg - interval_avg * interval_bnd2, interval_avg - interval_avg * interval_bnd1,
                        _('Under Target'), {'fill':'#a2d5d0', 'fill-opacity':'0.3'}),
                    (None, interval_avg - interval_avg * interval_bnd2,
                        _('Far Under Target'), {'fill':'#0aac98', 'fill-opacity':'0.3'})]

                doc = sld.StyledLayerDescriptor()
                fts = doc.create_namedlayer(subject_name).create_userstyle().create_featuretypestyle()

                for interval in intervals:
                    imin, imax, ititle, ifill = interval
                    rule = fts.create_rule(ititle, sld.PolygonSymbolizer)
                    if imin is None:
                        rule.create_filter('number', '<', str(int(round(imax))))
                    elif imax is None:
                        rule.create_filter('number', '>=', str(int(round(imin))))
                    else:
                        f1 = sld.Filter(rule)
                        f1.PropertyIsGreaterThanOrEqualTo = sld.PropertyCriterion(f1, 'PropertyIsGreaterThanOrEqualTo')
                        f1.PropertyIsGreaterThanOrEqualTo.PropertyName = 'number'
                        f1.PropertyIsGreaterThanOrEqualTo.Literal = str(int(round(imin)))

                        f2 = sld.Filter(rule)
                        f2.PropertyIsLessThan = sld.PropertyCriterion(f2, 'PropertyIsLessThan')
                        f2.PropertyIsLessThan.PropertyName = 'number'
                        f2.PropertyIsLessThan.Literal = str(int(round(imax)))

                        rule.Filter = f1 + f2

                    ps = rule.PolygonSymbolizer
                    ps.Fill.CssParameters[0].Value = ifill['fill']
                    ps.Fill.create_cssparameter('fill-opacity', ifill['fill-opacity'])
                    ps.Stroke.CssParameters[0].Value = '#fdb913'
                    ps.Stroke.CssParameters[1].Value = '2'
                    ps.Stroke.create_cssparameter('stroke-opacity', '1')

                self.write_style(lbody_name + '_' + subject_name, doc.as_sld(pretty_print=True))

        except Exception, ex:
            logger.debug(traceback.format_exc())
            logger.warn('LegislativeBody intervals are not configured.')

        logger.info("Geoserver configuration complete.")

        # finished configure_geoserver
        return True
dataset/ETHPy150Open PublicMapping/DistrictBuilder/django/publicmapping/redistricting/config.py/SpatialUtils.configure_geoserver/swapped operands of `%`