Skip to content

Commit

Permalink
Merge pull request #10 from acdh-oeaw/migrate-notes-to-comments
Browse files Browse the repository at this point in the history
Migrate notes to comments
  • Loading branch information
gythaogg authored Apr 23, 2024
2 parents fc8ec69 + 376525d commit e0284c9
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions apis_ontology/management/commands/migrate_notes_to_comments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import logging
import pandas as pd
from django.core.management.base import BaseCommand
from apis_ontology.models import Person, Place, Work, Instance

logger = logging.getLogger(__name__)
pd.set_option("display.max_colwidth", None)


class Command(BaseCommand):
"""
Migrates values from Legacy Notes field to Comments
for Person, Place, Instance and Work objects
"""

def handle(self, *args, **kwargs):
"""
copies values from Notes to Comments
"""

def copy_to_comments(obj):
if not obj.notes:
return

logging.debug("Copying notes for obj [%s]: %s", obj.pk, obj.notes)

if not obj.comments:
obj.comments = ""
else:
obj.comments += "\n"
logging.debug("Existing comments: %s", obj.comments)

obj.comments += obj.notes
obj.notes = ""
obj.save()
logging.debug("Saved obj %s", obj.pk)

for obj in Person.objects.all():
copy_to_comments(obj)

for obj in Place.objects.all():
copy_to_comments(obj)

for obj in Work.objects.all():
copy_to_comments(obj)

for obj in Instance.objects.all():
copy_to_comments(obj)

0 comments on commit e0284c9

Please sign in to comment.