From beaf9662298b2aad79c8108a2a70469e1ba564e9 Mon Sep 17 00:00:00 2001 From: Andy Shapiro Date: Sun, 15 Oct 2023 10:35:49 -0400 Subject: [PATCH] fix epi clones --- hawc/apps/epi/autocomplete.py | 14 ------ hawc/apps/epi/forms.py | 90 ++++++++++++++++++++++++++++------- hawc/apps/lit/managers.py | 1 - 3 files changed, 72 insertions(+), 33 deletions(-) diff --git a/hawc/apps/epi/autocomplete.py b/hawc/apps/epi/autocomplete.py index fc962b8322..98cc949ffe 100644 --- a/hawc/apps/epi/autocomplete.py +++ b/hawc/apps/epi/autocomplete.py @@ -30,13 +30,6 @@ class OutcomeAutocomplete(BaseAutocomplete): filter_fields = ["study_population_id", "study_population__study__assessment_id"] -@register -class ComparisonSetAutocomplete(BaseAutocomplete): - model = models.ComparisonSet - search_fields = ["name"] - filter_fields = ["study_population_id", "outcome_id"] - - @register class AdjustmentFactorAutocomplete(BaseAutocomplete): model = models.AdjustmentFactor @@ -44,13 +37,6 @@ class AdjustmentFactorAutocomplete(BaseAutocomplete): filter_fields = ["assessment_id"] -@register -class ResultAutocomplete(BaseAutocomplete): - model = models.Result - search_fields = ["metric__metric", "comparison_set__name"] - filter_fields = ["outcome_id"] - - @register class CountryAutocomplete(BaseAutocomplete): model = models.Country diff --git a/hawc/apps/epi/forms.py b/hawc/apps/epi/forms.py index 25c4881941..b8d8b67987 100644 --- a/hawc/apps/epi/forms.py +++ b/hawc/apps/epi/forms.py @@ -192,9 +192,18 @@ def clean(self): class StudyPopulationSelectorForm(CopyForm): - label = "Study Population" - parent_field = "study_id" - autocomplete_class = autocomplete.StudyPopulationAutocomplete + legend_text = "Copy Study Population" + help_text = "Select an existing study population as a template to create a new one." + create_url_pattern = "epi:sp_create" + selector = forms.ModelChoiceField( + queryset=models.StudyPopulation.objects.all(), empty_label=None, label="Select template" + ) + + def __init__(self, *args, **kw): + super().__init__(*args, **kw) + self.fields["selector"].queryset = self.fields["selector"].queryset.filter( + study=self.parent + ) class AdjustmentFactorForm(forms.ModelForm): @@ -307,9 +316,18 @@ def helper(self): class ExposureSelectorForm(CopyForm): - label = "Exposure" - parent_field = "study_population_id" - autocomplete_class = autocomplete.ExposureAutocomplete + legend_text = "Copy Exposure" + help_text = "Select an existing exposure as a template to create a new one." + create_url_pattern = "epi:exp_create" + selector = forms.ModelChoiceField( + queryset=models.Exposure.objects.all(), empty_label=None, label="Select template" + ) + + def __init__(self, *args, **kw): + super().__init__(*args, **kw) + self.fields["selector"].queryset = self.fields["selector"].queryset.filter( + study_population=self.parent + ) class OutcomeForm(forms.ModelForm): @@ -387,9 +405,18 @@ def helper(self): class OutcomeSelectorForm(CopyForm): - label = "Outcome" - parent_field = "study_population_id" - autocomplete_class = autocomplete.OutcomeAutocomplete + legend_text = "Copy Outcome" + help_text = "Select an existing outcome as a template to create a new one." + create_url_pattern = "epi:outcome_create" + selector = forms.ModelChoiceField( + queryset=models.Outcome.objects.all(), empty_label=None, label="Select template" + ) + + def __init__(self, *args, **kw): + super().__init__(*args, **kw) + self.fields["selector"].queryset = self.fields["selector"].queryset.filter( + study_population=self.parent + ) class ComparisonSet(forms.ModelForm): @@ -446,15 +473,33 @@ def helper(self): class ComparisonSetByStudyPopulationSelectorForm(CopyForm): - label = "Comparison set" - parent_field = "study_population_id" - autocomplete_class = autocomplete.ComparisonSetAutocomplete + legend_text = "Copy Comparison Set" + help_text = "Select an existing comparison set as a template to create a new one." + create_url_pattern = "epi:cs_create" + selector = forms.ModelChoiceField( + queryset=models.ComparisonSet.objects.all(), empty_label=None, label="Select template" + ) + + def __init__(self, *args, **kw): + super().__init__(*args, **kw) + self.fields["selector"].queryset = self.fields["selector"].queryset.filter( + study_population=self.parent + ) class ComparisonSetByOutcomeSelectorForm(CopyForm): - label = "Comparison set" - parent_field = "outcome_id" - autocomplete_class = autocomplete.ComparisonSetAutocomplete + legend_text = "Copy Comparison Set" + help_text = "Select an existing comparison set as a template to create a new one." + create_url_pattern = "epi:cs_outcome_create" + selector = forms.ModelChoiceField( + queryset=models.ComparisonSet.objects.all(), empty_label=None, label="Select template" + ) + + def __init__(self, *args, **kw): + super().__init__(*args, **kw) + self.fields["selector"].queryset = self.fields["selector"].queryset.filter( + outcome=self.parent + ) class GroupForm(forms.ModelForm): @@ -694,9 +739,18 @@ def helper(self): class ResultSelectorForm(CopyForm): - label = "Result" - parent_field = "outcome_id" - autocomplete_class = autocomplete.ResultAutocomplete + legend_text = "Copy Result" + help_text = "Select an existing result as a template to create a new one." + create_url_pattern = "epi:result_create" + selector = forms.ModelChoiceField( + queryset=models.Result.objects.all(), empty_label=None, label="Select template" + ) + + def __init__(self, *args, **kw): + super().__init__(*args, **kw) + self.fields["selector"].queryset = self.fields["selector"].queryset.filter( + outcome=self.parent + ) class ResultUpdateForm(ResultForm): diff --git a/hawc/apps/lit/managers.py b/hawc/apps/lit/managers.py index 0e67ebd1b0..251ebe1a85 100644 --- a/hawc/apps/lit/managers.py +++ b/hawc/apps/lit/managers.py @@ -18,7 +18,6 @@ from ...services.epa import hero from ...services.nih import pubmed from ..assessment.managers import published -from ..assessment.models import Assessment from ..common.models import BaseManager, replace_null, str_m2m from ..study.managers import study_df_annotations from . import constants