diff --git a/src/indicators/migrations/0004_alter_indicator_base.py b/src/indicators/migrations/0004_alter_indicator_base.py
new file mode 100644
index 0000000..b01df46
--- /dev/null
+++ b/src/indicators/migrations/0004_alter_indicator_base.py
@@ -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'),
+ ),
+ ]
diff --git a/src/indicators/models.py b/src/indicators/models.py
index 3279652..ca7ed2e 100644
--- a/src/indicators/models.py
+++ b/src/indicators/models.py
@@ -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,
)
diff --git a/src/indicatorsets/filters.py b/src/indicatorsets/filters.py
index e98d511..dd82525 100644
--- a/src/indicatorsets/filters.py
+++ b/src/indicatorsets/filters.py
@@ -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):
@@ -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,
diff --git a/src/indicatorsets/forms.py b/src/indicatorsets/forms.py
index 11e0813..abf0b8b 100644
--- a/src/indicatorsets/forms.py
+++ b/src/indicatorsets/forms.py
@@ -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):
@@ -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(),
)
diff --git a/src/indicatorsets/utils.py b/src/indicatorsets/utils.py
index daeb7ae..1bf84f0 100644
--- a/src/indicatorsets/utils.py
+++ b/src/indicatorsets/utils.py
@@ -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):
@@ -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()
+ ]
diff --git a/src/templates/http_errors/400.html b/src/templates/http_errors/400.html
index 26d9026..cac38d2 100644
--- a/src/templates/http_errors/400.html
+++ b/src/templates/http_errors/400.html
@@ -8,7 +8,7 @@
400
Sorry, the request could not be understood by the server due to malformed syntax.
- Back to home
+ Back to home
diff --git a/src/templates/http_errors/403.html b/src/templates/http_errors/403.html
index a63efc3..21b8ec9 100644
--- a/src/templates/http_errors/403.html
+++ b/src/templates/http_errors/403.html
@@ -7,7 +7,7 @@
403
You don't have permission to access this resource.
- Back to home
+ Back to home
{% endblock %}
\ No newline at end of file
diff --git a/src/templates/http_errors/404.html b/src/templates/http_errors/404.html
index 796d499..ae3f65e 100644
--- a/src/templates/http_errors/404.html
+++ b/src/templates/http_errors/404.html
@@ -9,7 +9,7 @@
{% endblock %}
diff --git a/src/templates/http_errors/500.html b/src/templates/http_errors/500.html
index 5cd1b2e..ddf0308 100644
--- a/src/templates/http_errors/500.html
+++ b/src/templates/http_errors/500.html
@@ -7,7 +7,7 @@
500
Internal Server Error.
- Back to home
+ Back to home
{% endblock %}
\ No newline at end of file