Skip to content
Snippets Groups Projects
Commit c13195b3 authored by Fredrik Jonsson's avatar Fredrik Jonsson
Browse files

Disable auto_* on date fields so imported dates are used.

parent 4b878dc8
No related branches found
No related tags found
No related merge requests found
...@@ -39,6 +39,10 @@ class Command(BaseCommand): ...@@ -39,6 +39,10 @@ class Command(BaseCommand):
type='comment', type='comment',
visibility='internal', visibility='internal',
) )
# Disable auto_* on date fields so imported dates are used.
for field in activity._meta.local_fields:
if field.name == "timestamp":
field.auto_now_add = False
try: try:
activity.save() activity.save()
self.stdout.write(f"Processed \"{comment['subject']}\" ({comment['cid']})") self.stdout.write(f"Processed \"{comment['subject']}\" ({comment['cid']})")
......
...@@ -67,6 +67,13 @@ class Command(BaseCommand): ...@@ -67,6 +67,13 @@ class Command(BaseCommand):
except Determination.DoesNotExist: except Determination.DoesNotExist:
determination = Determination(drupal_id=node['nid']) determination = Determination(drupal_id=node['nid'])
# Disable auto_* on date fields so imported dates are used.
for field in determination._meta.local_fields:
if field.name == "created_at":
field.auto_now_add = False
elif field.name == "updated_at":
field.auto_now = False
# TODO timezone? # TODO timezone?
determination.created_at = datetime.fromtimestamp(int(node['created']), timezone.utc) determination.created_at = datetime.fromtimestamp(int(node['created']), timezone.utc)
determination.updated_at = datetime.fromtimestamp(int(node['changed']), timezone.utc) determination.updated_at = datetime.fromtimestamp(int(node['changed']), timezone.utc)
......
...@@ -119,6 +119,13 @@ class Command(BaseCommand): ...@@ -119,6 +119,13 @@ class Command(BaseCommand):
except Determination.DoesNotExist: except Determination.DoesNotExist:
determination = Determination(drupal_id=node['nid']) determination = Determination(drupal_id=node['nid'])
# Disable auto_* on date fields so imported dates are used.
for field in determination._meta.local_fields:
if field.name == "created_at":
field.auto_now_add = False
elif field.name == "updated_at":
field.auto_now = False
# TODO timezone? # TODO timezone?
determination.created_at = datetime.fromtimestamp(int(node['created']), timezone.utc) determination.created_at = datetime.fromtimestamp(int(node['created']), timezone.utc)
determination.updated_at = datetime.fromtimestamp(int(node['changed']), timezone.utc) determination.updated_at = datetime.fromtimestamp(int(node['changed']), timezone.utc)
...@@ -202,6 +209,9 @@ class Command(BaseCommand): ...@@ -202,6 +209,9 @@ class Command(BaseCommand):
return value return value
def get_user(self, uid): def get_user(self, uid):
# Dan Blah hade one admin account uid 52, all should be set up uid 2 in new system.
if uid == '52':
uid = '2'
try: try:
User = get_user_model() User = get_user_model()
return User.objects.get(drupal_id=uid) return User.objects.get(drupal_id=uid)
......
...@@ -80,6 +80,11 @@ class MigrateCommand(BaseCommand): ...@@ -80,6 +80,11 @@ class MigrateCommand(BaseCommand):
except ApplicationSubmission.DoesNotExist: except ApplicationSubmission.DoesNotExist:
submission = ApplicationSubmission(drupal_id=node['nid']) submission = ApplicationSubmission(drupal_id=node['nid'])
# Disable auto_* on date fields so imported dates are used.
for field in submission._meta.local_fields:
if field.name == "submit_time":
field.auto_now_add = False
# TODO timezone? # TODO timezone?
submission.submit_time = datetime.fromtimestamp(int(node['created']), timezone.utc) submission.submit_time = datetime.fromtimestamp(int(node['created']), timezone.utc)
submission.user = self.get_user(node['uid']) submission.user = self.get_user(node['uid'])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment