Ejemplo n.º 1
0
class PlacetypeResource(BuiltFormResource):
    placetype_component_percent_query = lambda bundle: bundle.obj.placetypecomponentpercent_set.all(
    )

    def add_placetype_component_percents(bundle,
                                         *placetype_component_percents):
        for placetype_component_percent in placetype_component_percents:
            placetype_component_percent.placetype = bundle.obj
            placetype_component_percent.save()

    def remove_placetype_component_percents(bundle,
                                            *placetype_component_percents):
        for placetype_component_percent in placetype_component_percents:
            placetype_component_percent.delete()

    placetype_component_percents = ToManyCustomAddField(
        PlacetypeComponentPercentResource,
        attribute=placetype_component_percent_query,
        add=add_placetype_component_percents,
        remove=remove_placetype_component_percents,
        full=True,
        null=True)

    class Meta(FootprintResource.Meta):
        always_return_data = True
        queryset = Placetype.objects.filter(deleted=False)
        resource_name = 'placetype'
Ejemplo n.º 2
0
class PlacetypeComponentResource(BuiltFormResource):

    component_category = fields.ToOneField(PlacetypeComponentCategoryResource,
                                           attribute='component_category')

    # The readonly through instances that show what primary components this placetype component contains and at what percent
    primary_component_percent_query = lambda bundle: bundle.obj.primarycomponentpercent_set.all(
    )

    def add_primary_component_percents(bundle, *primary_component_percents):
        for primary_component_percent in primary_component_percents:
            primary_component_percent.placetype_component = bundle.obj
            primary_component_percent.save()

    def remove_primary_component_percents(bundle, *primary_component_percents):
        for primary_component_percent in primary_component_percents:
            primary_component_percent.delete()

    primary_component_percents = ToManyCustomAddField(
        PrimaryComponentPercentResource,
        attribute=primary_component_percent_query,
        add=add_primary_component_percents,
        remove=remove_primary_component_percents,
        full=True,
        null=True)

    # The readonly through instances that show what placetypes contain this placetype component and at what percent
    placetype_component_percent_query = lambda bundle: bundle.obj.placetypecomponentpercent_set.all(
    )
    placetype_component_percent_set = fields.ToManyField(
        'footprint.main.resources.built_form_resources.PlacetypeComponentPercentResource',
        attribute=placetype_component_percent_query,
        full=True,
        null=True,
        readonly=True)

    class Meta(FootprintResource.Meta):
        always_return_data = True
        queryset = PlacetypeComponent.objects.filter(deleted=False)
        resource_name = 'placetype_component'
Ejemplo n.º 3
0
class BuildingAttributeSetResource(FootprintResource):

    building_use_percents_query = lambda bundle: bundle.obj.buildingusepercent_set.all(
    )

    def hydrate_m2m(self, bundle):
        for building_use_percent in bundle.data['building_use_percents']:
            # Fill in the backreference to building_attribute_set for this nested instance
            # TODO there must be a better to handle this
            # One option is to just not set the foreign_key on the client, since it becomes 0, and then set it belowing in add_builidng_use_percents
            building_use_percent[
                'building_attribute_set'] = building_use_percent[
                    'building_attribute_set'].replace('/0/',
                                                      '/%s/' % bundle.obj.id)
        return super(BuildingAttributeSetResource, self).hydrate_m2m(bundle)

    def add_building_use_percents(bundle, *building_use_percents):
        # Save the instances explicitly since they are based on the set query
        for building_use_percent in building_use_percents:
            building_use_percent.save()

    def remove_building_use_percents(bundle, *building_use_percents):
        for building_use_percent in building_use_percents:
            building_use_percent.delete()

    # The BuildingUsePercents
    building_use_percents = ToManyCustomAddField(
        BuildingUsePercentResource,
        attribute=building_use_percents_query,
        add=add_building_use_percents,
        remove=remove_building_use_percents,
        full=True,
        null=True)

    class Meta(FootprintResource.Meta):
        always_return_data = True
        queryset = BuildingAttributeSet.objects.all()
        resource_name = 'building_attribute_set'
Ejemplo n.º 4
0
class EnvironmentalConstraintUpdaterToolResource(AnalysisToolResource):
    def add_environmental_constraint_percents(
            bundle, *environmental_constraint_percents):
        for environmental_constraint_percent in environmental_constraint_percents:
            environmental_constraint_percent.save()

    def remove_environmental_constraint_percents(
            bundle, *environmental_constraint_percents):
        for environmental_constraint_percent in environmental_constraint_percents:
            environmental_constraint_percent.delete()

    environmental_constraint_percent_query = lambda bundle: bundle.obj.environmentalconstraintpercent_set.all(
    )
    environmental_constraint_percents = ToManyCustomAddField(
        'footprint.main.resources.environmental_constraint_resources.EnvironmentalConstraintPercentResource',
        attribute=environmental_constraint_percent_query,
        add=add_environmental_constraint_percents,
        remove=add_environmental_constraint_percents,
        full=True,
        null=True)

    class Meta(AnalysisToolResource.Meta):
        queryset = EnvironmentalConstraintUpdaterTool.objects.all()
        resource_name = 'environmental_constraint_updater_tool'