Add media_library app

This commit is contained in:
Lorenz Padberg 2022-08-18 11:35:59 +02:00
parent 67545f474a
commit 08d0245a04
18 changed files with 249 additions and 0 deletions

View File

@ -63,6 +63,7 @@ if [ "$SKIP_SETUP" = false ]; then
python3 server/manage.py migrate --settings="$DJANGO_SETTINGS_MODULE" python3 server/manage.py migrate --settings="$DJANGO_SETTINGS_MODULE"
python3 server/manage.py create_default_users --settings="$DJANGO_SETTINGS_MODULE" python3 server/manage.py create_default_users --settings="$DJANGO_SETTINGS_MODULE"
python3 server/manage.py create_default_learning_path --settings="$DJANGO_SETTINGS_MODULE" python3 server/manage.py create_default_learning_path --settings="$DJANGO_SETTINGS_MODULE"
python3 server/manage.py create_default_media_library --settings="$DJANGO_SETTINGS_MODULE"
# make django translations # make django translations
(cd server && python3 manage.py compilemessages --settings="$DJANGO_SETTINGS_MODULE") (cd server && python3 manage.py compilemessages --settings="$DJANGO_SETTINGS_MODULE")

View File

@ -107,6 +107,7 @@ LOCAL_APPS = [
"vbv_lernwelt.sso", "vbv_lernwelt.sso",
"vbv_lernwelt.learnpath", "vbv_lernwelt.learnpath",
"vbv_lernwelt.completion", "vbv_lernwelt.completion",
"vbv_lernwelt.media_library",
] ]
# https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps # https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
@ -213,6 +214,8 @@ LANGUAGES = [
('it-CH', "Swiss Italian") ('it-CH', "Swiss Italian")
] ]
WAGTAILDOCS_DOCUMENT_MODEL = 'media_library.CustomDocument'
WAGTAIL_CONTENT_LANGUAGES = [ WAGTAIL_CONTENT_LANGUAGES = [
('fr-CH', "Swiss French"), ('fr-CH', "Swiss French"),

View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

View File

@ -0,0 +1,18 @@
from django.apps import AppConfig
class MediaLibraryConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'vbv_lernwelt.media_library'
#
# default_auto_field = 'django.db.models.BigAutoField'
# name = 'vbv_lernwelt.learnpath'
#
# def ready(self):
# try:
# # pylint: disable=unused-import,import-outside-toplevel
# import vbv_lernwelt.learnpath.signals # noqa F401
# except ImportError:
# pass

View File

@ -0,0 +1,16 @@
from wagtail.core.models import Collection
def create_default_collections():
c = Collection.objects.all().delete()
root, created = Collection.objects.get_or_create(name='Root', depth=0)
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']
for handlungsfeld in handlungsfelder_names:
versicherungsvermittler = handlungsfelder.add_child(name=handlungsfeld)

View File

@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
#
# Iterativ GmbH
# http://www.iterativ.ch/
#
# Copyright (c) 2015 Iterativ GmbH. All rights reserved.
#
# Created on 2022-08-18
# @author: lorenz.padberg@iterativ.ch

View File

@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
#
# Iterativ GmbH
# http://www.iterativ.ch/
#
# Copyright (c) 2015 Iterativ GmbH. All rights reserved.
#
# Created on 2022-08-18
# @author: lorenz.padberg@iterativ.ch

View File

@ -0,0 +1,8 @@
import djclick as click
from vbv_lernwelt.media_library.create_default_documents import create_default_collections
@click.command()
def command():
create_default_collections()

View File

@ -0,0 +1,46 @@
# Generated by Django 3.2.13 on 2022-08-16 08:35
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import taggit.managers
import wagtail.models.collections
import wagtail.search.index
class Migration(migrations.Migration):
initial = True
dependencies = [
('wagtailcore', '0069_log_entry_jsonfield'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('taggit', '0004_alter_taggeditem_content_type_alter_taggeditem_tag'),
]
operations = [
migrations.CreateModel(
name='CustomDocument',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=255, verbose_name='title')),
('file', models.FileField(upload_to='documents', verbose_name='file')),
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='created at')),
('file_size', models.PositiveIntegerField(editable=False, null=True)),
('file_hash', models.CharField(blank=True, editable=False, max_length=40)),
('display_text', models.CharField(default='', max_length=1024)),
('description', models.TextField(default='')),
('link_display_text', models.CharField(default='', max_length=1024)),
('thumbnail', models.URLField()),
('collection', models.ForeignKey(default=wagtail.models.collections.get_root_collection_id, on_delete=django.db.models.deletion.CASCADE, related_name='+', to='wagtailcore.collection', verbose_name='collection')),
('tags', taggit.managers.TaggableManager(blank=True, help_text=None, through='taggit.TaggedItem', to='taggit.Tag', verbose_name='tags')),
('uploaded_by_user', models.ForeignKey(blank=True, editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL, verbose_name='uploaded by user')),
],
options={
'verbose_name': 'document',
'verbose_name_plural': 'documents',
'abstract': False,
},
bases=(wagtail.search.index.Indexed, models.Model),
),
]

