From 6f4d50b0336535b48d3bc47e4e7f29151095c88b Mon Sep 17 00:00:00 2001 From: Ramon Wenger Date: Tue, 23 May 2023 12:30:58 +0200 Subject: [PATCH] Update command form exporting instruments --- .../management/commands/export_instruments.py | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/server/core/management/commands/export_instruments.py b/server/core/management/commands/export_instruments.py index 8526cdc6..e8485fe4 100644 --- a/server/core/management/commands/export_instruments.py +++ b/server/core/management/commands/export_instruments.py @@ -4,29 +4,37 @@ from basicknowledge.models import BasicKnowledge from datetime import date actions = { - 'text_block': lambda c: print(c.value.get('text')), - 'subtitle': lambda c: print(f'

{c.value.get("text")}

'), - 'section_title': lambda c: print(f'

{c.value.get("text")}

'), - 'thinglink_block': lambda c: print('===THINGLINK==='), - 'image_block': lambda c: print('===BILD==='), - 'document_block': lambda c: print('===DOCUMENT==='), - 'infogram_block': lambda c: print('===INFOGRAM==='), - 'genially_block': lambda c: print('===GENIALLY==='), - 'video_block': lambda c: print('===VIDEO==='), - 'link_block': lambda c: print(f'===LINK=== {c.value.get("text")} {c.value.get("url")}'), + "text_block": lambda c: print(c.value.get("text")), + "subtitle": lambda c: print(f'

{c.value.get("text")}

'), + "section_title": lambda c: print(f'

{c.value.get("text")}

'), + "thinglink_block": lambda _: print("===THINGLINK==="), + "image_block": lambda _: print("===BILD==="), + "document_block": lambda _: print("===DOCUMENT==="), + "infogram_block": lambda _: print("===INFOGRAM==="), + "genially_block": lambda _: print("===GENIALLY==="), + "video_block": lambda _: print("===VIDEO==="), + "link_block": lambda c: print( + f'===LINK=== {c.value.get("text")} {c.value.get("url")}' + ), } class Command(BaseCommand): + """ + usage: `python manage.py export_instruments --slugs slug-a slug-b [...]` + """ + def add_arguments(self, parser): - parser.add_argument('--slugs', nargs='+', type=str) + parser.add_argument("--slugs", nargs="+", type=str) def handle(self, *args, **options): # todo: only published after X: Page.last_published_at > X - print('') - for i in BasicKnowledge.objects.live().filter(slug__in=options['slugs']): - print(f'

{i.title}

') + print("") + for i in BasicKnowledge.objects.live().filter(slug__in=options["slugs"]): + print(f"

{i.title}

") for c in i.contents: - action = actions.get(c.block_type, lambda c: print(f'==={c.block_type}===')) + action = actions.get( + c.block_type, lambda c: print(f"==={c.block_type}===") + ) action(c) - print('') + print("")