Skip to content

Commit 3a1588c

Browse files
committed
Added custom warning message for non-delphi indicators
1 parent 51a5519 commit 3a1588c

File tree

6 files changed

+79
-16
lines changed

6 files changed

+79
-16
lines changed

src/assets/js/indicatorSetsTable.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@ new DataTable.Buttons(table, {
4444
table.buttons(0, null).container().appendTo("#colvis");
4545

4646
function format(indicatorSetId, relatedIndicators, indicatorSetDescription) {
47-
console.lopg;
4847
var indicators = relatedIndicators.filter(
4948
(indicator) => indicator.indicator_set === indicatorSetId
5049
);
51-
var disabled, restricted;
50+
var disabled, restricted, sourceType;
5251

5352
if (indicators.length > 0) {
5453
var data = `<p style="width: 40%;">${indicatorSetDescription}</p>`;
@@ -71,6 +70,7 @@ function format(indicatorSetId, relatedIndicators, indicatorSetDescription) {
7170
var checkboxTitle = "";
7271
checked = checked ? "checked" : "";
7372
disabled = indicator.endpoint ? "" : "disabled";
73+
sourceType = indicator.source_type;
7474
var restricted = indicator.restricted != "No";
7575
if (disabled === "disabled") {
7676
checkboxTitle =
@@ -92,11 +92,19 @@ function format(indicatorSetId, relatedIndicators, indicatorSetDescription) {
9292
});
9393
tableMarkup += "</tbody></table>";
9494
if (disabled === "disabled" || restricted) {
95-
data +=
96-
`<div class="alert alert-warning" data-mdb-alert-init role="alert">` +
97-
` <div>This indicator set is available via the <a href="https://cmu-delphi.github.io/delphi-epidata/">Epidata API</a>, and directly via <a href="https://delphi.cmu.edu/epivis/">Epivis</a>, but is not yet available via this interface.</div>` +
98-
"</div>";
95+
if (sourceType === "non_delphi") {
96+
data +=
97+
`<div class="alert alert-warning" data-mdb-alert-init role="alert">` +
98+
` <div>This indicator set is not available via Delphi. It is included here for general discoverability only, and may or may not be available from the Original Data Provider.</div>` +
99+
"</div>";
100+
} else {
101+
data +=
102+
`<div class="alert alert-warning" data-mdb-alert-init role="alert">` +
103+
` <div>This indicator set is available via the <a href="https://cmu-delphi.github.io/delphi-epidata/">Epidata API</a>, and directly via <a href="https://delphi.cmu.edu/epivis/">Epivis</a>, but is not yet available via this interface.</div>` +
104+
"</div>";
105+
}
99106
}
107+
100108
data += tableMarkup;
101109
} else {
102110
data = "<p>No available indicators yet.</p>";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.0.7 on 2025-05-05 19:33
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('indicators', '0004_alter_indicator_base'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='indicator',
15+
name='source_type',
16+
field=models.CharField(blank=True, choices=[('covidcast', 'Covidcast'), ('other_endpoint', 'Other Endpoint'), ('non_delphi', 'Non Delphi')], default='covidcast', help_text='Type of source for the indicator', max_length=255, null=True, verbose_name='Source Type'),
17+
),
18+
]

src/indicators/models.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
from django.db import models
55

66

7+
SOURCE_TYPES = [
8+
("covidcast", "Covidcast"),
9+
("other_endpoint", "Other Endpoint"),
10+
("non_delphi", "Non Delphi"),
11+
]
12+
13+
714
# Create your models here.
815
class IndicatorType(models.Model):
916

@@ -122,9 +129,7 @@ def display_name(self):
122129

123130
class Indicator(models.Model):
124131

125-
name: models.CharField = models.CharField(
126-
verbose_name="Name", max_length=255
127-
)
132+
name: models.CharField = models.CharField(verbose_name="Name", max_length=255)
128133
display_name: models.CharField = models.CharField(
129134
verbose_name="Display Name", max_length=255, blank=True
130135
)
@@ -380,6 +385,16 @@ class Indicator(models.Model):
380385
blank=True,
381386
)
382387

388+
source_type: models.CharField = models.CharField(
389+
verbose_name="Source Type",
390+
max_length=255,
391+
choices=SOURCE_TYPES,
392+
default="covidcast",
393+
help_text="Type of source for the indicator",
394+
blank=True,
395+
null=True,
396+
)
397+
383398
class Meta:
384399
verbose_name = "Indicator"
385400
verbose_name_plural = "Indicators"
@@ -397,7 +412,8 @@ class Meta:
397412
fields=["name", "source"], name="unique_indicator_name"
398413
),
399414
models.UniqueConstraint(
400-
fields=["name", "indicator_set"], name="unique_indicator_indicator_set_name"
415+
fields=["name", "indicator_set"],
416+
name="unique_indicator_indicator_set_name",
401417
),
402418
]
403419

src/indicators/resources.py

+12
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,10 @@ def before_import_row(self, row, **kwargs) -> None:
428428
def after_import_row(self, row, row_result, **kwargs):
429429
process_indicator_geography(row)
430430

431+
def after_save_instance(self, instance, row, **kwargs):
432+
instance.source_type = "covidcast"
433+
instance.save()
434+
431435
def skip_row(self, instance, original, row, import_validation_errors=None):
432436
if not row["Include in indicator app"]:
433437
return True
@@ -601,6 +605,10 @@ def skip_row(self, instance, original, row, import_validation_errors=None):
601605
def after_import_row(self, row, row_result, **kwargs):
602606
process_indicator_geography(row)
603607

608+
def after_save_instance(self, instance, row, **kwargs):
609+
instance.source_type = "other_endpoint"
610+
instance.save()
611+
604612

605613
class NonDelphiIndicatorResource(resources.ModelResource):
606614

@@ -633,3 +641,7 @@ def before_import_row(self, row, **kwargs) -> None:
633641
def skip_row(self, instance, original, row, import_validation_errors=None):
634642
if not row["Include in indicator app"]:
635643
return True
644+
645+
def after_save_instance(self, instance, row, **kwargs):
646+
instance.source_type = "non_delphi"
647+
instance.save()

src/indicatorsets/views.py

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def get_related_indicators(self, queryset, indicator_set_ids: list):
8989
"description": indicator.description if indicator.description else "",
9090
"member_description": indicator.member_description if indicator.member_description else indicator.description,
9191
"restricted": indicator.indicator_set.dua_required if indicator.indicator_set else "",
92+
"source_type": indicator.source_type,
9293
}
9394
)
9495
return related_indicators

src/staticfiles/js/indicatorSetsTable.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@ new DataTable.Buttons(table, {
4444
table.buttons(0, null).container().appendTo("#colvis");
4545

4646
function format(indicatorSetId, relatedIndicators, indicatorSetDescription) {
47-
console.lopg;
4847
var indicators = relatedIndicators.filter(
4948
(indicator) => indicator.indicator_set === indicatorSetId
5049
);
51-
var disabled, restricted;
50+
var disabled, restricted, sourceType;
5251

5352
if (indicators.length > 0) {
5453
var data = `<p style="width: 40%;">${indicatorSetDescription}</p>`;
@@ -71,6 +70,7 @@ function format(indicatorSetId, relatedIndicators, indicatorSetDescription) {
7170
var checkboxTitle = "";
7271
checked = checked ? "checked" : "";
7372
disabled = indicator.endpoint ? "" : "disabled";
73+
sourceType = indicator.source_type;
7474
var restricted = indicator.restricted != "No";
7575
if (disabled === "disabled") {
7676
checkboxTitle =
@@ -92,11 +92,19 @@ function format(indicatorSetId, relatedIndicators, indicatorSetDescription) {
9292
});
9393
tableMarkup += "</tbody></table>";
9494
if (disabled === "disabled" || restricted) {
95-
data +=
96-
`<div class="alert alert-warning" data-mdb-alert-init role="alert">` +
97-
` <div>This indicator set is available via the <a href="https://cmu-delphi.github.io/delphi-epidata/">Epidata API</a>, and directly via <a href="https://delphi.cmu.edu/epivis/">Epivis</a>, but is not yet available via this interface.</div>` +
98-
"</div>";
95+
if (sourceType === "non_delphi") {
96+
data +=
97+
`<div class="alert alert-warning" data-mdb-alert-init role="alert">` +
98+
` <div>This indicator set is not available via Delphi. It is included here for general discoverability only, and may or may not be available from the Original Data Provider.</div>` +
99+
"</div>";
100+
} else {
101+
data +=
102+
`<div class="alert alert-warning" data-mdb-alert-init role="alert">` +
103+
` <div>This indicator set is available via the <a href="https://cmu-delphi.github.io/delphi-epidata/">Epidata API</a>, and directly via <a href="https://delphi.cmu.edu/epivis/">Epivis</a>, but is not yet available via this interface.</div>` +
104+
"</div>";
105+
}
99106
}
107+
100108
data += tableMarkup;
101109
} else {
102110
data = "<p>No available indicators yet.</p>";

0 commit comments

Comments
 (0)