From 772901085b37251835841463f80dc8c555661f19 Mon Sep 17 00:00:00 2001 From: lois <lois@procolix.eu> Date: Thu, 20 Mar 2025 16:56:25 +0100 Subject: [PATCH] Rebase onto main --- panel/src/panel/views.py | 54 ++-------------------------------------- 1 file changed, 2 insertions(+), 52 deletions(-) diff --git a/panel/src/panel/views.py b/panel/src/panel/views.py index b618c2c5..e36b7622 100644 --- a/panel/src/panel/views.py +++ b/panel/src/panel/views.py @@ -98,57 +98,7 @@ class DeploymentStatus(ConfigurationForm): return super().form_valid(form) -class DeploymentStatus(LoginRequiredMixin, FormView): - template_name = 'configuration_form.html' - success_url = reverse_lazy('configuration_form') - form_class = forms.Form - - def get_object(self): - """Get or create the configuration object for the current user""" - obj, created = models.Configuration.objects.get_or_create( - operator=self.request.user, - ) - - return obj - - def convert_enums_to_names(self, data_dict): - """ - Recursively convert all enum values in a dictionary to their string names. - This handles nested dictionaries and lists as well. - - Needed for converting a Pydantic `BaseModel` instance to a `Form` input. - """ - if isinstance(data_dict, dict): - result = {} - for key, value in data_dict.items(): - if isinstance(value, Enum): - # Convert Enum to its name - result[key] = value.name - elif isinstance(value, (dict, list)): - # Recursively process nested structures - result[key] = self.convert_enums_to_names(value) - else: - # Keep other values as is - result[key] = value - return result - elif isinstance(data_dict, list): - # Process each item in the list - return [self.convert_enums_to_names(item) for item in data_dict] - elif isinstance(data_dict, Enum): - # Convert single Enum value - return data_dict.name - else: - # Return non-dict, non-list, non-Enum values as is - return data_dict - - def get_initial(self): - initial = super().get_initial() - config = self.get_object() - config_dict = config.parsed_value.model_dump() - - initial.update(self.convert_enums_to_names(config_dict)) - return initial - +class DeploymentStatus(ConfigurationForm): def form_valid(self, form): obj = self.get_object() obj.value = form.to_python().model_dump_json() @@ -194,4 +144,4 @@ class DeploymentStatus(LoginRequiredMixin, FormView): env=env, ) print(deployment_result) - return deployment_result + return deployment_result \ No newline at end of file