|
2 | 2 |
|
3 | 3 | from open_inwoner.openzaak.models import ZGWApiGroupConfig |
4 | 4 | from open_inwoner.openzaak.zgw_imports import ( |
5 | | - import_catalog_configs, |
6 | | - import_zaaktype_configs, |
7 | | - import_zaaktype_informatieobjecttype_configs, |
8 | | - import_zaaktype_resultaattype_configs, |
9 | | - import_zaaktype_statustype_configs, |
| 5 | + ZGWCatalogusImporter, |
10 | 6 | ) |
11 | 7 |
|
12 | 8 |
|
13 | 9 | class Command(BaseCommand): |
14 | 10 | help = "Import ZGW catalog data" |
15 | 11 |
|
16 | | - def log_supplement_imports_to_stdout( |
17 | | - self, import_func: callable, config_type: str |
18 | | - ) -> None: |
19 | | - """ |
20 | | - Convenience function for logging zaaktype config types to stdout |
21 | | -
|
22 | | - Example input: |
23 | | - import_func=import_zaaktype_informatieobjecttype_configs |
24 | | - config_type="informatiebjecttype" |
25 | | -
|
26 | | - Example output: |
27 | | - imported 3 new zaaktype-informatiebjecttype configs |
28 | | - AAA - zaaktype-aaa |
29 | | - info-aaa-1 |
30 | | - info-aaa-2 |
31 | | - BBB - zaaktype-bbb |
32 | | - info-bbb |
33 | | - """ |
34 | | - imported = import_func() |
35 | | - |
36 | | - count = sum(len(t[1]) for t in imported) |
37 | | - self.stdout.write(f"imported {count} new zaaktype-{config_type} configs") |
38 | | - |
39 | | - for ztc, config_types in sorted(imported, key=lambda t: str(t[0])): |
40 | | - self.stdout.write(str(ztc)) |
41 | | - for c in sorted(map(str, config_types)): |
42 | | - self.stdout.write(f" {c}") |
43 | | - |
44 | | - self.stdout.write("") |
45 | | - |
46 | 12 | def handle(self, *args, **options): |
47 | | - if ZGWApiGroupConfig.objects.count() == 0: |
| 13 | + if not ZGWApiGroupConfig.objects.exists(): |
48 | 14 | self.stdout.write( |
49 | 15 | "Please define at least one ZGWApiGroupConfig before running this command." |
50 | 16 | ) |
51 | 17 | return |
52 | 18 |
|
53 | | - # catalogus config |
54 | | - imported = import_catalog_configs() |
55 | | - |
56 | | - self.stdout.write(f"imported {len(imported)} new catalogus configs") |
57 | | - for c in sorted(map(str, imported)): |
58 | | - self.stdout.write(c) |
59 | | - |
60 | | - self.stdout.write("") |
61 | | - |
62 | | - # zaaktype config |
63 | | - imported = import_zaaktype_configs() |
64 | | - |
65 | | - self.stdout.write(f"imported {len(imported)} new zaaktype configs") |
66 | | - for c in sorted(map(str, imported)): |
67 | | - self.stdout.write(c) |
| 19 | + importers = [ |
| 20 | + ZGWCatalogusImporter(api_group) |
| 21 | + for api_group in ZGWApiGroupConfig.objects.all() |
| 22 | + ] |
68 | 23 |
|
69 | | - self.stdout.write("") |
| 24 | + output = "" |
| 25 | + for importer in importers: |
| 26 | + result = importer.import_all() |
| 27 | + output = output + result.pretty_print() + "\n" |
70 | 28 |
|
71 | | - # supplemental configs |
72 | | - self.log_supplement_imports_to_stdout( |
73 | | - import_zaaktype_informatieobjecttype_configs, "informatiebjecttype" |
74 | | - ) |
75 | | - self.log_supplement_imports_to_stdout( |
76 | | - import_zaaktype_statustype_configs, "statustype" |
77 | | - ) |
78 | | - self.log_supplement_imports_to_stdout( |
79 | | - import_zaaktype_resultaattype_configs, "resultaattype" |
80 | | - ) |
| 29 | + self.stdout.write(output) |
0 commit comments