Skip to content

Commit

Permalink
fix ajax load transformer consume from attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Sispheor committed Sep 14, 2023
1 parent d82d1c9 commit 65e9215
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion resource_tracker_v2/forms/transformer_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
17 changes: 11 additions & 6 deletions resource_tracker_v2/views/transformer_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,17 @@ 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)
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)

options = [(transformer.attribute_definition.id, transformer.attribute_definition.name) for transformer in
all_available_attribute_to_target_rg.all()]
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})

0 comments on commit 65e9215

Please sign in to comment.