environment: add update_* helpers (#85759)

This commit is contained in:
Benjamin Dauvergne 2024-01-17 14:14:45 +01:00
parent 4daf3d5137
commit 024d83734b
2 changed files with 25 additions and 14 deletions

View File

@ -101,6 +101,22 @@ class Variable(models.Model):
def clean(self):
self._parse_value_as_json()
def update_value(self, value):
if self.value != value:
self.value = value
self.save()
return True
else:
return False
def update_json(self, value):
if self.json != value:
self.json = value
self.save()
return True
else:
return False
def is_resolvable(url):
try:

View File

@ -68,21 +68,16 @@ class HomeView(FormView):
form.add_confirmation_checkbox()
return self.form_invalid(form)
self.maintenance_page_variable.json = form.cleaned_data['maintenance_page']
self.maintenance_page_variable.save()
self.maintenance_page_message_variable.value = form.cleaned_data['maintenance_page_message']
self.maintenance_page_message_variable.save()
self.maintenance_page_variable.update_json(form.cleaned_data['maintenance_page'])
self.maintenance_page_message_variable.update_value(form.cleaned_data['maintenance_page_message'])
self.maintenance_pass_through_header_variable.update_value(
form.cleaned_data['maintenance_pass_through_header']
)
self.maintenance_pass_through_dnswl_variable.update_value(
form.cleaned_data['maintenance_pass_through_dnswl']
)
self.tenant_disable_cron_jobs_variable.update_json(form.cleaned_data['disable_cron'])
self.maintenance_pass_through_header_variable.value = form.cleaned_data[
'maintenance_pass_through_header'
]
self.maintenance_pass_through_header_variable.save()
self.maintenance_pass_through_dnswl_variable.value = form.cleaned_data[
'maintenance_pass_through_dnswl'
]
self.maintenance_pass_through_dnswl_variable.save()
self.tenant_disable_cron_jobs_variable.json = form.cleaned_data['disable_cron']
self.tenant_disable_cron_jobs_variable.save()
return super().form_valid(form)
def get_context_data(self, **kwargs):