Skip to content

Pre development #142

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

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/datasources/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SourceSubdivisionAdmin(ImportExportModelAdmin):
"""
Admin interface for managing source subdivision objects.
"""
list_display: tuple[Literal['name'], Literal['db_source']] = ('name', 'db_source')
list_display: tuple[Literal['name'], Literal['db_source'], Literal['external_name']] = ('name', 'db_source', 'external_name')
search_fields: tuple[Literal['name'], Literal['db_source']] = ('name', 'db_source')
resource_classes: list[type[SourceSubdivisionResource]] = [SourceSubdivisionResource]

Expand Down
7 changes: 7 additions & 0 deletions src/fixtures/available_geography.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"pk": 1,
"fields": {
"name": "county",
"display_name": "L2 division (e.g. U.S. counties)",
"created": "2023-08-09T19:23:22.597131",
"modified": "2023-08-09T19:23:22.597131"
}
Expand All @@ -13,6 +14,7 @@
"pk": 2,
"fields": {
"name": "hhs",
"display_name": "HHS Regions",
"created": "2023-08-09T19:23:22.597131",
"modified": "2023-08-09T19:23:22.597131"
}
Expand All @@ -22,6 +24,7 @@
"pk": 3,
"fields": {
"name": "hrr",
"display_name": "Hospital Referral Regions (HRAs)",
"created": "2023-08-09T19:23:22.597131",
"modified": "2023-08-09T19:23:22.597131"
}
Expand All @@ -31,6 +34,7 @@
"pk": 4,
"fields": {
"name": "msa",
"display_name": "Metropolitan Statistical Areas (MSAs)",
"created": "2023-08-09T19:23:22.597131",
"modified": "2023-08-09T19:23:22.597131"
}
Expand All @@ -40,6 +44,7 @@
"pk": 5,
"fields": {
"name": "nation",
"display_name": "National",
"created": "2023-08-09T19:23:22.597131",
"modified": "2023-08-09T19:23:22.597131"
}
Expand All @@ -49,6 +54,7 @@
"pk": 6,
"fields": {
"name": "state",
"display_name": "L1 division (e.g. U.S. states)",
"created": "2023-08-09T19:23:22.597131",
"modified": "2023-08-09T19:23:22.597131"
}
Expand All @@ -58,6 +64,7 @@
"pk": 7,
"fields": {
"name": "dma",
"display_name": "Designated Market Areas (DMAs)",
"created": "2023-08-09T19:23:22.597131",
"modified": "2023-08-09T19:23:22.597131"
}
Expand Down
12 changes: 10 additions & 2 deletions src/signals/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
FormatChoices,
Signal,
TimeTypeChoices,
GeographicScope,
SeverityPyramidRungsChoices,
)


Expand All @@ -41,10 +43,16 @@ class SignalFilter(django_filters.FilterSet):
)
)
format_type = django_filters.MultipleChoiceFilter(choices=FormatChoices.choices)
severenity_pyramid_rungs = django_filters.MultipleChoiceFilter(choices=SeverityPyramidRungsChoices.choices)
source = django_filters.ModelMultipleChoiceFilter(queryset=SourceSubdivision.objects.all())
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] = [
Expand All @@ -53,9 +61,9 @@ class Meta:
'pathogen',
'active',
'available_geography',
'signal_type',
'severenity_pyramid_rungs',
'category',
'format_type',
'geographic_scope',
'source',
'time_type',
'base_signal',
Expand Down
26 changes: 6 additions & 20 deletions src/signals/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
from datasources.models import SourceSubdivision
from signals.models import (
ActiveChoices,
FormatChoices,
Pathogen,
Signal,
TimeTypeChoices,
GeographicScope,
SeverityPyramidRungsChoices,
)


Expand All @@ -27,10 +28,11 @@ 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())
severenity_pyramid_rungs = forms.ChoiceField(choices=SeverityPyramidRungsChoices.choices, widget=forms.CheckboxSelectMultiple())

class Meta:
model = Signal
Expand All @@ -41,11 +43,10 @@ class Meta:
'pathogen',
'active',
'available_geography',
'category',
'format_type',
'signal_type',
'severenity_pyramid_rungs',
'source',
'time_type',
'geographic_scope',
]

widgets = {
Expand All @@ -60,21 +61,6 @@ class Meta:
'data-bs-toggle': 'tooltip',
'data-bs-placement': 'bottom',
}),
'signal_type': forms.CheckboxSelectMultiple(attrs={
'class': 'form-select',
'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',
Expand Down
18 changes: 18 additions & 0 deletions src/signals/migrations/0017_geography_display_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.10 on 2024-06-11 14:17

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('signals', '0016_remove_signal_geographic_scope_and_more'),
]

operations = [
migrations.AddField(
model_name='geography',
name='display_name',
field=models.CharField(blank=True, help_text='Display Name', max_length=128, null=True),
),
]
12 changes: 9 additions & 3 deletions src/signals/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -154,6 +153,13 @@ class Geography(TimeStampedModel):
unique=True
)

display_name: models.CharField = models.CharField(
help_text=_('Display Name'),
max_length=128,
null=True,
blank=True
)

class Meta:
verbose_name_plural: str = "geographies"
ordering: list[str] = ["name"]
Expand All @@ -165,7 +171,7 @@ def __str__(self) -> str:
:return: The name of the available geography as a string.
:rtype: str
"""
return str(self.name)
return str(self.display_name)


class GeographySignal(models.Model):
Expand Down
18 changes: 9 additions & 9 deletions src/signals/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -45,13 +45,12 @@ def get_url_params(self):
]
if self.request.GET.get("available_geography")
else None,
"signal_type": [int(el) for el in self.request.GET.getlist("signal_type")]
if self.request.GET.get("signal_type")
"severenity_pyramid_rungs": [el for el in self.request.GET.getlist("severenity_pyramid_rungs")]
if self.request.GET.get("severenity_pyramid_rungs")
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"),
Expand All @@ -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
Expand Down Expand Up @@ -120,10 +121,9 @@ class SignalsListApiView(ListAPIView):
"display_name",
"pathogen__name",
"available_geography__name",
"signal_type__name",
"category__name",
"format_type",
"severenity_pyramid_rungs",
"base",
"source__name",
"time_label",
"geographic_scope__name",
)
Loading
Loading