View File

@ -0,0 +1,71 @@
from django.db import models
# Create your models here.
from wagtail.models import Page
from wagtail.documents.models import AbstractDocument, Document
class CustomDocument(AbstractDocument):
# Todo: check https://filepreviews.io/
# Custom field example:
display_text = models.CharField(max_length=1024, default='')
description = models.TextField(default='')
link_display_text = models.CharField(max_length=1024, default='')
thumbnail = models.URLField()
admin_form_fields = Document.admin_form_fields + (
'display_text', 'description', 'link_display_text', 'thumbnail'
)
class TopCategory(Page):
"""
Handlungsfelder
"""
parent_page_types = ['learnpath.LearningPath']
subpage_types = ['media_library.Category']
# Todo: use wagtail collections for this...
class Category(Page):
"""
Handlungsfeld
"""
parent_page_types = ['media_library.TopCategory']
#
# description
# thumbnail_image
# description_image
# additional_content # Rich text field
# documents = []
#
#
# class LibraryDocument(CustomDocument):
# """
# Extension from the standart Wagtail document.
# """
# pass
#
#
# class LibraryLink():
# """
# Custom Link Block
#
# """
# pass
#
#
# class LearningPathReference():
# icon
# pass
#
#
# class CrossReference():
# pass

View File

@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
#
# Iterativ GmbH
# http://www.iterativ.ch/
#
# Copyright (c) 2015 Iterativ GmbH. All rights reserved.
#
# Created on 2022-08-16
# @author: lorenz.padberg@iterativ.ch

View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

View File

@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
#
# Iterativ GmbH
# http://www.iterativ.ch/
#
# Copyright (c) 2015 Iterativ GmbH. All rights reserved.
#
# Created on 2022-08-16
# @author: lorenz.padberg@iterativ.ch

View File

@ -0,0 +1,15 @@
import wagtail_factories
from vbv_lernwelt.learnpath.models import LearningPath, Topic, Circle, LearningSequence, LearningContent, LearningUnit, \
LearningUnitQuestion
from vbv_lernwelt.media_library.models import CustomDocument
class LibraryDocumentFactory(wagtail_factories.PageFactory):
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

View File

@ -0,0 +1,23 @@
from django.conf import settings
from django.test import TestCase
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
class TestCreateDefaultDocuments(TestCase):
def setUp(self) -> None:
create_default_users()
create_locales_for_wagtail()
def test_create_default_collections(self):
create_default_collections()
qs = Collection.objects.filter(name="Versicherungsvermittler/in")
self.assertTrue(qs.exists())
def create_locales_for_wagtail():
for language in settings.WAGTAIL_CONTENT_LANGUAGES:
Locale.objects.get_or_create(language_code=language[0])

View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.