diff --git a/.gitignore b/.gitignore index 180b7b05..4e35ac96 100644 --- a/.gitignore +++ b/.gitignore @@ -284,3 +284,5 @@ cypress/test-reports /server/vbv_lernwelt/static/vue/ /server/vbv_lernwelt/templates/vue/index.html !/server/vbv_lernwelt/media/ +SchweizerischesZivilgesetzbuch_* +SmallPDF_* diff --git a/server/config/settings/base.py b/server/config/settings/base.py index a0a4609e..8f935ced 100644 --- a/server/config/settings/base.py +++ b/server/config/settings/base.py @@ -108,6 +108,7 @@ LOCAL_APPS = [ "vbv_lernwelt.learnpath", "vbv_lernwelt.completion", "vbv_lernwelt.media_library", + ] # https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS @@ -214,7 +215,7 @@ LANGUAGES = [ ('it-CH', "Swiss Italian") ] -WAGTAILDOCS_DOCUMENT_MODEL = 'media_library.CustomDocument' +WAGTAILDOCS_DOCUMENT_MODEL = 'media_library.LibraryDocument' WAGTAIL_CONTENT_LANGUAGES = [ diff --git a/server/vbv_lernwelt/core/migrations/0004_alter_user_managers.py b/server/vbv_lernwelt/core/migrations/0004_alter_user_managers.py new file mode 100644 index 00000000..820b5223 --- /dev/null +++ b/server/vbv_lernwelt/core/migrations/0004_alter_user_managers.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.13 on 2022-08-16 08:35 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0003_create_users'), + ] + + operations = [ + migrations.AlterModelManagers( + name='user', + managers=[ + ], + ), + ] diff --git a/server/vbv_lernwelt/media/documents/SchweizerischesZivilgesetzbuch.pdf b/server/vbv_lernwelt/media/documents/SchweizerischesZivilgesetzbuch.pdf new file mode 100644 index 00000000..4e87e3a9 Binary files /dev/null and b/server/vbv_lernwelt/media/documents/SchweizerischesZivilgesetzbuch.pdf differ diff --git a/server/vbv_lernwelt/media/documents/SmallPDF.pdf b/server/vbv_lernwelt/media/documents/SmallPDF.pdf new file mode 100644 index 00000000..3d382f93 Binary files /dev/null and b/server/vbv_lernwelt/media/documents/SmallPDF.pdf differ diff --git a/server/vbv_lernwelt/media_library/create_default_documents.py b/server/vbv_lernwelt/media_library/create_default_documents.py index 8646a58d..5c52cbd4 100644 --- a/server/vbv_lernwelt/media_library/create_default_documents.py +++ b/server/vbv_lernwelt/media_library/create_default_documents.py @@ -1,4 +1,11 @@ from wagtail.core.models import Collection +import factory +from django.core.files import File +import os + +from vbv_lernwelt.media_library.models import LibraryDocument +from vbv_lernwelt.media_library.tests.media_library_factories import LibraryDocumentFactory +from factory.django import DjangoModelFactory def create_default_collections(): @@ -8,9 +15,39 @@ def create_default_collections(): versicherungsvermittler = root.add_child(name='Versicherungsvermittler/in') handlungsfelder = versicherungsvermittler.add_child(name='Handlungsfelder') - - handlungsfelder_names = ['Fahrzeug', 'Reisen', 'Einkommensicherung', 'Gesundheit', 'Haushalt', 'Sparen', 'Pensionierung', 'KMU', 'Wohneigentum', 'Rechtsstreitigkeiten', 'Erben / Vererben', 'Selbständigkeit'] + handlungsfelder_names = ['Fahrzeug', 'Reisen', 'Einkommensicherung', 'Gesundheit', 'Haushalt', 'Sparen', + 'Pensionierung', 'KMU', 'Wohneigentum', 'Rechtsstreitigkeiten', 'Erben / Vererben', + 'Selbständigkeit'] for handlungsfeld in handlungsfelder_names: versicherungsvermittler = handlungsfelder.add_child(name=handlungsfeld) + +def create_default_documents(): + LibraryDocument.objects.all().delete() + + path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../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 Wolbefinden 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 Wolbefinden für Handyvekäufer.', + link_display_text='Dokument laden', + file=factory.django.FileField(from_path=os.path.join(path, filename), filename=filename), + collection=collection + ) + pass + diff --git a/server/vbv_lernwelt/media_library/management/commands/create_default_media_library.py b/server/vbv_lernwelt/media_library/management/commands/create_default_media_library.py index a32c2e6d..93a44ca0 100644 --- a/server/vbv_lernwelt/media_library/management/commands/create_default_media_library.py +++ b/server/vbv_lernwelt/media_library/management/commands/create_default_media_library.py @@ -1,8 +1,10 @@ import djclick as click -from vbv_lernwelt.media_library.create_default_documents import create_default_collections +from vbv_lernwelt.media_library.create_default_documents import create_default_collections, create_default_documents @click.command() def command(): create_default_collections() + create_default_documents() + diff --git a/server/vbv_lernwelt/media_library/migrations/0002_auto_20220818_1414.py b/server/vbv_lernwelt/media_library/migrations/0002_auto_20220818_1414.py new file mode 100644 index 00000000..70da2f30 --- /dev/null +++ b/server/vbv_lernwelt/media_library/migrations/0002_auto_20220818_1414.py @@ -0,0 +1,42 @@ +# Generated by Django 3.2.13 on 2022-08-18 12:14 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('wagtailcore', '0069_log_entry_jsonfield'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('taggit', '0004_alter_taggeditem_content_type_alter_taggeditem_tag'), + ('media_library', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Category', + fields=[ + ('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')), + ], + options={ + 'abstract': False, + }, + bases=('wagtailcore.page',), + ), + migrations.CreateModel( + name='TopCategory', + fields=[ + ('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')), + ], + options={ + 'abstract': False, + }, + bases=('wagtailcore.page',), + ), + migrations.RenameModel( + old_name='CustomDocument', + new_name='LibraryDocument', + ), + ] diff --git a/server/vbv_lernwelt/media_library/models.py b/server/vbv_lernwelt/media_library/models.py index f3bd9276..74d3e2ee 100644 --- a/server/vbv_lernwelt/media_library/models.py +++ b/server/vbv_lernwelt/media_library/models.py @@ -5,7 +5,7 @@ from wagtail.models import Page from wagtail.documents.models import AbstractDocument, Document -class CustomDocument(AbstractDocument): +class LibraryDocument(AbstractDocument): # Todo: check https://filepreviews.io/ # Custom field example: diff --git a/server/vbv_lernwelt/media_library/tests/media_library_factories.py b/server/vbv_lernwelt/media_library/tests/media_library_factories.py index a7a37fd8..267a193e 100644 --- a/server/vbv_lernwelt/media_library/tests/media_library_factories.py +++ b/server/vbv_lernwelt/media_library/tests/media_library_factories.py @@ -3,13 +3,13 @@ import wagtail_factories from vbv_lernwelt.learnpath.models import LearningPath, Topic, Circle, LearningSequence, LearningContent, LearningUnit, \ LearningUnitQuestion -from vbv_lernwelt.media_library.models import CustomDocument +from vbv_lernwelt.media_library.models import LibraryDocument -class LibraryDocumentFactory(wagtail_factories.PageFactory): +class LibraryDocumentFactory(wagtail_factories.DocumentFactory): link_display_text = 'Dokument herunter laden' thumbnail = 'https://d9-wret.s3.us-west-2.amazonaws.com/assets/palladium/production/s3fs-public/thumbnails/image/file.jpg' class Meta: - model = CustomDocument + model = LibraryDocument diff --git a/server/vbv_lernwelt/media_library/tests/test_create_default_documents.py b/server/vbv_lernwelt/media_library/tests/test_create_default_documents.py index eec04ab8..0d74e807 100644 --- a/server/vbv_lernwelt/media_library/tests/test_create_default_documents.py +++ b/server/vbv_lernwelt/media_library/tests/test_create_default_documents.py @@ -4,7 +4,8 @@ from wagtail.core.models import Collection from wagtail.models import Locale from vbv_lernwelt.core.create_default_users import create_default_users -from vbv_lernwelt.media_library.create_default_documents import create_default_collections +from vbv_lernwelt.media_library.create_default_documents import create_default_collections, create_default_documents +from vbv_lernwelt.media_library.models import LibraryDocument class TestCreateDefaultDocuments(TestCase): @@ -17,6 +18,13 @@ class TestCreateDefaultDocuments(TestCase): qs = Collection.objects.filter(name="Versicherungsvermittler/in") self.assertTrue(qs.exists()) + def test_create_default_documents(self): + create_default_collections() + + create_default_documents() + qs = LibraryDocument.objects.all() + self.assertTrue(qs.exists()) + def create_locales_for_wagtail(): for language in settings.WAGTAIL_CONTENT_LANGUAGES: