From f4d7f268f9f5836dc8e531149ff2adb783fcf913 Mon Sep 17 00:00:00 2001 From: Dmytro Trotsko Date: Mon, 10 Jun 2024 23:57:46 +0300 Subject: [PATCH 1/2] OKRS24-217 Save stage commit --- src/signals/filters.py | 8 +- src/signals/forms.py | 17 +---- src/signals/models.py | 3 +- src/signals/views.py | 12 +-- src/templates/signals/signals.html | 116 +++++++++-------------------- 5 files changed, 52 insertions(+), 104 deletions(-) diff --git a/src/signals/filters.py b/src/signals/filters.py index 3777f74..489e4b5 100644 --- a/src/signals/filters.py +++ b/src/signals/filters.py @@ -15,6 +15,7 @@ FormatChoices, Signal, TimeTypeChoices, + GeographicScope, ) @@ -45,6 +46,11 @@ class SignalFilter(django_filters.FilterSet): time_type = django_filters.MultipleChoiceFilter(choices=TimeTypeChoices.choices) base_signal = django_filters.BooleanFilter(lookup_expr='isnull', field_name='base_for') + def __init__(self, data, *args, **kwargs): + data = data.copy() + data.setdefault('geographic_scope', GeographicScope.objects.get(name='USA').id) + super().__init__(data, *args, **kwargs) + class Meta: model = Signal fields: list[str] = [ @@ -55,7 +61,7 @@ class Meta: 'available_geography', 'signal_type', 'category', - 'format_type', + 'geographic_scope', 'source', 'time_type', 'base_signal', diff --git a/src/signals/forms.py b/src/signals/forms.py index 040689d..2a6edbf 100644 --- a/src/signals/forms.py +++ b/src/signals/forms.py @@ -4,10 +4,10 @@ from datasources.models import SourceSubdivision from signals.models import ( ActiveChoices, - FormatChoices, Pathogen, Signal, TimeTypeChoices, + GeographicScope, ) @@ -27,10 +27,10 @@ class SignalFilterForm(forms.ModelForm): search = forms.CharField(min_length=3) pathogen = forms.ModelChoiceField(queryset=Pathogen.objects.all(), widget=forms.CheckboxSelectMultiple()) active = forms.TypedMultipleChoiceField(choices=ActiveChoices.choices, coerce=bool, widget=forms.CheckboxSelectMultiple()) - format_type = forms.ChoiceField(choices=FormatChoices.choices, widget=forms.CheckboxSelectMultiple()) source = forms.ModelMultipleChoiceField(queryset=SourceSubdivision.objects.all(), widget=forms.CheckboxSelectMultiple()) time_type = forms.ChoiceField(choices=TimeTypeChoices.choices, widget=forms.CheckboxSelectMultiple()) base_signal = forms.ChoiceField(choices=[('', _('All')), (True, _('Yes')), (False, _('No'))], required=False, widget=forms.RadioSelect()) + geographic_scope = forms.ModelMultipleChoiceField(queryset=GeographicScope.objects.all(), widget=forms.CheckboxSelectMultiple()) class Meta: model = Signal @@ -41,11 +41,10 @@ class Meta: 'pathogen', 'active', 'available_geography', - 'category', - 'format_type', 'signal_type', 'source', 'time_type', + 'geographic_scope', ] widgets = { @@ -65,16 +64,6 @@ class Meta: 'data-bs-toggle': 'tooltip', 'data-bs-placement': 'bottom', }), - 'category': forms.CheckboxSelectMultiple(attrs={ - 'class': 'form-select', - 'data-bs-toggle': 'tooltip', - 'data-bs-placement': 'bottom', - }), - 'format_type': forms.CheckboxSelectMultiple(attrs={ - 'class': 'form-select', - 'data-bs-toggle': 'tooltip', - 'data-bs-placement': 'bottom', - }), 'source': forms.CheckboxSelectMultiple(attrs={ 'class': 'form-select', 'data-bs-toggle': 'tooltip', diff --git a/src/signals/models.py b/src/signals/models.py index 59c695d..7530c16 100644 --- a/src/signals/models.py +++ b/src/signals/models.py @@ -53,8 +53,7 @@ class ActiveChoices(models.TextChoices): """ A class representing choices for active signals. """ - ACTIVE = True, _('Active') - HISTORICAL = False, _('Historical') + ACTIVE = True, _('Current Surveillance Only') class SeverityPyramidRungsChoices(models.TextChoices): diff --git a/src/signals/views.py b/src/signals/views.py index af80898..dcfd018 100644 --- a/src/signals/views.py +++ b/src/signals/views.py @@ -8,7 +8,7 @@ from signals.filters import SignalFilter from signals.forms import SignalFilterForm -from signals.models import Signal +from signals.models import Signal, GeographicScope from signals.serializers import SignalSerializer @@ -48,10 +48,9 @@ def get_url_params(self): "signal_type": [int(el) for el in self.request.GET.getlist("signal_type")] if self.request.GET.get("signal_type") else None, - "category": self.request.GET.getlist("category") - if self.request.GET.get("category") + "geographic_scope": [el for el in self.request.GET.getlist("geographic_scope")] + if self.request.GET.get("geographic_scope") else None, - "format_type": [el for el in self.request.GET.getlist("format_type")], "source": [int(el) for el in self.request.GET.getlist("source")], "time_type": [el for el in self.request.GET.getlist("time_type")], "base_signal": self.request.GET.get("base_signal"), @@ -76,6 +75,8 @@ def get_context_data(self, **kwargs) -> Dict[str, Any]: context: Dict[str, Any] = super().get_context_data(**kwargs) url_params_dict, url_params_str = self.get_url_params() + if not url_params_dict.get("geographic_scope"): + url_params_dict["geographic_scope"] = [GeographicScope.objects.get(name="USA").id] context["url_params_dict"] = url_params_dict context["form"] = SignalFilterForm(initial=url_params_dict) context["url_params_str"] = url_params_str @@ -121,9 +122,8 @@ class SignalsListApiView(ListAPIView): "pathogen__name", "available_geography__name", "signal_type__name", - "category__name", - "format_type", "base", "source__name", "time_label", + "geographic_scope__name", ) diff --git a/src/templates/signals/signals.html b/src/templates/signals/signals.html index 0370fb8..cee42ff 100644 --- a/src/templates/signals/signals.html +++ b/src/templates/signals/signals.html @@ -20,6 +20,9 @@
value="{% if filter.form.search.value %}{{ filter.form.search.value }}{% endif %}" > +
+ {{ form.active|as_crispy_field}} +
@@ -27,9 +30,9 @@

-

- {% if form.active.value %} -
- {% else %} -
- {% endif %} -
- {{ form.active|as_crispy_field}} -
-
-
-

@@ -89,9 +75,9 @@

{% endif %}
-
+
- +
{{ form.available_geography|as_crispy_field }}
@@ -99,14 +85,14 @@

-

+

-

- {% if form.category.value %} -
- {% else %} -
- {% endif %} -
-
- - -
- {{ form.category|as_crispy_field }} -
-
-
-

+

- {% if form.format_type.value %} -
+ {% if form.geographic_scope.value %} +
{% else %} -
+
{% endif %}
-
- - -
- {{ form.format_type|as_crispy_field }} + {{ form.geographic_scope|as_crispy_field }}
@@ -203,18 +157,18 @@

{% endif %}
-
+
- +
{{ form.source|as_crispy_field }}
-

+