def test_eco_not_wanted(self): RainGarden.set_config_property(self.instance, 'should_show_eco', False) drainage_area_sq_meters = 100000000.0 feature = self._make_map_feature(RainGarden, drainage_area=drainage_area_sq_meters) runoff_reduced = self._get_runoff_reduced(feature, expect_empty=True) self.assertEqual(runoff_reduced, 0)
def test_rain_garden(self): RainGarden.set_config_property(self.instance, 'should_show_eco', True) drainage_area_sq_meters = 100000000.0 feature = self._make_map_feature(RainGarden, drainage_area_sq_meters) runoff_reduced = self._get_runoff_reduced(feature) self._assert_runoff_reduced( self.polygon_area_sq_meters, drainage_area_sq_meters, .85, runoff_reduced)
def test_rain_garden(self): RainGarden.set_config_property(self.instance, 'should_show_eco', True) drainage_area_sq_meters = 100000000.0 feature = self._make_map_feature(RainGarden, drainage_area_sq_meters) runoff_reduced = self._get_runoff_reduced(feature) self._assert_runoff_reduced(self.polygon_area_sq_meters, drainage_area_sq_meters, .85, runoff_reduced)
def units(request, instance): """ Build context for "Units" tab, which allows specifying units and number of decimal digits for values like plot.width or eco.stormwater. For each such value we build a "field spec" for "units" and for "digits", which drive the creation of display/edit fields on the tab form. """ value_names = [ {'title': _("Planting Site Fields"), 'category_name': 'plot', 'model': Plot, 'value_names': ['width', 'length']}, {'title': _("Tree Fields"), 'category_name': 'tree', 'model': Tree, 'value_names': ['diameter', 'height', 'canopy_height']}, {'title': _("Eco Benefits"), 'category_name': 'eco', 'label_dict': benefit_labels, 'value_names': BenefitCategory.GROUPS}, {'title': _("{bioswale} Fields") .format(bioswale=Bioswale.display_name(instance)), 'category_name': 'bioswale', 'model': Bioswale, 'value_names': ['drainage_area']}, {'title': _("{rainBarrel} Fields") .format(rainBarrel=RainBarrel.display_name(instance)), 'category_name': 'rainBarrel', 'model': RainBarrel, 'value_names': ['capacity']}, {'title': _("{rainGarden} Fields") .format(rainGarden=RainGarden.display_name(instance)), 'category_name': 'rainGarden', 'model': RainGarden, 'value_names': ['drainage_area']}, {'title': _("Green Infrastructure"), 'category_name': 'greenInfrastructure', 'inclusion_test': lambda: instance.feature_enabled('green_infrastructure'), 'label_dict': { GreenInfrastructureCategory.RAINFALL: _('Annual Rainfall'), GreenInfrastructureCategory.AREA: _('Area') }, 'value_names': GreenInfrastructureCategory.GROUPS}, ] def get_label_getter(attrs): inclusion_test = attrs.get('inclusion_test') if inclusion_test: if not inclusion_test(): return None Model = attrs.get('model') if Model: name = Model.__name__ if name == 'Tree' or name in instance.map_feature_types: return lambda value_name: \ Model._meta.get_field(value_name).verbose_name else: label_dict = attrs.get('label_dict') if label_dict: return label_dict.get return None specs_by_category = [] for attrs in value_names: get_label = get_label_getter(attrs) if not get_label: continue category_name = attrs['category_name'] category_specs = [] for value_name in attrs['value_names']: def identifier_and_value(key): return get_value_display_attr( instance, category_name, value_name, key) label = get_label(value_name) # Make a dropdown choice for each unit we can convert to abbrevs = get_convertible_units(category_name, value_name) choices = [{'value': abbrev, 'display_value': get_unit_name(abbrev)} for abbrev in abbrevs] # Make field spec for units identifier, abbrev = identifier_and_value('units') units_field_spec = { 'identifier': identifier, 'value': abbrev, 'display_value': get_unit_name(abbrev), 'data_type': 'choice', 'choices': choices } # Make field spec for number of decimal digits identifier, value = identifier_and_value('digits') digits_field_spec = { 'identifier': identifier, 'value': value, 'display_value': value } category_specs.append({ 'label': label, 'units': units_field_spec, 'digits': digits_field_spec}) if category_specs: specs_by_category.append({'title': attrs['title'], 'items': category_specs}) return {'value_specs': specs_by_category}
def units(request, instance): """ Build context for "Units" tab, which allows specifying units and number of decimal digits for values like plot.width or eco.stormwater. For each such value we build a "field spec" for "units" and for "digits", which drive the creation of display/edit fields on the tab form. """ value_names = [ { 'title': _("Planting Site Fields"), 'category_name': 'plot', 'model': Plot, 'value_names': ['width', 'length'] }, { 'title': _("Tree Fields"), 'category_name': 'tree', 'model': Tree, 'value_names': ['diameter', 'height', 'canopy_height'] }, { 'title': _("Eco Benefits"), 'category_name': 'eco', 'label_dict': benefit_labels, 'value_names': BenefitCategory.GROUPS }, { 'title': _("{bioswale} Fields").format( bioswale=Bioswale.display_name(instance)), 'category_name': 'bioswale', 'model': Bioswale, 'value_names': ['drainage_area'] }, { 'title': _("{rainBarrel} Fields").format( rainBarrel=RainBarrel.display_name(instance)), 'category_name': 'rainBarrel', 'model': RainBarrel, 'value_names': ['capacity'] }, { 'title': _("{rainGarden} Fields").format( rainGarden=RainGarden.display_name(instance)), 'category_name': 'rainGarden', 'model': RainGarden, 'value_names': ['drainage_area'] }, { 'title': _("Green Infrastructure"), 'category_name': 'greenInfrastructure', 'inclusion_test': lambda: instance.feature_enabled('green_infrastructure'), 'label_dict': { GreenInfrastructureCategory.RAINFALL: _('Annual Rainfall'), GreenInfrastructureCategory.AREA: _('Area') }, 'value_names': GreenInfrastructureCategory.GROUPS }, ] def get_label_getter(attrs): inclusion_test = attrs.get('inclusion_test') if inclusion_test: if not inclusion_test(): return None Model = attrs.get('model') if Model: name = Model.__name__ if name == 'Tree' or name in instance.map_feature_types: return lambda value_name: \ Model._meta.get_field(value_name).verbose_name else: label_dict = attrs.get('label_dict') if label_dict: return label_dict.get return None specs_by_category = [] for attrs in value_names: get_label = get_label_getter(attrs) if not get_label: continue category_name = attrs['category_name'] category_specs = [] for value_name in attrs['value_names']: def identifier_and_value(key): return get_value_display_attr(instance, category_name, value_name, key) label = get_label(value_name) # Make a dropdown choice for each unit we can convert to abbrevs = get_convertible_units(category_name, value_name) choices = [{ 'value': abbrev, 'display_value': get_unit_name(abbrev) } for abbrev in abbrevs] # Make field spec for units identifier, abbrev = identifier_and_value('units') units_field_spec = { 'identifier': identifier, 'value': abbrev, 'display_value': get_unit_name(abbrev), 'data_type': 'choice', 'choices': choices } # Make field spec for number of decimal digits identifier, value = identifier_and_value('digits') digits_field_spec = { 'identifier': identifier, 'value': value, 'display_value': value } category_specs.append({ 'label': label, 'units': units_field_spec, 'digits': digits_field_spec }) if category_specs: specs_by_category.append({ 'title': attrs['title'], 'items': category_specs }) return {'value_specs': specs_by_category}