Esempio n. 1
0
 def map_related_to_field_and_label(field_name, related_model):
     """
         Creates a mapping from the _id attribute of ForeignKeys to
         to the related attribute (e.g. built_form_id to built_form).
         It puts the related attribute in the main dict with its resource_uri
         and puts a label representation in the __labels dict so that
         the related attribute can map from its id to a label. This
         is similar to what the regular FeatureResource does but it is
         more manual since we only have the _id attribute and must
         resolve the related instance ourselves
     """
     client_field_name = self.client_field_name(field_name)
     related_id = getattr(
         bundle.obj, client_field_name) if hasattr(
             bundle.obj, client_field_name) else None
     if related_id:
         related_model_instance = related_model.objects.get(
             id=related_id)
         related_field_name = field_name.replace('_id', '')
         return {
             # Get the resource class of the related model so we can make a uri
             related_field_name:
             FootprintResource.resolve_resource_class(
                 related_model)().get_resource_uri(
                     related_model_instance),
             # The label representation
             '__labels': {
                 related_field_name:
                 LayerSelection.resolve_instance_label(
                     related_model_instance)
             }
         }
     return None
Esempio n. 2
0
 def map_related_to_field_and_label(field_name, related_model):
     """
         Creates a mapping from the _id attribute of ForeignKeys to
         to the related attribute (e.g. built_form_id to built_form).
         It puts the related attribute in the main dict with its resource_uri
         and puts a label representation in the __labels dict so that
         the related attribute can map from its id to a label. This
         is similar to what the regular FeatureResource does but it is
         more manual since we only have the _id attribute and must
         resolve the related instance ourselves
     """
     client_field_name = self.client_field_name(field_name)
     related_id = getattr(bundle.obj, client_field_name) if hasattr(bundle.obj, client_field_name) else None
     if related_id:
         related_model_instance = related_model.objects.get(id=related_id)
         related_field_name = field_name.replace('_id', '')
         return {
             # Get the resource class of the related model so we can make a uri
             related_field_name: FootprintResource.resolve_resource_class(related_model)().get_resource_uri(related_model_instance),
             # The label representation
             '__labels': {related_field_name: LayerSelection.resolve_instance_label(related_model_instance)}
         }
     return None