Skip to content
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

Temporal coverage with only start date #3040

Closed
wants to merge 3 commits into from
Closed
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
6 changes: 2 additions & 4 deletions udata/core/dataset/api_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,8 @@
resources_order = api.as_list(fields.String(description='Resource ID'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also support it in rdf (import/export)


temporal_coverage_fields = api.model('TemporalCoverage', {
'start': fields.ISODateTime(description='The temporal coverage start date',
required=True),
'end': fields.ISODateTime(description='The temporal coverage end date',
required=True),
'start': fields.ISODateTime(description='The temporal coverage start date', required=True),
'end': fields.ISODateTime(description='The temporal coverage end date'),
})

dataset_ref_fields = api.inherit('DatasetReference', base_reference, {
Expand Down
14 changes: 11 additions & 3 deletions udata/forms/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,14 +695,22 @@ def process_formdata(self, valuelist):
value = valuelist[0]
if isinstance(value, str):
start, end = value.split(' - ')
if end is not None:
end = parse(end, yearfirst=True).date()

self.data = db.DateRange(
start=parse(start, yearfirst=True).date(),
end=parse(end, yearfirst=True).date(),
end=end,
)
elif 'start' in value and 'end' in value:
elif 'start' in value:
if value.get('end', None):
end = parse(value['end'], yearfirst=True).date()
else:
end = None

self.data = db.DateRange(
start=parse(value['start'], yearfirst=True).date(),
end=parse(value['end'], yearfirst=True).date(),
end=end,
)
else:
raise validators.ValidationError(
Expand Down
26 changes: 26 additions & 0 deletions udata/tests/api/test_datasets_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,32 @@ def test_dataset_api_update_deleted(self):
self.assertEqual(Dataset.objects.first().description,
dataset.description)


def test_update_temporal_coverage(self):
user = self.login()
dataset = DatasetFactory(owner=user)
data = dataset.to_dict()
data['temporal_coverage'] = {
'start': '2024-01-01',
'end': '2024-01-31',
}
response = self.put(url_for('api.dataset', dataset=dataset), data)
self.assert200(response)

dataset.reload()
self.assertEqual('2024-01-01', str(dataset.temporal_coverage.start))
self.assertEqual('2024-01-31', str(dataset.temporal_coverage.end))

data = dataset.to_dict()
data['temporal_coverage'] = { 'start': '2024-01-01', 'end': None }
response = self.put(url_for('api.dataset', dataset=dataset), data)
self.assert200(response)

dataset.reload()
self.assertEqual('2024-01-01', str(dataset.temporal_coverage.start))
self.assertIsNone(dataset.temporal_coverage.end)


def test_dataset_api_update_contact_point(self):
'''It should update a dataset from the API'''
self.login()
Expand Down