skillbox/server/core/management/commands/dummy_rooms.py

229 lines
9.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
data = [
{
'title': 'Ein historisches Festival',
'description': '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_block',
'value': {
'title': 'Ein Bild sagt mehr als 1000 Worte',
'url': 'https://picsum.photos/600/400/?random'
}
},
{
'type': 'text_block',
'value': {
'text': """<p>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.</p>
<p>Aufgaben zum Interview «Das ist ein ganz markanter Wechsel»</p>"""
}
},
{
'type': 'text_block',
'value': {
'text': '<p>Erklären Sie, welche Informationen den Leserinnen und Lesern in der Einleitung vermittelt werden.</p>'
}
}
]
},
{
'title': 'Mein Tagesblog',
'subtitle': 'https://blogger.com/cruel-festivals-around-the-world/',
'contents': [
{
'type': 'image_url_block',
'value': {
'title': 'Ein Bild sagt mehr als 1000 Worte',
'url': 'https://picsum.photos/600/400/?random'
}
},
{
'type': 'text_block',
'value': {
'text': """<p>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.</p>
<p>Aufgaben zum Interview «Das ist ein ganz markanter Wechsel»</p>"""
}
},
{
'type': 'task',
'value': {
'text': '<p>Erklären Sie, welche Informationen den Leserinnen und Lesern in der Einleitung vermittelt werden.</p>'
}
}
]
},
{
'title': 'Woodstock',
'subtitle': 'In Woodstock hat sich dem Mythos nach vor genau vierzig Jahren das Lebensgefühl …',
'contents': [
{
'type': 'image_url_block',
'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_block',
'value': {
'title': 'Ein Bild sagt mehr als 1000 Worte',
'url': 'https://picsum.photos/600/400/?random'
}
},
{
'type': 'text_block',
'value': {
'text': """<p>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.</p>
<p>Aufgaben zum Interview «Das ist ein ganz markanter Wechsel»</p>"""
}
},
{
'type': 'task',
'value': {
'text': '<p>Erklären Sie, welche Informationen den Leserinnen und Lesern in der Einleitung vermittelt werden.</p>'
}
}
]
}
]
},
{
'title': 'Erfahrungen Lehrbeginn',
'appearance': 'green',
'description': 'Eine Beschreibung',
'entries': [
{
'title': 'Ich heisse Jan und habe am 01. August 2017 meine Ausbildung begonnen. Pünktlich zum …',
'subtitle': '',
'contents': [
{
'type': 'image_url_block',
'value': {
'title': 'Ein Bild sagt mehr als 1000 Worte',
'url': 'https://picsum.photos/600/400/?random'
}
},
{
'type': 'text_block',
'value': {
'text': """<p>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.</p>
<p>Aufgaben zum Interview «Das ist ein ganz markanter Wechsel»</p>"""
}
},
{
'type': 'task',
'value': {
'text': '<p>Erklären Sie, welche Informationen den Leserinnen und Lesern in der Einleitung vermittelt werden.</p>'
}
}
]
},
{
'title': 'Mein Lehrbeginn',
'subtitle': 'Was war ich angespannt… und nervös. Das hat sich aber schnell gelegt.',
'contents': [
{
'type': 'image_url_block',
'value': {
'title': 'Ein Bild sagt mehr als 1000 Worte',
'url': 'https://picsum.photos/600/400/?random'
}
},
{
'type': 'text_block',
'value': {
'text': """<p>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.</p>
<p>Aufgaben zum Interview «Das ist ein ganz markanter Wechsel»</p>"""
}
},
{
'type': 'task',
'value': {
'text': '<p>Erklären Sie, welche Informationen den Leserinnen und Lesern in der Einleitung vermittelt werden.</p>'
}
}
]
}
]
},
{
'title': 'Interview «Mein neues Umfeld»',
'description': '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()
root_page = Site.objects.get(is_default_site=True).root_page
for room_idx, room_data in enumerate(data):
room = RoomFactory.create(**self.filter_data(room_data, ['entries']))
default_room_entries = [{} for _ 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)