diff --git a/src/signal_sets/migrations/0015_signalset_short_name.py b/src/signal_sets/migrations/0015_signalset_short_name.py new file mode 100644 index 0000000..1d4b272 --- /dev/null +++ b/src/signal_sets/migrations/0015_signalset_short_name.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.7 on 2024-12-24 10:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('signal_sets', '0014_signalset_endpoint'), + ] + + operations = [ + migrations.AddField( + model_name='signalset', + name='short_name', + field=models.CharField(blank=True, max_length=255, verbose_name='Signal Set short name'), + ), + ] diff --git a/src/signal_sets/models.py b/src/signal_sets/models.py index 7ec7eeb..d5e62c6 100644 --- a/src/signal_sets/models.py +++ b/src/signal_sets/models.py @@ -40,6 +40,12 @@ class SignalSet(models.Model): unique=True, ) + short_name: models.CharField = models.CharField( + verbose_name="Signal Set short name", + max_length=255, + blank=True, + ) + description: models.TextField = models.TextField( verbose_name="Signal Set description", blank=True, diff --git a/src/signal_sets/resources.py b/src/signal_sets/resources.py index 78a9c4b..5c727a6 100644 --- a/src/signal_sets/resources.py +++ b/src/signal_sets/resources.py @@ -1,4 +1,6 @@ from typing import Any +from django.db import IntegrityError, transaction + from import_export import resources from import_export.fields import Field, widgets @@ -82,6 +84,7 @@ def fix_boolean_fields(row) -> Any: class SignalSetResource(resources.ModelResource): name = Field(attribute="name", column_name="Signal Set name* ") + short_name = Field(attribute="short_name", column_name="Signal Set Short Name") description = Field(attribute="description", column_name="Signal Set Description*") maintainer_name = Field( attribute="maintainer_name", column_name="Maintainer/\nKey Contact *" @@ -95,6 +98,7 @@ class SignalSetResource(resources.ModelResource): column_name="Data Source", widget=widgets.ForeignKeyWidget(DataSource, field="name"), ) + endpoint = Field(attribute="endpoint", column_name="Endpoint") language = Field(attribute="language", column_name="Language (likely English) ") version_number = Field( attribute="version_number", column_name="Version Number \n(if applicable) " @@ -154,12 +158,12 @@ class SignalSetResource(resources.ModelResource): link_to_documentation = Field( attribute="link_to_documentation", column_name="Link to documentation" ) - endpoint = Field(attribute="endpoint", column_name="Endpoint") class Meta: model = SignalSet fields: list[str] = [ "name", + "short_name", "description", "maintainer_name", "maintainer_email", @@ -190,6 +194,7 @@ class Meta: ] import_id_fields = ["name", "data_source"] store_instance = True + skip_unchanged = True def before_import_row(self, row, **kwargs): fix_boolean_fields(row) @@ -199,6 +204,13 @@ def before_import_row(self, row, **kwargs): process_avaliable_geographies(row) process_datasources(row) + def save_instance(self, instance, is_create, row, **kwargs): + try: + with transaction.atomic(): + return super().save_instance(instance, is_create, row, **kwargs) + except IntegrityError: + pass + def skip_row(self, instance, original, row, import_validation_errors=None): if not row["Include in signal app"]: return True diff --git a/src/signal_sets/views.py b/src/signal_sets/views.py index 41480b0..7a781b7 100644 --- a/src/signal_sets/views.py +++ b/src/signal_sets/views.py @@ -66,7 +66,7 @@ def get_related_signals(self): related_signals.append( { "id": signal.id, - "display_name": signal.display_name, + "display_name": signal.get_display_name, "name": signal.name, "signal_set": signal_set.id, "signal_set_name": signal_set.name, diff --git a/src/signals/migrations/0008_signal_member_short_name.py b/src/signals/migrations/0008_signal_member_short_name.py new file mode 100644 index 0000000..9c964f6 --- /dev/null +++ b/src/signals/migrations/0008_signal_member_short_name.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.7 on 2024-12-24 10:57 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('signals', '0007_signal_member_description_signal_member_name'), + ] + + operations = [ + migrations.AddField( + model_name='signal', + name='member_short_name', + field=models.CharField(blank=True, help_text='Member short name of the signal.', max_length=255, null=True, verbose_name='member short name'), + ), + ] diff --git a/src/signals/models.py b/src/signals/models.py index c55957e..28ace69 100644 --- a/src/signals/models.py +++ b/src/signals/models.py @@ -239,6 +239,13 @@ class Signal(TimeStampedModel): null=True, blank=True ) + member_short_name: models.CharField = models.CharField( + max_length=255, + verbose_name=_("member short name"), + help_text=_("Member short name of the signal."), + null=True, + blank=True + ) member_description: models.TextField = models.TextField( verbose_name=_("member description"), help_text=_("Member description of the signal."), @@ -506,6 +513,17 @@ def clean(self) -> None: if Signal.objects.exists() and not self.base: raise ValidationError(_("Signal should have base.")) + @property + def get_display_name(self): + if self.member_short_name: + return self.member_short_name + if self.member_name: + return self.member_name + if self.display_name: + return self.display_name + else: + return self.name + class SignalsDbView(models.Model): id = models.BigIntegerField(primary_key=True) diff --git a/src/signals/resources.py b/src/signals/resources.py index 4c77b0b..14879a5 100644 --- a/src/signals/resources.py +++ b/src/signals/resources.py @@ -226,6 +226,7 @@ class SignalResource(ModelResource): name = Field(attribute="name", column_name="Signal") display_name = Field(attribute="display_name", column_name="Name") member_name = Field(attribute="member_name", column_name="Member Name") + member_short_name = Field(attribute="member_short_name", column_name="Member Short Name") member_description = Field( attribute="member_description", column_name="Member Description" ) diff --git a/src/templates/signal_sets/signal_sets.html b/src/templates/signal_sets/signal_sets.html index eced0ad..502593c 100644 --- a/src/templates/signal_sets/signal_sets.html +++ b/src/templates/signal_sets/signal_sets.html @@ -430,31 +430,6 @@

} } - {% comment %} let dataSignals = Array.from(document.getElementsByName('selectedSignal')); - dataSignals.forEach((checkbox) => { - checkbox.addEventListener('change', function(event) { - if (this.checked) { - checkedSignalMembers.push({ - _endpoint: this.dataset.endpoint, - data_source: this.dataset.datasource, - signal: this.dataset.signal, - time_type: this.dataset.timeType, - }); - updateSelectedSignals(this.dataset.datasource, this.dataset.signal, this.dataset.signalset); - } else { - checkedSignalMembers = checkedSignalMembers.filter(signal => signal.signal !== this.dataset.signal); - document.getElementById(`${this.dataset.datasource}_${this.dataset.signal}`).remove(); - } - - - if (checkedSignalMembers.length > 0) { - $("#showSelectedSignalsButton").show(); - } else { - $("#showSelectedSignalsButton").hide(); - } - }); - }); {% endcomment %} - function plotData(epivisUrl) { var dataSets = {};