Skip to content

Commit

Permalink
Add script to map old list of activities to early action block
Browse files Browse the repository at this point in the history
  • Loading branch information
susilnem authored and k9845 committed Mar 25, 2024
1 parent 5dddd70 commit 59505e2
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions dref/management/commands/create_early_action_block.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.core.management.base import BaseCommand
from dref.models import ActivityTimeFrame, PlannedIntervention

from api.logger import logger

class Command(BaseCommand):
help = 'Convert Old PlannedIntervention description to early action block'

def handle(self, *args, **options):
logger.info("Creating early action blocks from planned interventions description")
interventions_to_create = []
for pi in PlannedIntervention.objects.filter(description__isnull=False):
if pi.description:
descriptions = pi.description.split('•')
for desc in descriptions[1:]:
activity_frame_title = desc.replace('\n', '').strip()
interventions_to_create.append(ActivityTimeFrame(title=activity_frame_title))
if interventions_to_create:
ActivityTimeFrame.objects.bulk_create(interventions_to_create)
pi.early_action_block.add(*interventions_to_create)
pi.description = None
pi.save()
logger.info(f"Created {len(interventions_to_create)} early action blocks for planned intervention")
if not interventions_to_create:
logger.info(f"No early action blocks created for planned intervention")

0 comments on commit 59505e2

Please sign in to comment.