vbv/server/vbv_lernwelt/media_library/create_default_documents.py

48 lines
1.8 KiB
Python

import os
import factory
from wagtail.core.models import Collection
from vbv_lernwelt.course.models import Course
from vbv_lernwelt.media_library.models import LibraryDocument
from vbv_lernwelt.media_library.tests.media_library_factories import LibraryDocumentFactory
def create_default_collections():
c = Collection.objects.all().delete()
root, created = Collection.objects.get_or_create(name='Root', depth=0)
for course in Course.objects.all():
course_collection = root.add_child(name=course.name)
for cat in course.coursecategory_set.all():
cat_collection = course_collection.add_child(name=cat.name)
def create_default_documents():
LibraryDocument.objects.all().delete()
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../static/media/documents/')
collection = Collection.objects.get(name='Fahrzeug')
filename = 'SchweizerischesZivilgesetzbuch.pdf'
document = LibraryDocumentFactory(
title='V1 C25 ZGB CH',
display_text='Schweizerisches Zivilgesetzbuch',
description='Ein wundervolles Dokument, Bachblüten für Leseratten und metaphysisches Wohlbefinden für Handyvekäufer.',
link_display_text='Dokument laden',
file=factory.django.FileField(from_path=os.path.join(path, filename), filename=filename),
collection=collection
)
filename = 'SmallPDF.pdf'
document = LibraryDocumentFactory(
title='V1 C25 ',
display_text='Pdf showcase ',
description='Ein wundervolles Dokument, Bachblüten für Leseratten und metaphysisches Wohlbefinden für Handyvekäufer.',
link_display_text='Dokument laden',
file=factory.django.FileField(from_path=os.path.join(path, filename), filename=filename),
collection=collection
)