From 9ee1b7c124dd3cd4367198b07ae0939caed91691 Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 25 Jun 2019 02:25:17 +0200 Subject: [PATCH] Make public_key form params mandatory only if existing keys do not exist --- datacenterlight/views.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 7aa6d8a4..914c66eb 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -595,8 +595,12 @@ class OrderConfirmationView(DetailView, FormView): # Check ssh public key and then proceed form = self.get_form() required = 'add_ssh' in self.request.POST - form.fields['name'].required = required - form.fields['public_key'].required = required + + # SSH key is required only if the user doesn't have an existing + # key + if len(get_all_public_keys(self.request.user)) == 0: + form.fields['name'].required = required + form.fields['public_key'].required = required if not form.is_valid(): response = { 'status': False,