From e69445385bf0b6e10b7026ea0c0effc26cde36a8 Mon Sep 17 00:00:00 2001 From: Nicolas Marcq Date: Thu, 14 Sep 2023 16:25:34 +0200 Subject: [PATCH] fix ajax load transformer consume from attribute --- resource_tracker_v2/forms/transformer_form.py | 3 ++- resource_tracker_v2/views/transformer_views.py | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/resource_tracker_v2/forms/transformer_form.py b/resource_tracker_v2/forms/transformer_form.py index 3448ef77a..f1bc59cd8 100644 --- a/resource_tracker_v2/forms/transformer_form.py +++ b/resource_tracker_v2/forms/transformer_form.py @@ -10,7 +10,8 @@ class TransformerForm(SquestModelForm): class Meta: model = Transformer - fields = ["attribute_definition", "consume_from_resource_group", "consume_from_attribute_definition", "factor"] + fields = ["attribute_definition", "consume_from_resource_group", "consume_from_attribute_definition", "factor", + "yellow_threshold_percent_consumed", "red_threshold_percent_consumed"] def __init__(self, *args, **kwargs): self.source_resource_group = kwargs.pop("source_resource_group") diff --git a/resource_tracker_v2/views/transformer_views.py b/resource_tracker_v2/views/transformer_views.py index 0671f2e2a..031c41d23 100644 --- a/resource_tracker_v2/views/transformer_views.py +++ b/resource_tracker_v2/views/transformer_views.py @@ -136,12 +136,14 @@ def ajax_load_attribute(request): current_resource_group_id = request.GET.get('current_resource_group_id') target_resource_group_id = request.GET.get('target_resource_group_id') current_resource_group = ResourceGroup.objects.get(id=current_resource_group_id) - target_resource_group = ResourceGroup.objects.get(id=target_resource_group_id) - all_available_attribute_to_target_rg = Transformer.objects \ - .filter(resource_group=target_resource_group) \ - .exclude(resource_group=current_resource_group, consume_from_resource_group=target_resource_group) + if target_resource_group_id != "": + target_resource_group = ResourceGroup.objects.get(id=target_resource_group_id) + options = Transformer.objects.filter(resource_group=target_resource_group)\ + .exclude(resource_group=current_resource_group, + consume_from_resource_group=target_resource_group).values_list('attribute_definition__id', 'attribute_definition__name') + else: + # remove consume from on attribute from the transformer + options = ["---------", "---------"] - options = [(transformer.attribute_definition.id, transformer.attribute_definition.name) for transformer in - all_available_attribute_to_target_rg.all()] return render(request, 'generics/ajax-option.html', {'options': options})