Make public_key form params mandatory only if existing keys do not exist

This commit is contained in:
PCoder 2019-06-25 02:25:17 +02:00
parent 0cf5e541cc
commit 9ee1b7c124

View file

@ -595,6 +595,10 @@ class OrderConfirmationView(DetailView, FormView):
# Check ssh public key and then proceed # Check ssh public key and then proceed
form = self.get_form() form = self.get_form()
required = 'add_ssh' in self.request.POST required = 'add_ssh' in self.request.POST
# 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['name'].required = required
form.fields['public_key'].required = required form.fields['public_key'].required = required
if not form.is_valid(): if not form.is_valid():