Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Order operation fields by awx order instead by name #742

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.6 on 2023-12-08 14:20

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('service_catalog', '0037_alter_request_options_remove_approvalstep_next_and_more'),
]

operations = [
migrations.AlterUniqueTogether(
name='towersurveyfield',
unique_together=set(),
),
migrations.AddField(
model_name='towersurveyfield',
name='position',
field=models.IntegerField(default=0),
),
migrations.AlterUniqueTogether(
name='towersurveyfield',
unique_together={('operation', 'position', 'variable')},
),
]
7 changes: 7 additions & 0 deletions service_catalog/models/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ def update_survey(self):
if self.job_template is not None:
spec_list = self.job_template.survey.get("spec", [])
from service_catalog.models.tower_survey_field import TowerSurveyField
position = 0
for field in spec_list:
squest_field, created = TowerSurveyField.objects.get_or_create(
variable=field['variable'],
position=position,
operation=self,
defaults={
'is_customer_field': True,
Expand All @@ -84,6 +86,7 @@ def update_survey(self):
)
if not created:
squest_field.name = field['question_name']
squest_field.position = position
squest_field.description = field['question_description']
squest_field.type = field['type']
squest_field.required = field['required']
Expand All @@ -94,6 +97,7 @@ def update_survey(self):
"default": field.get('default', '')
}
squest_field.save()
position += 1
self.tower_survey_fields.exclude(
variable__in=[survey_spec["variable"] for survey_spec in spec_list]).delete()

Expand All @@ -113,9 +117,11 @@ def add_job_template_survey_as_default_survey(cls, sender, instance, created, *a
# copy the default survey and add a flag 'is_visible'
default_survey = instance.job_template.survey
if "spec" in default_survey:
position = 0
for field in default_survey["spec"]:
TowerSurveyField.objects.create(
variable=field['variable'],
position=position,
is_customer_field=True,
operation=instance,
name=field['question_name'],
Expand All @@ -129,6 +135,7 @@ def add_job_template_survey_as_default_survey(cls, sender, instance, created, *a
"default": field.get('default', '')
}
)
position += 1


post_save.connect(Operation.add_job_template_survey_as_default_survey, sender=Operation)
Expand Down
5 changes: 3 additions & 2 deletions service_catalog/models/tower_survey_field.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import sys

from django.db.models import CharField, BooleanField, ForeignKey, CASCADE, SET_NULL, JSONField
from django.db.models import CharField, BooleanField, ForeignKey, CASCADE, SET_NULL, JSONField, IntegerField
from django.db.models.signals import pre_save
from django.dispatch import receiver
from django.forms import CharField as FormsCharField
Expand Down Expand Up @@ -47,9 +47,10 @@ def __init__(self, quota=None, *args, **kwargs):

class TowerSurveyField(SquestModel):
class Meta(SquestModel.Meta):
unique_together = ('operation', 'variable',)
unique_together = ('operation', 'position', 'variable',)

variable = CharField(null=False, blank=False, max_length=200)
position = IntegerField(default=0)
is_customer_field = BooleanField(default=True, null=False, blank=False, help_text="Display for non approver user")
default = CharField(null=True, blank=True, max_length=200, verbose_name="Default value")
operation = ForeignKey(Operation,
Expand Down
Loading