Skip to content

Commit

Permalink
Add help text with interface list link to CIV create forms (#3660)
Browse files Browse the repository at this point in the history
closes #3555
  • Loading branch information
ammar257ammar authored Oct 28, 2024
1 parent cda0704 commit a25f734
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/grandchallenge/archives/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ def bulk_delete_url(self):
kwargs={"slug": self.slug},
)

@property
def interface_viewname(self):
return "components:component-interface-list-archives"

@property
def civ_sets_related_manager(self):
return self.items
Expand Down
19 changes: 18 additions & 1 deletion app/grandchallenge/components/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
ModelMultipleChoiceField,
)
from django.utils.functional import empty
from django.utils.text import format_lazy

from grandchallenge.algorithms.models import AlgorithmImage
from grandchallenge.components.form_fields import (
Expand All @@ -24,6 +25,7 @@
from grandchallenge.core.forms import SaveFormInitMixin
from grandchallenge.core.guardian import get_objects_for_user
from grandchallenge.evaluation.models import Method
from grandchallenge.subdomains.utils import reverse_lazy
from grandchallenge.uploads.models import UserUpload
from grandchallenge.uploads.widgets import UserUploadSingleWidget
from grandchallenge.workstations.models import WorkstationImage
Expand Down Expand Up @@ -215,7 +217,14 @@ class SingleCIVForm(Form):
}

def __init__(
self, *args, pk, interface, base_obj, user, htmx_url, **kwargs
self,
*args,
pk,
interface,
base_obj,
user,
htmx_url,
**kwargs,
):
super().__init__(*args, **kwargs)
data = kwargs.get("data")
Expand Down Expand Up @@ -267,6 +276,14 @@ def __init__(
queryset=qs,
widget=widget(**widget_kwargs),
label="Interface",
help_text=format_lazy(
(
'See the <a href="{}">list of interfaces</a> for more '
"information about each interface. "
"Please contact support if your desired interface is missing."
),
reverse_lazy(base_obj.interface_viewname),
),
)

if selected_interface is not None:
Expand Down
4 changes: 4 additions & 0 deletions app/grandchallenge/reader_studies/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,10 @@ def bulk_delete_url(self):
kwargs={"slug": self.slug},
)

@property
def interface_viewname(self):
return "components:component-interface-list-reader-studies"

@property
def list_url(self):
return reverse("reader-studies:list")
Expand Down
36 changes: 36 additions & 0 deletions app/tests/components_tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from grandchallenge.archives.models import ArchiveItem
from grandchallenge.components.models import InterfaceKindChoices
from grandchallenge.reader_studies.models import DisplaySet, ReaderStudy
from grandchallenge.subdomains.utils import reverse
from tests.algorithms_tests.factories import AlgorithmFactory
from tests.archives_tests.factories import ArchiveFactory, ArchiveItemFactory
from tests.components_tests.factories import (
Expand Down Expand Up @@ -503,3 +504,38 @@ def test_display_ci_example_value(client):
assert response.status_code == 200
assert v.value in response.rendered_content
assert v.extra_info in response.rendered_content


@pytest.mark.django_db
@pytest.mark.parametrize(
"object_factory, viewname, interface_list_viewname",
[
[
ReaderStudyFactory,
"reader-studies:display-set-new-interfaces-create",
"components:component-interface-list-reader-studies",
],
[
ArchiveFactory,
"archives:item-new-interface-create",
"components:component-interface-list-archives",
],
],
)
def test_interfaces_list_link_in_new_interface_form(
client, object_factory, viewname, interface_list_viewname
):
object = object_factory()
u = UserFactory()
object.add_editor(u)

response = get_view_for_user(
viewname=viewname,
client=client,
method=client.get,
reverse_kwargs={
"slug": object.slug,
},
user=u,
)
assert reverse(interface_list_viewname) in response.rendered_content

0 comments on commit a25f734

Please sign in to comment.