RockefellerArchiveCenter / aurora

A Django web application to receive, virus check and validate transfers of digital archival records, and allow archivists to appraise and accession those records.
http://projectelectron.rockarch.org/
MIT License
25 stars 6 forks source link

Change datetime fields to date fields in BagInfoMetadata model #636

Closed helrond closed 8 months ago

helrond commented 8 months ago

This PR is from @McDaPick for Issue #506

After updating the date_start and date_end fields in the BagInfoMetadata model from

date_start = models.DateTimeField()
date_end = models.DateTimeField()

to

date_start = models.DateField()
date_end = models.DateField()

and running a migration, the date was being saved as one day earlier than what was in the bag-info file.

Transfer's Bag Info:

External Identifier: records-2017-12-11T20:09:48.238148 BagIt-Profile-Identifier: http://localhost:8000/api/bagit_profiles/2/ Bagging-Date: 2017-12-11T20:09:48.238148 Date-End: 2005-06-22 Date-Start: 2003-05-14

The Transfer's data through the Django shell after being imported:

>>> from bag_transfer.models import BagInfoMetadata
>>> x = BagInfoMetadata.objects.get(external_identifier="records-2017-12-11T20:09:48.238148")
>>> print(x.date_end)
2005-06-21
>>> print(x.date_start)
2003-05-13

Inside of the Transfer's detail view:

image

After reading @helrond comment about timezone/daylight, I started to take a look around and saw that config.py has the time zone set as America/New_York on line 15.

DJANGO_TIME_ZONE = "America/New_York"  # TZ database name for local timezone (string)

Updating this value to UTC allowed for the date_fieldto save correctly.

DJANGO_TIME_ZONE = "UTC"  # TZ database name for local timezone (string)

Transfer's Bag Info:

External Identifier: records-2017-12-11T20:09:48.238148 BagIt-Profile-Identifier: http://localhost:8000/api/bagit_profiles/2/ Bagging-Date: 2017-12-11T20:09:48.238148 Date-End: 2005-06-22 Date-Start: 2003-05-14

The Transfer's data through the Django shell after DJANGO_TIME_ZONE was updated:

>>> from bag_transfer.models import BagInfoMetadata
>>> x = BagInfoMetadata.objects.get(external_identifier="records-2017-12-11T20:09:48.238148")
>>> print(x.date_end)
2005-06-22
>>> print(x.date_start)
2003-05-14

Inside of the Transfer's detail view:

image

Side Note:

This update to the DJANGO_TIME_ZONE also seems to fix the bagging_date time being fives hours off of its value in bag-data.

helrond commented 8 months ago

OK @McDaPick I had to do a few additional things to get this to pass CI:

If you're good with this I can push this through development and into base.

McDaPick commented 8 months ago

Hi @helrond !

Thank you so much, that sounds great to me. I'll make a note of the updates you made for the future.

Let me know if I can lend a hand anywhere else!