Exemple #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
def export_query_results(request, layer_selection_unique_id, api_key):
    layer_selection = LayerSelection.from_unique_id(layer_selection_unique_id)
    query = layer_selection.query_sql
    logger.debug("Exporting query results for layer_selection: %s, query: %s" %
                 (layer_selection.unique_id, query))
    job = start_and_track_task(_export_query_results, api_key,
                               class_name_for_client(LayerSelection),
                               layer_selection.unique_id,
                               layer_selection.layer.db_entity_key, query)
    return HttpResponse(job.hashid)
 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
Exemple #4
0
def export_query_summary(request, layer_selection_unique_id, api_key):
    layer_selection = LayerSelection.from_unique_id(layer_selection_unique_id)
    query = layer_selection.summary_query_sql
    logger.debug("Exporting summary query results for layer_selection: %s, summary query: %s" % (layer_selection.unique_id, query))
    job = start_and_track_task(_export_query_results, api_key, class_name_for_client(LayerSelection), layer_selection.unique_id, '%s_Summary' % layer_selection.layer.db_entity_key, query)
    return HttpResponse(job.hashid)