Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show comparison set name for group on the result form #748

Merged
merged 2 commits into from
Dec 12, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion hawc/apps/epi/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,10 +713,20 @@ def __init__(self, *args, **kwargs):
self.fields["comparison_set"].widget.attrs["disabled"] = True


class GroupSelectWidget(forms.Select):
def create_option(self, name, value, label, selected, index, subindex=None, attrs=None):
# show the parent's name in case groups are named the same across comparison sets
option = super().create_option(name, value, label, selected, index, subindex, attrs)
if value:
option["label"] = f"{value.instance.comparison_set} - {value.instance.name}"
return option


class GroupResultForm(forms.ModelForm):
class Meta:
model = models.GroupResult
exclude = ("result",)
widgets = {"group": GroupSelectWidget}

def __init__(self, *args, **kwargs):
study_population = kwargs.pop("study_population", None)
Expand All @@ -726,7 +736,7 @@ def __init__(self, *args, **kwargs):
self.fields["group"].queryset = models.Group.objects.filter(
Q(comparison_set__study_population=study_population)
| Q(comparison_set__outcome=outcome)
)
).select_related("comparison_set")
if result:
self.instance.result = result

Expand Down