5
5
from import_export import resources
6
6
from import_export .fields import Field , widgets
7
7
8
- from base .models import Link , LinkTypeChoices
8
+ from base .models import Link , LinkTypeChoices , License
9
9
from datasources .models import DataSource , SourceSubdivision
10
10
11
11
@@ -40,6 +40,7 @@ def before_import_row(self, row, **kwargs) -> None:
40
40
any additional links specified in 'DUA' or 'Link' columns.
41
41
"""
42
42
self .process_links (row )
43
+ self .process_licenses (row )
43
44
self .process_datasource (row )
44
45
45
46
def process_links (self , row ) -> None :
@@ -58,6 +59,13 @@ def process_links(self, row) -> None:
58
59
link , created = Link .objects .get_or_create (url = link_url , link_type = link_type )
59
60
row ['Links' ] += row ['Links' ] + f'|{ link .url } '
60
61
62
+ def process_licenses (self , row ) -> None :
63
+ if row ['License' ]:
64
+ license : License
65
+ created : bool
66
+ license , created = License .objects .get_or_create (name = row ['License' ])
67
+ row ['License' ] = license
68
+
61
69
def process_datasource (self , row ) -> None :
62
70
if row ['Name' ]:
63
71
data_source : DataSource
@@ -71,4 +79,6 @@ def process_datasource(self, row) -> None:
71
79
}
72
80
)
73
81
links : QuerySet [Link ] = Link .objects .filter (url__in = row ['Links' ].split ('|' )).values_list ('id' , flat = True )
82
+ license : License = License .objects .filter (name = row ['License' ]).first ()
74
83
data_source .links .add (* links )
84
+ data_source .source_license = license
0 commit comments