Skip to content

Commit

Permalink
Update default interface property
Browse files Browse the repository at this point in the history
  • Loading branch information
amickan committed Dec 16, 2024
1 parent 1df4405 commit 36f51e6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
2 changes: 1 addition & 1 deletion app/grandchallenge/algorithms/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
(
Expand Down
30 changes: 13 additions & 17 deletions app/grandchallenge/algorithms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions app/grandchallenge/algorithms/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 36f51e6

Please sign in to comment.