Update command form exporting instruments
This commit is contained in:
parent
d251931b39
commit
6f4d50b033
|
|
@ -4,29 +4,37 @@ from basicknowledge.models import BasicKnowledge
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
actions = {
|
actions = {
|
||||||
'text_block': lambda c: print(c.value.get('text')),
|
"text_block": lambda c: print(c.value.get("text")),
|
||||||
'subtitle': lambda c: print(f'<h3>{c.value.get("text")}</h3>'),
|
"subtitle": lambda c: print(f'<h3>{c.value.get("text")}</h3>'),
|
||||||
'section_title': lambda c: print(f'<h2>{c.value.get("text")}</h2>'),
|
"section_title": lambda c: print(f'<h2>{c.value.get("text")}</h2>'),
|
||||||
'thinglink_block': lambda c: print('===THINGLINK==='),
|
"thinglink_block": lambda _: print("===THINGLINK==="),
|
||||||
'image_block': lambda c: print('===BILD==='),
|
"image_block": lambda _: print("===BILD==="),
|
||||||
'document_block': lambda c: print('===DOCUMENT==='),
|
"document_block": lambda _: print("===DOCUMENT==="),
|
||||||
'infogram_block': lambda c: print('===INFOGRAM==='),
|
"infogram_block": lambda _: print("===INFOGRAM==="),
|
||||||
'genially_block': lambda c: print('===GENIALLY==='),
|
"genially_block": lambda _: print("===GENIALLY==="),
|
||||||
'video_block': lambda c: print('===VIDEO==='),
|
"video_block": lambda _: print("===VIDEO==="),
|
||||||
'link_block': lambda c: print(f'===LINK=== {c.value.get("text")} {c.value.get("url")}'),
|
"link_block": lambda c: print(
|
||||||
|
f'===LINK=== {c.value.get("text")} {c.value.get("url")}'
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
|
"""
|
||||||
|
usage: `python manage.py export_instruments --slugs slug-a slug-b [...]`
|
||||||
|
"""
|
||||||
|
|
||||||
def add_arguments(self, parser):
|
def add_arguments(self, parser):
|
||||||
parser.add_argument('--slugs', nargs='+', type=str)
|
parser.add_argument("--slugs", nargs="+", type=str)
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
# todo: only published after X: Page.last_published_at > X
|
# todo: only published after X: Page.last_published_at > X
|
||||||
print('<html><head></head><body>')
|
print("<html><head></head><body>")
|
||||||
for i in BasicKnowledge.objects.live().filter(slug__in=options['slugs']):
|
for i in BasicKnowledge.objects.live().filter(slug__in=options["slugs"]):
|
||||||
print(f'<h1>{i.title}</h1>')
|
print(f"<h1>{i.title}</h1>")
|
||||||
for c in i.contents:
|
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)
|
action(c)
|
||||||
print('</body></html>')
|
print("</body></html>")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue