diff --git a/geospaas/catalog/migrations/0009_auto_20201012_0905.py b/geospaas/catalog/migrations/0009_auto_20201012_0905.py new file mode 100644 index 00000000..854273b5 --- /dev/null +++ b/geospaas/catalog/migrations/0009_auto_20201012_0905.py @@ -0,0 +1,27 @@ +# Generated by Django 3.0.6 on 2020-10-12 09:05 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('vocabularies', '0004_auto_20200331_0806'), + ('catalog', '0008_auto_20200331_0806'), + ] + + operations = [ + migrations.RemoveField( + model_name='dataset', + name='parameters', + field=models.ManyToManyField(to='vocabularies.Parameter'), + ), + migrations.DeleteModel( + name='DatasetParameter', + ), + migrations.AddField( + model_name='dataset', + name='parameters', + field=models.ManyToManyField(to='vocabularies.Parameter'), + ), + ] diff --git a/geospaas/catalog/models.py b/geospaas/catalog/models.py index 87e645fc..9bd36490 100644 --- a/geospaas/catalog/models.py +++ b/geospaas/catalog/models.py @@ -144,7 +144,7 @@ class Dataset(models.Model): ] ) entry_title = models.CharField(max_length=220) - parameters = models.ManyToManyField(Parameter, through='DatasetParameter') + parameters = models.ManyToManyField(Parameter) ISO_topic_category = models.ForeignKey(ISOTopicCategory, on_delete=models.CASCADE) data_center = models.ForeignKey(DataCenter, on_delete=models.CASCADE) summary = models.TextField() @@ -174,12 +174,6 @@ def __str__(self): # temporal_resolution = models.CharField(max_length=220) # temporal_resolution_range = models.ForeignKey(TemporalDataResolution) -class DatasetParameter(models.Model): - dataset = models.ForeignKey(Dataset, on_delete=models.CASCADE) - parameter = models.ForeignKey(Parameter, on_delete=models.CASCADE) - - def __str__(self): - return '%s:%s' %(self.dataset, self.parameter) class DatasetURI(models.Model): diff --git a/geospaas/catalog/tests.py b/geospaas/catalog/tests.py index 77a3775b..aaea4e26 100644 --- a/geospaas/catalog/tests.py +++ b/geospaas/catalog/tests.py @@ -122,19 +122,6 @@ def test_entry_id_is_correct(self): ds.full_clean() self.assertEqual(ds.entry_id, id) - def test_search_datasets(self): - ''' Shall add one parameter to the first dataset - shall find one Dataset without sst ''' - dataset1 = Dataset.objects.get(pk=1) - p = Parameter.objects.get( - standard_name='sea_surface_temperature') - dp = DatasetParameter(dataset=dataset1, parameter=p) - dp.save() - dsearch = Dataset.objects.filter( source__instrument__short_name = - 'MODIS') - dsearch = dsearch.exclude(datasetparameter__parameter__short_name = - 'SST' ) - self.assertEqual(dsearch.count(), 1) class DatasetURITests(TestCase): @@ -152,20 +139,6 @@ def test_DatasetURI_created(self, mock_isfile): self.assertEqual(dsuri.uri, uri) - -class DatasetParameterTests(TestCase): - - fixtures = ["vocabularies", "catalog"] - - def test_add_sar_sigma0(self): - ds = Dataset.objects.get(pk=1) - p = Parameter.objects.get( - standard_name='surface_backwards_scattering_coefficient_of_radar_wave', - short_name='sigma0') - dp = DatasetParameter(dataset=ds, parameter=p) - dp.save() - self.assertEqual(dp.parameter.short_name, 'sigma0') - class DatasetRelationshipTests(TestCase): fixtures = ["vocabularies", "catalog"] @@ -181,6 +154,7 @@ def test_variable(self): dr.save() self.assertEqual(dr.child.source, dr.parent.source) + class GeographicLocationTests(TestCase): def test_geographiclocation(self): ''' Shall create GeographicLocation instance ''' @@ -210,17 +184,18 @@ def test__reproduce__not_null_constraint_failed(self): self.assertFalse(created) # Conclusion: db can't handle numbers with too many decimals (NOT NULL constraint failed) -class PersonnelTests(TestCase): +class PersonnelTests(TestCase): ''' We should add user admin with, e.g., with the Personnel model. Skip testing before that is in place ''' pass -class RoleTests(TestCase): +class RoleTests(TestCase): pass + class SourceTests(TestCase): fixtures = ["vocabularies"] diff --git a/geospaas/nansat_ingestor/managers.py b/geospaas/nansat_ingestor/managers.py index c03efb5c..c7d00cc7 100644 --- a/geospaas/nansat_ingestor/managers.py +++ b/geospaas/nansat_ingestor/managers.py @@ -7,7 +7,7 @@ from django.db import models from geospaas.catalog.managers import FILE_SERVICE_NAME, LOCAL_FILE_SERVICE -from geospaas.catalog.models import (Dataset, DatasetParameter, DatasetURI, +from geospaas.catalog.models import (Dataset, DatasetURI, GeographicLocation, Source) from geospaas.utils.utils import nansat_filename, validate_uri from geospaas.vocabularies.models import (DataCenter, Instrument, @@ -132,7 +132,7 @@ def get_or_create(self, geometry=WKTReader().read(n.get_border_wkt(nPoints=n_points)))[0] # create dataset - # - the get_or_create method should use get_or_create here as well, + # - the get_or_create method should use get_or_create here as well, # or its name should be changed - see issue #127 ds, created = Dataset.objects.update_or_create(entry_id=options['entry_id'], defaults={ 'time_coverage_start': n.get_metadata('time_coverage_start'), @@ -161,8 +161,6 @@ def get_or_create(self, if params.count() > 1 and units is not None: params = params.filter(units=units) if params.count() >= 1: - DatasetParameter.objects.get_or_create( - dataset=ds, parameter=params[0]) ds.parameters.add(params[0]) # create dataset URI diff --git a/geospaas/nansat_ingestor/tests.py b/geospaas/nansat_ingestor/tests.py index 10807255..616ad1c2 100644 --- a/geospaas/nansat_ingestor/tests.py +++ b/geospaas/nansat_ingestor/tests.py @@ -174,7 +174,7 @@ def test_getorcreate_localfile_filtering_base_on_parameter(self): self.predefined_band_metadata_dict[2]['standard_name']) def test_dont_add_longitude_latitude(self): - """ shall not add latitude and longitude into DatasetParameter table """ + """ shall not add latitude and longitude into Parameters of Dataset table """ uri = 'file://localhost/some/folder/filename.ext' ds0, _ = Dataset.objects.get_or_create(uri) ds_params_standard_names = ds0.parameters.values_list('standard_name', flat=True) @@ -184,7 +184,7 @@ def test_dont_add_longitude_latitude(self): self.assertNotIn('latidtude', ds_params_standard_names) def test_add_sigma0_gamma0(self): - """ shall add both sigma0 and gamma0 with same standard name into DatasetParameter table """ + """ shall add both sigma0 and gamma0 with same standard name into Parameters of Dataset table """ uri = 'file://localhost/some/folder/filename.ext' ds0, _ = Dataset.objects.get_or_create(uri) ds_params_standard_names = ds0.parameters.values_list('standard_name', flat=True)