Skip to content

Okrs24 115 add new fields to the signals app #98

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
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
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ services:
python3 /usr/src/signal_documentation/src/manage.py loaddata ./fixtures/pathogens.json &&
python3 /usr/src/signal_documentation/src/manage.py loaddata ./fixtures/signal_types.json &&
python3 /usr/src/signal_documentation/src/manage.py loaddata ./fixtures/signal_categories.json &&
python3 /usr/src/signal_documentation/src/manage.py loaddata ./fixtures/demographic_scopes.json &&
python3 /usr/src/signal_documentation/src/manage.py loaddata ./fixtures/county.json &&
python3 /usr/src/signal_documentation/src/manage.py loaddata ./fixtures/hhs.json &&
python3 /usr/src/signal_documentation/src/manage.py loaddata ./fixtures/hrr.json &&
Expand Down
10 changes: 10 additions & 0 deletions src/base/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
DescriptedFilter,
DescriptedFilterField,
Link,
License
)


Expand All @@ -27,3 +28,12 @@ class LinkAdmin(admin.ModelAdmin):
Admin interface for managing link objects.
"""
list_display: tuple[Literal['url'], Literal['link_type']] = ('url', 'link_type')


@admin.register(License)
class GeographyAdmin(admin.ModelAdmin):
"""
Admin interface for managing license objects.
"""
list_display: tuple[Literal['name'], Literal['use_restrictions']] = ('name', 'use_restrictions')
search_fields: tuple[Literal['name']] = ('name',)
21 changes: 21 additions & 0 deletions src/base/migrations/0004_license.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 4.2.10 on 2024-06-07 12:15

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('base', '0003_descriptedfilter_alter_link_link_type_and_more'),
]

operations = [
migrations.CreateModel(
name='License',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(help_text='License', max_length=256, unique=True)),
('use_restrictions', models.TextField(blank=True, help_text='Use Restrictions', null=True)),
],
),
]
17 changes: 17 additions & 0 deletions src/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,20 @@ def get_preview(self) -> LinkPreview:
return {
'description': _('No description available'),
}


class License(models.Model):
"""
A model representing a License.
"""
name: models.CharField = models.CharField(help_text=_('License'), max_length=256, unique=True)
use_restrictions: models.TextField = models.TextField(help_text=_('Use Restrictions'), blank=True, null=True)

def __str__(self) -> str:
"""
Returns the name of the license as a string.

:return: The name of the license as a string.
:rtype: str
"""
return self.name
20 changes: 20 additions & 0 deletions src/datasources/migrations/0006_alter_datasource_source_license.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.2.10 on 2024-06-07 12:15

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


class Migration(migrations.Migration):

dependencies = [
('base', '0004_license'),
('datasources', '0005_sourcesubdivision_external_name'),
]

operations = [
migrations.AlterField(
model_name='datasource',
name='source_license',
field=models.ForeignKey(help_text='License', on_delete=django.db.models.deletion.PROTECT, related_name='source_license', to='base.license'),
),
]
20 changes: 20 additions & 0 deletions src/datasources/migrations/0007_alter_datasource_source_license.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.2.10 on 2024-06-07 12:47

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


class Migration(migrations.Migration):

dependencies = [
('base', '0004_license'),
('datasources', '0006_alter_datasource_source_license'),
]

operations = [
migrations.AlterField(
model_name='datasource',
name='source_license',
field=models.ForeignKey(help_text='License', null=True, on_delete=django.db.models.deletion.PROTECT, related_name='data_sources', to='base.license'),
),
]
9 changes: 7 additions & 2 deletions src/datasources/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,15 @@ class DataSource(TimeStampedModel):
null=True,
blank=True
)
source_license: models.CharField = models.CharField(

source_license: models.ForeignKey = models.ForeignKey(
'base.License',
related_name='data_sources',
help_text=_('License'),
max_length=128
on_delete=models.PROTECT,
null=True
)

links: models.ManyToManyField = models.ManyToManyField(
'base.Link',
help_text=_('DataSource links'),
Expand Down
12 changes: 11 additions & 1 deletion src/datasources/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from import_export import resources
from import_export.fields import Field, widgets

from base.models import Link, LinkTypeChoices
from base.models import Link, LinkTypeChoices, License
from datasources.models import DataSource, SourceSubdivision


Expand Down Expand Up @@ -40,6 +40,7 @@ def before_import_row(self, row, **kwargs) -> None:
any additional links specified in 'DUA' or 'Link' columns.
"""
self.process_links(row)
self.process_licenses(row)
self.process_datasource(row)

