Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add missing checklists loader #187

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import uuid
import time
import typer
import json

from pathlib import Path

from support_sphere.models.public import (UserProfile, People, Cluster, PeopleGroup, Household,
RolePermission, UserRole, UserCaptainCluster, SignupCode,
ResourceType, ResourceCV, Resource)
ResourceType, ResourceCV, Resource, Checklist, ChecklistStep,
ChecklistStepsOrder)
from support_sphere.models.auth import User
from support_sphere.repositories.auth import UserRepository
from support_sphere.repositories.base_repository import BaseRepository
Expand Down Expand Up @@ -113,6 +115,26 @@ def populate_user_details():
BaseRepository.add(people_group)
logger.info("Database Populated Successfully")

def populate_checklists():
"""
Populate checklists to the database.
"""
file_path = DATA_DIRECTORY / 'checklists.json'
with open(file_path) as f:
data = json.load(f)

for ch in data['checklists']:
checklist = Checklist(
title=ch['title'],
description=ch['purpose']
)
BaseRepository.add(checklist)
for idx, st in enumerate(ch['steps']):
step = ChecklistStep(label=st['step'], description=st['description'])
BaseRepository.add(step)
step_order = ChecklistStepsOrder(checklist_id=checklist.id, checklist_step_id=step.id, priority=idx)
BaseRepository.add(step_order)


@db_init_app.command(help="Setup a dummy cluster and a household")
def populate_cluster_and_household_details():
Expand Down Expand Up @@ -260,6 +282,7 @@ def test_unauthorized_app_mode_update():
def setup_utility_resources():
resource_type_uids = populate_resource_types()
populate_resources(resource_type_uids=resource_type_uids)
populate_checklists()


@db_init_app.command(help="Command to setup the database with dummy users, roles, and permissions")
Expand Down