150 lines
6.3 KiB
Python
150 lines
6.3 KiB
Python
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 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!',
|
||
'description': 'Endlich war es soweit. Zum ersten Mal fand am 2. und 3. Juli 1977 das 1. Internationale …'
|
||
},
|
||
{
|
||
'title': 'Mein Tagesblog',
|
||
'description': 'https://blogger.com/cruel-festivals-around-the-world/'
|
||
},
|
||
{
|
||
'title': 'Woodstock',
|
||
'description': 'In Woodstock hat sich dem Mythos nach vor genau vierzig Jahren das Lebensgefühl …'
|
||
},
|
||
{
|
||
'title': 'Ein neues Festival auf dem Gurten – und ich bin dabei!',
|
||
'description': 'Endlich war es soweit. Zum ersten Mal fand am 2. und 3. Juli 1977 das 1. Internationale …'
|
||
},
|
||
{
|
||
'title': 'Das Festival',
|
||
'description': 'www.meinblog.ch'
|
||
},
|
||
{
|
||
'title': '',
|
||
'description': ''
|
||
},
|
||
]
|
||
},
|
||
{
|
||
'title': 'Erfahrungen Lehrbeginn',
|
||
'appearance': 'green',
|
||
'entries': [
|
||
{
|
||
'title': 'Ich heisse Jan und habe am 01. August 2017 meine Ausbildung begonnen. Pünktlich zum …',
|
||
'description': ''
|
||
},
|
||
{
|
||
'title': 'Mein Lehrbeginn',
|
||
'description': 'Was war ich angespannt… und nervös. Das hat sich aber schnell gelegt.'
|
||
}
|
||
]
|
||
},
|
||
{
|
||
'title': 'Interview «Mein neues Umfeld»',
|
||
'appearance': 'brown'
|
||
}
|
||
]
|
||
|
||
|
||
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):
|
||
# self.ensure_clean_dir('images')
|
||
# self.ensure_clean_dir('original_images')
|
||
# self.ensure_clean_dir('documents')
|
||
#
|
||
# site = wagtail_factories.SiteFactory.create(is_default_site=True)
|
||
# Page.objects.filter(title='Root').delete()
|
||
#
|
||
# u = UserFactory(
|
||
# username='test',
|
||
# is_staff=True,
|
||
# is_superuser=True
|
||
# )
|
||
|
||
Room.objects.all().delete()
|
||
UserGroup.objects.all().delete()
|
||
|
||
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 in enumerate(room_entries):
|
||
RoomEntryFactory.create(room=room, **room_entry)
|
||
|
||
# for book_idx, book_data in enumerate(data):
|
||
# book = BookFactory.create(parent=site.root_page, **self.filter_data(book_data, 'topics'))
|
||
#
|
||
# default_topics = [{} for i in range(0, random.randint(5, 8))]
|
||
# topics_data = book_data.get('topics', default_topics)
|
||
#
|
||
# for topic_idx, topic_data in enumerate(topics_data):
|
||
# topic = TopicFactory.create(parent=book, **self.filter_data(topic_data, 'modules'))
|
||
#
|
||
# default_modules = [{} for i in range(0, random.randint(3, 6))]
|
||
# modules_data = topic_data.get('modules', default_modules)
|
||
#
|
||
# for module_idx, module_data in enumerate(modules_data):
|
||
# module = ModuleFactory.create(parent=topic, **self.filter_data(module_data, ['objective_groups', 'chapters']))
|
||
#
|
||
# default_objective_groups = [{} for i in range(0, 2)]
|
||
# objective_group_data = module_data.get('objective_groups', default_objective_groups)
|
||
#
|
||
# for objective_group_idx, objective_group_entry in enumerate(objective_group_data):
|
||
# factory_params = self.filter_data(objective_group_entry, 'objectives')
|
||
# objective_group = ObjectiveGroupFactory.create(module=module,
|
||
# user=None,
|
||
# **factory_params)
|
||
#
|
||
# default_objectives = [{} for i in range(0, 4)]
|
||
# objectives_data = objective_group_entry.get('objectives', default_objectives)
|
||
#
|
||
# for objective_idx, objective_data in enumerate(objectives_data):
|
||
# objective = ObjectiveFactory.create(group=objective_group, **objective_data)
|
||
#
|
||
# default_chapters = [{} for i in range(0, 2)]
|
||
# chapters_data = module_data.get('chapters', default_chapters)
|
||
#
|
||
# for chapter_idx, chapter_data in enumerate(chapters_data):
|
||
# chapter = ChapterFactory.create(parent=module, **self.filter_data(chapter_data, 'content_blocks'))
|
||
#
|
||
# default_content_blocks = [{} for i in range(0, 4)]
|
||
# content_blocks_data = chapter_data.get('content_blocks', default_content_blocks)
|
||
#
|
||
# 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)
|