def process_links(self, row) -> None:
Expand All @@ -58,6 +59,13 @@ def process_links(self, row) -> None:
link, created = Link.objects.get_or_create(url=link_url, link_type=link_type)
row['Links'] += row['Links'] + f'|{link.url}'

def process_licenses(self, row) -> None:
if row['License']:
license: License
created: bool
license, created = License.objects.get_or_create(name=row['License'])
row['License'] = license

def process_datasource(self, row) -> None:
if row['Name']:
data_source: DataSource
Expand All @@ -71,4 +79,6 @@ def process_datasource(self, row) -> None:
}
)
links: QuerySet[Link] = Link.objects.filter(url__in=row['Links'].split('|')).values_list('id', flat=True)
license: License = License.objects.filter(name=row['License']).first()
data_source.links.add(*links)
data_source.source_license = license
47 changes: 47 additions & 0 deletions src/fixtures/demographic_scopes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[
{
"model": "signals.DemographicScope",
"pk": 1,
"fields": {
"name": "nationwide Change Healthcare network",
"created": "2022-01-01T00:00:00Z",
"modified": "2022-01-01T00:00:00Z"
}
},
{
"model": "signals.DemographicScope",
"pk": 2,
"fields": {
"name": "nationwide Optum network",
"created": "2022-01-01T00:00:00Z",
"modified": "2022-01-01T00:00:00Z"
}
},
{
"model": "signals.DemographicScope",
"pk": 3,
"fields": {
"name": "Adult Facebook users",
"created": "2022-01-01T00:00:00Z",
"modified": "2022-01-01T00:00:00Z"
}
},
{
"model": "signals.DemographicScope",
"pk": 4,
"fields": {
"name": "Google search users",
"created": "2022-01-01T00:00:00Z",
"modified": "2022-01-01T00:00:00Z"
}
},
{
"model": "signals.DemographicScope",
"pk": 5,
"fields": {
"name": "Smartphone users",
"created": "2022-01-01T00:00:00Z",
"modified": "2022-01-01T00:00:00Z"
}
}
]
20 changes: 20 additions & 0 deletions src/signals/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
from import_export.admin import ImportExportModelAdmin

from signals.models import (
DemographicScope,
Geography,
GeographyUnit,
Pathogen,
Signal,
SignalCategory,
SignalType,
GeographySignal,
)
from signals.resources import SignalBaseResource, SignalResource

Expand Down Expand Up @@ -41,6 +43,15 @@ class GeographyAdmin(admin.ModelAdmin):
search_fields: tuple[Literal['name']] = ('name',)


@admin.register(GeographySignal)
class GeographySignalAdmin(admin.ModelAdmin):
"""
Admin interface for managing signal geography objects.
"""
list_display: tuple[Literal['geography']] = ('geography', 'signal', 'aggregated_by_delphi')
search_fields: tuple[Literal['geography']] = ('geography', 'signal', 'aggregated_by_delphi')


@admin.register(Pathogen)
class PathogenAdmin(admin.ModelAdmin):
"""
Expand All @@ -59,6 +70,15 @@ class SignalTypeAdmin(admin.ModelAdmin):
search_fields: tuple[Literal['name']] = ('name',)


@admin.register(DemographicScope)
class DemographicScopeAdmin(admin.ModelAdmin):
"""
Admin interface for managing demographic scope objects.
"""
list_display: tuple[Literal['name']] = ('name',)
search_fields: tuple[Literal['name']] = ('name',)


@admin.register(Signal)
class SignalAdmin(ImportExportModelAdmin):
"""
Expand Down
Loading
Loading