Coverage for formkit_ninja/management/commands/import_forms.py: 0%

1 from django.core.management.base import BaseCommand

2

3 from formkit_ninja import models

4 from formkit_ninja.formkit_schema import FormKitNode, GroupNode

5 from formkit_ninja.schemas import Schemas

6

7

8 class Command(BaseCommand):

9 help = "Load all the Partisipa forms to the database"

10

11 def handle(self, *args, **options):

12 models.FormComponents.objects.all().delete()

13 models.FormKitSchema.objects.all().delete()

14 models.FormKitSchemaNode.objects.all().delete()

15 models.Option.objects.all().delete()

16 models.OptionGroup.objects.all().delete()

17

18 schemas = Schemas()

19 for schema_name in schemas.list_schemas():

20 # Each part of the form becomes a 'Schema'

21 schema = schemas.as_json(schema_name)

22 node: FormKitNode = FormKitNode.parse_obj(schema)

23 parsed_node: GroupNode = node.__root__

24 list(models.FormKitSchemaNode.from_pydantic(parsed_node))[0]