-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from acdh-oeaw/migrate-notes-to-comments
Migrate notes to comments
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
apis_ontology/management/commands/migrate_notes_to_comments.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |