import os import random import shutil from django.conf import settings from django.contrib.auth import get_user_model from django.core.management import BaseCommand from wagtail.core.models import Site from rooms.factories import RoomFactory, RoomEntryFactory from rooms.models import Room from user.factories import UserGroupFactory from user.models import UserGroup data = [ { 'title': 'Ein historisches Festival', 'appearance': 'red', 'entries': [ { 'title': 'Ein neues Festival auf dem Gurten – und ich bin dabei!', 'subtitle': 'Endlich war es soweit. Zum ersten Mal fand am 2. und 3. Juli 1977 das 1. Internationale …', 'contents': [ { 'type': 'image_url', 'value': { 'title': 'Ein Bild sagt mehr als 1000 Worte', 'url': 'https://picsum.photos/600/400/?random' } }, { 'type': 'text_block', 'value': { 'text': """

Das folgende Interview bezieht sich auf Jugendliche, die Ihre Lehre im Sommer begonnen haben. Lesen Sie das Interview durch und bearbeiten Sie anschliessend die Aufgaben.

Aufgaben zum Interview «Das ist ein ganz markanter Wechsel»

""" } }, { 'type': 'text_block', 'value': { 'text': '

Erklären Sie, welche Informationen den Leserinnen und Lesern in der Einleitung vermittelt werden.

' } } ] }, { 'title': 'Mein Tagesblog', 'subtitle': 'https://blogger.com/cruel-festivals-around-the-world/', 'contents': [ { 'type': 'image_url', 'value': { 'title': 'Ein Bild sagt mehr als 1000 Worte', 'url': 'https://picsum.photos/600/400/?random' } }, { 'type': 'text_block', 'value': { 'text': """

Das folgende Interview bezieht sich auf Jugendliche, die Ihre Lehre im Sommer begonnen haben. Lesen Sie das Interview durch und bearbeiten Sie anschliessend die Aufgaben.

Aufgaben zum Interview «Das ist ein ganz markanter Wechsel»

""" } }, { 'type': 'task', 'value': { 'text': '

Erklären Sie, welche Informationen den Leserinnen und Lesern in der Einleitung vermittelt werden.

' } } ] }, { 'title': 'Woodstock', 'subtitle': 'In Woodstock hat sich dem Mythos nach vor genau vierzig Jahren das Lebensgefühl …', 'contents': [ { 'type': 'image_url', 'value': { 'title': 'Ein Bild sagt mehr als 1000 Worte', 'url': 'https://picsum.photos/600/400/?random' } }, { 'type': 'link_block', 'value': { 'text': 'Netflix & Chill', 'url': 'https://netflix.com' } } ] }, { 'title': 'Das Festival', 'subtitle': 'www.meinblog.ch', 'contents': [ { 'type': 'image_url', 'value': { 'title': 'Ein Bild sagt mehr als 1000 Worte', 'url': 'https://picsum.photos/600/400/?random' } }, { 'type': 'text_block', 'value': { 'text': """

Das folgende Interview bezieht sich auf Jugendliche, die Ihre Lehre im Sommer begonnen haben. Lesen Sie das Interview durch und bearbeiten Sie anschliessend die Aufgaben.

Aufgaben zum Interview «Das ist ein ganz markanter Wechsel»

""" } }, { 'type': 'task', 'value': { 'text': '

Erklären Sie, welche Informationen den Leserinnen und Lesern in der Einleitung vermittelt werden.

' } } ] } ] }, { 'title': 'Erfahrungen Lehrbeginn', 'appearance': 'green', 'entries': [ { 'title': 'Ich heisse Jan und habe am 01. August 2017 meine Ausbildung begonnen. Pünktlich zum …', 'subtitle': '', 'contents': [ { 'type': 'image_url', 'value': { 'title': 'Ein Bild sagt mehr als 1000 Worte', 'url': 'https://picsum.photos/600/400/?random' } }, { 'type': 'text_block', 'value': { 'text': """

Das folgende Interview bezieht sich auf Jugendliche, die Ihre Lehre im Sommer begonnen haben. Lesen Sie das Interview durch und bearbeiten Sie anschliessend die Aufgaben.

Aufgaben zum Interview «Das ist ein ganz markanter Wechsel»

""" } }, { 'type': 'task', 'value': { 'text': '

Erklären Sie, welche Informationen den Leserinnen und Lesern in der Einleitung vermittelt werden.

' } } ] }, { 'title': 'Mein Lehrbeginn', 'subtitle': 'Was war ich angespannt… und nervös. Das hat sich aber schnell gelegt.', 'contents': [ { 'type': 'image_url', 'value': { 'title': 'Ein Bild sagt mehr als 1000 Worte', 'url': 'https://picsum.photos/600/400/?random' } }, { 'type': 'text_block', 'value': { 'text': """

Das folgende Interview bezieht sich auf Jugendliche, die Ihre Lehre im Sommer begonnen haben. Lesen Sie das Interview durch und bearbeiten Sie anschliessend die Aufgaben.

Aufgaben zum Interview «Das ist ein ganz markanter Wechsel»

""" } }, { 'type': 'task', 'value': { 'text': '

Erklären Sie, welche Informationen den Leserinnen und Lesern in der Einleitung vermittelt werden.

' } } ] } ] }, { 'title': 'Interview «Mein neues Umfeld»', 'appearance': 'blue' } ] class Command(BaseCommand): def ensure_clean_dir(self, folder): path = os.path.join(settings.MEDIA_ROOT, folder) if os.path.exists(path): shutil.rmtree(path) if not os.path.exists(path): os.makedirs(path) def filter_data(self, input_data, filter_keyword): filters = [filter_keyword] if not isinstance(filter_keyword, list) else filter_keyword return {k: v for (k, v) in input_data.items() if not (k in filters)} def handle(self, *args, **options): Room.objects.all().delete() UserGroup.objects.all().delete() root_page = Site.objects.get(is_default_site=True).root_page for i in range(0, 6): UserGroupFactory(users=(random.choices(get_user_model().objects.all(), k=3))) for room_idx, room_data in enumerate(data): room = RoomFactory.create(**self.filter_data(room_data, ['entries'])) default_room_entries = [{} for i in range(0, random.randint(5, 8))] room_entries = room_data.get('entries', default_room_entries) for room_entry_idx, room_entry_data in enumerate(room_entries): room_entry = RoomEntryFactory.create(room=room, **room_entry_data) # room_entry = RoomEntryFactory.create(room=room, **self.filter_data(room_entry_data, 'contents')) # if 'contents' in room_entry_data: # # now create contents in a room entry # content_block = ContentBlockFactory.create( # parent=root_page, # title='{}_{}'.format(room_entry.title, fake_title(min_words=1, max_words=1)), # # description=room_entry.description, # contents=room_entry_data['contents'] # ) # room_entry.content = content_block # room_entry.save() # for content_block_idx, content_block_data in enumerate(content_blocks_data): # # ContentBlockFactory.create(parent=chapter, **self.filter_data(content_block_data, 'contents')) # ContentBlockFactory.create(parent=chapter, **content_block_data)