Ejemplo n.º 1
0
class BehaviorResource(FootprintResource):
    parents = ToManyField('self', attribute='parents', null=False)
    intersection = ToOneFieldWithSubclasses(
        IntersectionResource, attribute='intersection_subclassed', null=True)

    class Meta(FootprintResource.Meta):
        queryset = Behavior.objects.filter(deleted=False)
Ejemplo n.º 2
0
class FeatureBehaviorResource(FootprintResource):
    behavior = ToOneField(BehaviorResource, attribute='behavior', null=False)
    db_entity = ToOneField('footprint.main.resources.db_entity_resources.DbEntityResource', attribute='db_entity', null=True, readonly=True)
    intersection = ToOneFieldWithSubclasses(IntersectionResource, attribute='intersection_subclassed', null=True)

    class Meta(FootprintResource.Meta):
        queryset = FeatureBehavior.objects.filter(is_template=False)
        resource_name= 'feature_behavior'
Ejemplo n.º 3
0
class LayerResource(PresentationMediumResource, CloneableResourceMixin):

    create_from_selection = BooleanField(attribute='create_from_selection')
    medium = ToOneFieldWithSubclasses(LayerStyleResource,
                                      attribute='medium_subclassed',
                                      full=True,
                                      null=True)

    def full_hydrate(self, bundle):
        """
            Defaults the template of new Layers
        :param bundle:
        :return:
        """
        bundle = super(LayerResource, self).full_hydrate(bundle)
        if not bundle.obj.id:
            # If the layer is new, create its template.
            # This used to be done in the layer_publisher, but since the refactoring
            # to support style editing it the layer.medium is required, so this
            # must be done pre-save of the Layer
            config_entity = bundle.obj.db_entity_interest.config_entity

            db_entity_interest = bundle.obj.db_entity_interest
            #for debugging, delete existing layers on layer save
            db_entity_interest.presentationmedium_set.all().delete()

            # layer_fixture = resolve_fixture(
            #     "presentation",
            #     "layer",
            #     LayerConfigurationFixture,
            #     config_entity.schema())
            #
            # layer_configuration = create_layer_configuration_for_import(
            #     config_entity,
            #     bundle.obj.db_entity_key)
            #
            # template = layer_fixture.update_or_create_layer_style(
            #     config_entity,
            #     layer_configuration,
            #     bundle.obj)
            # bundle.obj.medium = template
        return bundle

    class Meta(PresentationMediumResource.Meta):
        resource_name = 'layer'
        always_return_data = True
        # Don't allow any Layer of and incomplete uploaded DbEntity
        queryset = Layer.objects.filter(
            db_entity_interest__db_entity__setup_percent_complete=100)
        filtering = {
            "id": ('exact', ),
        }
Ejemplo n.º 4
0
class BuiltFormResource(FootprintResource, TagResourceMixin,
                        PublisherControlMixin, CloneableResourceMixin):

    # The Medium of the BuiltForm, like Layer, is a LayerStyle. Unlike Layer, we set full=False so that
    # we won't load all the layer styles for BuiltForms that the user never looks at
    medium = ToOneFieldWithSubclasses(LayerStyleResource,
                                      attribute='medium_subclassed',
                                      full=False,
                                      null=True)
    media = fields.ToManyField(MediumResource, 'media', null=True, full=False)
    examples = fields.ToManyField(
        'footprint.main.resources.built_form_resources.BuiltFormExampleResource',
        'examples',
        null=True,
        full=False)

    # Do not wrap with using_bundle_cache. It fails since this doesn't return a query
    def flat_building_densities_query(bundle):
        return get_first(
            FlatBuiltForm.objects.filter(built_form_id=bundle.obj.id))

    flat_building_densities = fields.ToOneField(
        FlatBuiltFormResource,
        attribute=flat_building_densities_query,
        full=False,
        null=True,
        readonly=True)
    built_form_set_query = lambda bundle: bundle.obj.builtformset_set.all()

    built_form_sets = fields.ToManyField(
        'footprint.main.resources.built_form_resources.BuiltFormSetResource',
        attribute=built_form_set_query,
        full=False,
        null=True,
        readonly=True)

    def hydrate(self, bundle):
        """
            Set the user who created the ConfigEntity
        :param bundle:
        :return:
        """
        if not bundle.obj.id:
            bundle.obj.creator = self.resolve_user(bundle.request.GET)
        bundle.obj.updater = self.resolve_user(bundle.request.GET)
        return super(BuiltFormResource, self).hydrate(bundle)

    def full_hydrate(self, bundle):
        # There's no memory of the bundle.data layer_style being a LayerStyle class,
        # so wrap it here. We can't do this in hydate or hydrate_medium_context because Tastypie
        # will overwrite the value after
        super(BuiltFormResource, self).full_hydrate(bundle)
        if bundle.obj.medium_context.__class__ == dict:
            bundle.obj.medium_context = LayerStyle(**bundle.obj.medium_context)
        return bundle

    def full_dehydrate(self, bundle, for_list=False):
        # Make sure new built_forms are added to the built_form_sets prior to dehydration
        # This normally happens in post_save, which is too late for the create case
        add_built_forms_to_built_form_sets([bundle.obj])
        return super(BuiltFormResource, self).full_dehydrate(bundle)

    class Meta(FootprintResource.Meta):
        always_return_data = True
        queryset = BuiltForm.objects.filter(
            deleted=False).all().select_subclasses()
        resource_name = 'built_form'