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

Use the analysis:last-modified-at extra #2863

Merged
merged 11 commits into from
Jul 10, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Improve DCAT harvest of mime type [#2857](https://github.com/opendatateam/udata/pull/2857)
- Don't crash on files not found when purging resources [2858](https://github.com/opendatateam/udata/pull/2858)
- Use the resource's extra `analysis:last-modified-at` in the `last_modified` property [#2863](https://github.com/opendatateam/udata/pull/2863)
- Add optionnal harvest validation form [#2864](https://github.com/opendatateam/udata/pull/2864)
- Fix dataset list default sorting [#2867](https://github.com/opendatateam/udata/pull/2867)

Expand Down
2 changes: 2 additions & 0 deletions udata/core/dataset/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ def created_at(self):
def last_modified(self):
if self.harvest and self.harvest.modified_at and to_naive_datetime(self.harvest.modified_at) < datetime.utcnow():
return max([self.last_modified_internal, to_naive_datetime(self.harvest.modified_at)])
if self.filetype == 'remote' and self.extras.get('analysis:last-modified-at'):
return to_naive_datetime(self.extras.get('analysis:last-modified-at'))
return self.last_modified_internal

def clean(self):
Expand Down
7 changes: 7 additions & 0 deletions udata/tests/dataset/test_dataset_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,3 +689,10 @@ def test_harvest_resource_metadata_past_modifed_at(self):
resource.validate()

assert resource.last_modified == harvest_metadata.modified_at

def test_resource_metadata_extra_modifed_at(self):
resource = ResourceFactory(filetype='remote')
resource.extras.update({'analysis:last-modified-at': datetime(2023,1,1)})
resource.validate()

assert resource.last_modified == resource.extras['analysis:last-modified-at']