Skip to content

Development #5

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 2 commits into from
May 5, 2025
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
19 changes: 19 additions & 0 deletions src/indicators/migrations/0004_alter_indicator_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 5.0.7 on 2025-05-05 16:22

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('indicators', '0003_alter_indicator_geographic_scope_and_more'),
]

operations = [
migrations.AlterField(
model_name='indicator',
name='base',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='base_for', to='indicators.indicator', verbose_name='Base Indicator'),
),
]
2 changes: 1 addition & 1 deletion src/indicators/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ class Indicator(models.Model):
"indicators.Indicator",
verbose_name="Base Indicator",
related_name="base_for",
on_delete=models.PROTECT,
on_delete=models.CASCADE,
null=True,
blank=True,
)
Expand Down
18 changes: 5 additions & 13 deletions src/indicatorsets/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,16 @@


from indicatorsets.models import IndicatorSet
from indicatorsets.utils import get_list_of_indicators_filtered_by_geo
from indicatorsets.utils import (
get_list_of_indicators_filtered_by_geo,
get_original_data_provider_choices,
)
from indicators.models import Indicator
from base.models import Pathogen, GeographicScope, Geography, SeverityPyramidRung


logger = logging.getLogger(__name__)

try:
ORIGINAL_DATA_PROVIDER_CHOICES = [
(el, el)
for el in set(
IndicatorSet.objects.values_list("original_data_provider", flat=True)
)
]
except Exception as e:
ORIGINAL_DATA_PROVIDER_CHOICES = [("", "No original data provider available")]
print(f"Error fetching original data provider choices: {e}")


class IndicatorSetFilter(django_filters.FilterSet):

Expand Down Expand Up @@ -60,7 +52,7 @@ class IndicatorSetFilter(django_filters.FilterSet):

original_data_provider = django_filters.MultipleChoiceFilter(
field_name="original_data_provider",
choices=ORIGINAL_DATA_PROVIDER_CHOICES,
choices=get_original_data_provider_choices,
widget=QueryArrayWidget,
lookup_expr="exact",
required=False,
Expand Down
15 changes: 2 additions & 13 deletions src/indicatorsets/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,7 @@

from base.models import Pathogen, GeographicScope, Geography, SeverityPyramidRung
from indicatorsets.models import IndicatorSet


try:
ORIGINAL_DATA_PROVIDER_CHOICES = [
(el, el)
for el in set(
IndicatorSet.objects.values_list("original_data_provider", flat=True)
)
]
except Exception as e:
ORIGINAL_DATA_PROVIDER_CHOICES = [("", "No original data provider available")]
print(f"Error fetching original data provider choices: {e}")
from indicatorsets.utils import get_original_data_provider_choices


class IndicatorSetFilterForm(forms.ModelForm):
Expand Down Expand Up @@ -44,7 +33,7 @@ class IndicatorSetFilterForm(forms.ModelForm):
)

original_data_provider = forms.ChoiceField(
choices=ORIGINAL_DATA_PROVIDER_CHOICES,
choices=get_original_data_provider_choices,
widget=forms.CheckboxSelectMultiple(),
)

Expand Down
10 changes: 10 additions & 0 deletions src/indicatorsets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import requests
from django.conf import settings
from epiweeks import Week
from indicatorsets.models import IndicatorSet


def list_to_dict(lst):
Expand Down Expand Up @@ -53,3 +54,12 @@ def get_epiweek(start_date, end_date):
end_date = Week.fromdate(end_date)
end_date = f"{end_date.year}{end_date.week if end_date.week >= 10 else '0' + str(end_date.week)}"
return [start_date, end_date]


def get_original_data_provider_choices():
return [
(el, el)
for el in IndicatorSet.objects.values_list("original_data_provider", flat=True)
.order_by("original_data_provider")
.distinct()
]
2 changes: 1 addition & 1 deletion src/templates/http_errors/400.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<section class="section error-404 min-vh-100 d-flex flex-column align-items-center justify-content-center">
<h1>400</h1>
<h2>Sorry, the request could not be understood by the server due to malformed syntax.</h2>
<a class="btn" href="{% url 'signals' %}">Back to home</a>
<a class="btn" href="{% url 'indicatorsets' %}">Back to home</a>
</section>

</div>
Expand Down
2 changes: 1 addition & 1 deletion src/templates/http_errors/403.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<section class="section error-404 min-vh-100 d-flex flex-column align-items-center justify-content-center">
<h1>403</h1>
<h2>You don't have permission to access this resource.</h2>
<a class="btn" href="{% url 'signals' %}">Back to home</a>
<a class="btn" href="{% url 'indicatorsets' %}">Back to home</a>
</section>
</div>
{% endblock %}
2 changes: 1 addition & 1 deletion src/templates/http_errors/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<section class="section error-404 min-vh-100 d-flex flex-column align-items-center justify-content-center">
<h1>404</h1>
<h2>Not Found</h2>
<a class="btn" href="{% url 'signals' %}">Back to home</a>
<a class="btn" href="{% url 'indicatorsets' %}">Back to home</a>
</section>
</div>
{% endblock %}
2 changes: 1 addition & 1 deletion src/templates/http_errors/500.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<section class="section error-404 min-vh-100 d-flex flex-column align-items-center justify-content-center">
<h1>500</h1>
<h2>Internal Server Error.</h2>
<a class="btn" href="{% url 'signals' %}">Back to home</a>
<a class="btn" href="{% url 'indicatorsets' %}">Back to home</a>
</section>
</div>
{% endblock %}
Loading