diff --git a/app/grandchallenge/algorithms/forms.py b/app/grandchallenge/algorithms/forms.py index 8ebd68c8d..993d0be05 100644 --- a/app/grandchallenge/algorithms/forms.py +++ b/app/grandchallenge/algorithms/forms.py @@ -1463,7 +1463,7 @@ def __init__(self, *args, algorithm, **kwargs): self._algorithm.interfaces.all() ) self.fields["algorithm_interface"].initial = ( - self._algorithm.default_interface_for_job + self._algorithm.default_interface ) self.fields["algorithm_interface"].widget.choices = { ( diff --git a/app/grandchallenge/algorithms/models.py b/app/grandchallenge/algorithms/models.py index 022d9d86f..1f79b8867 100644 --- a/app/grandchallenge/algorithms/models.py +++ b/app/grandchallenge/algorithms/models.py @@ -8,7 +8,11 @@ from django.contrib.auth import get_user_model from django.contrib.auth.models import Group from django.contrib.contenttypes.models import ContentType -from django.core.exceptions import ObjectDoesNotExist, ValidationError +from django.core.exceptions import ( + MultipleObjectsReturned, + ObjectDoesNotExist, + ValidationError, +) from django.core.validators import MaxValueValidator, MinValueValidator from django.db import models from django.db.models import Count, Q, Sum @@ -511,22 +515,14 @@ def default_workstation(self): @cached_property def default_interface(self): try: - return self.interfaces.get( - algorithmalgorithminterface__is_default=True - ) - except ObjectDoesNotExist: - return None - - @cached_property - def requires_interface_selection_for_job(self): - return self.interfaces.count() != 1 - - @cached_property - def default_interface_for_job(self): - if self.requires_interface_selection_for_job: - return self.default_interface - else: - return self.interfaces.first() + return self.interfaces.get() + except MultipleObjectsReturned: + try: + return self.interfaces.get( + algorithmalgorithminterface__is_default=True + ) + except ObjectDoesNotExist: + return None def is_editor(self, user): return user.groups.filter(pk=self.editors_group.pk).exists() diff --git a/app/grandchallenge/algorithms/views.py b/app/grandchallenge/algorithms/views.py index dc6f6e845..e2574413d 100644 --- a/app/grandchallenge/algorithms/views.py +++ b/app/grandchallenge/algorithms/views.py @@ -504,11 +504,11 @@ class JobInterfaceSelect( selected_interface = None def get(self, request, *args, **kwargs): - if self.algorithm.requires_interface_selection_for_job: - return super().get(request, *args, **kwargs) - else: - self.selected_interface = self.algorithm.default_interface_for_job + if self.algorithm.interfaces.count() == 1: + self.selected_interface = self.algorithm.default_interface return HttpResponseRedirect(self.get_success_url()) + else: + return super().get(request, *args, **kwargs) def get_form_kwargs(self): kwargs = super().get_form_kwargs()