Skip to content

Commit

Permalink
Merge pull request #73 from cmu-delphi/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
dmytrotsko authored Dec 24, 2024
2 parents b25ca6e + f690ae5 commit 9ea9b60
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 27 deletions.
18 changes: 18 additions & 0 deletions src/signal_sets/migrations/0015_signalset_short_name.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
6 changes: 6 additions & 0 deletions src/signal_sets/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 13 additions & 1 deletion src/signal_sets/resources.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 *"
Expand All @@ -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) "
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/signal_sets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions src/signals/migrations/0008_signal_member_short_name.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
18 changes: 18 additions & 0 deletions src/signals/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."),
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/signals/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
25 changes: 0 additions & 25 deletions src/templates/signal_sets/signal_sets.html
Original file line number Diff line number Diff line change
Expand Up @@ -430,31 +430,6 @@ <h2 class="accordion-header" id="flush-heading_{{ form.data_source.auto_id }}">
}
}

{% 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 = {};

Expand Down

0 comments on commit 9ea9b60

Please sign in to comment.