Merge branch 'feature/MS-540-use-custom-document-model' into release/Wagtail-anpassungen
This commit is contained in:
commit
21413b183a
|
|
@ -5,7 +5,7 @@
|
||||||
:href="value.url"
|
:href="value.url"
|
||||||
class="cms-document-block__link"
|
class="cms-document-block__link"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
>{{ value.title }}</a>
|
>{{ value.display_text }}</a>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ from wagtail.images.models import Image
|
||||||
|
|
||||||
from assignments.models import Assignment
|
from assignments.models import Assignment
|
||||||
from basicknowledge.models import BasicKnowledge
|
from basicknowledge.models import BasicKnowledge
|
||||||
|
from books.models import CustomDocument
|
||||||
from surveys.models import Survey
|
from surveys.models import Survey
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
@ -88,14 +89,15 @@ def augment_fields(raw_data):
|
||||||
|
|
||||||
if _type == 'cms_document_block':
|
if _type == 'cms_document_block':
|
||||||
_value = data['value']
|
_value = data['value']
|
||||||
document = Document.objects.get(id=_value)
|
document = CustomDocument.objects.get(id=_value)
|
||||||
value = {
|
value = {
|
||||||
'value': _value,
|
'value': _value,
|
||||||
'id': document.id,
|
'id': document.id,
|
||||||
'file_name': document.filename,
|
'file_name': document.filename,
|
||||||
'file_extension': document.file_extension,
|
'file_extension': document.file_extension,
|
||||||
'url': document.url,
|
'url': document.url,
|
||||||
'title': document.title
|
'title': document.title,
|
||||||
|
'display_text': document.display_text
|
||||||
}
|
}
|
||||||
data['value'] = value
|
data['value'] = value
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
# Generated by Django 3.2.13 on 2022-07-28 08:48
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
import wagtail.core.blocks
|
||||||
|
import wagtail.core.fields
|
||||||
|
import wagtail.documents.blocks
|
||||||
|
import wagtail.images.blocks
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('basicknowledge', '0017_auto_20220630_0743'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='basicknowledge',
|
||||||
|
name='contents',
|
||||||
|
field=wagtail.core.fields.StreamField([('text_block', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.RichTextBlock(features=['bold', 'ul', 'brand', 'secondary']))])), ('image_block', wagtail.images.blocks.ImageChooserBlock()), ('link_block', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.TextBlock()), ('url', wagtail.core.blocks.URLBlock())])), ('video_block', wagtail.core.blocks.StructBlock([('url', wagtail.core.blocks.URLBlock())])), ('document_block', wagtail.core.blocks.StructBlock([('url', wagtail.core.blocks.URLBlock())])), ('section_title', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.TextBlock())])), ('infogram_block', wagtail.core.blocks.StructBlock([('id', wagtail.core.blocks.TextBlock()), ('title', wagtail.core.blocks.TextBlock())])), ('genially_block', wagtail.core.blocks.StructBlock([('id', wagtail.core.blocks.TextBlock())])), ('thinglink_block', wagtail.core.blocks.StructBlock([('id', wagtail.core.blocks.TextBlock())])), ('subtitle', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.TextBlock())])), ('cms_document_block', wagtail.documents.blocks.DocumentChooserBlock())], blank=True, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -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-02
|
||||||
|
# @author: lorenz.padberg@iterativ.ch
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
from django.core.management import BaseCommand
|
||||||
|
|
||||||
|
from books.migrate_document_model import migrate_documents_to_custom_document_model
|
||||||
|
from books.models import Module
|
||||||
|
from surveys.models import Survey
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
self.stdout.write("Migrating Wagtail documents to Custommyskillbox documents")
|
||||||
|
migrate_documents_to_custom_document_model()
|
||||||
|
self.stdout.write("Finish migration")
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
from wagtail.documents.models import Document
|
||||||
|
|
||||||
|
from .models.custom_document import CustomDocument
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_documents_to_custom_document_model(dryrun=False):
|
||||||
|
all_documents = Document.objects.all()
|
||||||
|
print(f"Found {all_documents.count()} Documents")
|
||||||
|
|
||||||
|
for document in all_documents:
|
||||||
|
tags = document.title.replace(':', '').split(' ')
|
||||||
|
|
||||||
|
if dryrun:
|
||||||
|
print('')
|
||||||
|
print(document.title)
|
||||||
|
print(tags)
|
||||||
|
print(document.created_at)
|
||||||
|
print(document.url)
|
||||||
|
print(document.file)
|
||||||
|
print(document.uploaded_by_user)
|
||||||
|
|
||||||
|
else:
|
||||||
|
print('')
|
||||||
|
new_document, created = CustomDocument.objects.get_or_create(title=document.title)
|
||||||
|
new_document.display_text = document.title
|
||||||
|
new_document.created_at = document.created_at
|
||||||
|
new_document.uploaded_by_user = document.uploaded_by_user
|
||||||
|
new_document.file = document.file
|
||||||
|
new_document.collection = document.collection
|
||||||
|
new_document.file_hash = document.file_hash
|
||||||
|
new_document.file_size = document.file_size
|
||||||
|
|
||||||
|
new_document.save()
|
||||||
|
if created:
|
||||||
|
print(f'Created New Document {new_document}')
|
||||||
|
else:
|
||||||
|
print(f'Udated document {document}')
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
# Generated by Django 3.2.13 on 2022-07-28 08:48
|
||||||
|
|
||||||
|
import assignments.models
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
import surveys.models
|
||||||
|
import taggit.managers
|
||||||
|
import wagtail.core.blocks
|
||||||
|
import wagtail.core.fields
|
||||||
|
import wagtail.core.models.collections
|
||||||
|
import wagtail.documents.blocks
|
||||||
|
import wagtail.images.blocks
|
||||||
|
import wagtail.search.index
|
||||||
|
import wagtail.snippets.blocks
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('taggit', '0004_alter_taggeditem_content_type_alter_taggeditem_tag'),
|
||||||
|
('wagtailcore', '0066_collection_management_permissions'),
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
('books', '0034_alter_contentblock_contents'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='contentblock',
|
||||||
|
name='contents',
|
||||||
|
field=wagtail.core.fields.StreamField([('text_block', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.RichTextBlock(features=['ul', 'bold']))])), ('basic_knowledge', wagtail.core.blocks.StructBlock([('description', wagtail.core.blocks.RichTextBlock(required=False)), ('basic_knowledge', wagtail.core.blocks.PageChooserBlock(page_type=['basicknowledge.BasicKnowledge'], required=True))])), ('assignment', wagtail.core.blocks.StructBlock([('assignment_id', wagtail.snippets.blocks.SnippetChooserBlock(assignments.models.Assignment))])), ('survey', wagtail.core.blocks.StructBlock([('survey_id', wagtail.snippets.blocks.SnippetChooserBlock(surveys.models.Survey))])), ('image_block', wagtail.images.blocks.ImageChooserBlock()), ('image_url_block', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.TextBlock()), ('url', wagtail.core.blocks.URLBlock())])), ('link_block', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.TextBlock()), ('url', wagtail.core.blocks.URLBlock())])), ('solution', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.RichTextBlock(features=['ul', 'bold']))], icon='tick')), ('video_block', wagtail.core.blocks.StructBlock([('url', wagtail.core.blocks.URLBlock())])), ('document_block', wagtail.core.blocks.StructBlock([('url', wagtail.core.blocks.URLBlock())])), ('infogram_block', wagtail.core.blocks.StructBlock([('id', wagtail.core.blocks.TextBlock()), ('title', wagtail.core.blocks.TextBlock())])), ('genially_block', wagtail.core.blocks.StructBlock([('id', wagtail.core.blocks.TextBlock())])), ('thinglink_block', wagtail.core.blocks.StructBlock([('id', wagtail.core.blocks.TextBlock())])), ('subtitle', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.TextBlock())])), ('instruction', wagtail.core.blocks.StructBlock([('url', wagtail.core.blocks.URLBlock()), ('text', wagtail.core.blocks.TextBlock(required=False))])), ('module_room_slug', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.TextBlock())])), ('cms_document_block', wagtail.documents.blocks.DocumentChooserBlock()), ('content_list_item', wagtail.core.blocks.StreamBlock([('text_block', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.RichTextBlock(features=['ul', 'bold']))])), ('basic_knowledge', wagtail.core.blocks.StructBlock([('description', wagtail.core.blocks.RichTextBlock(required=False)), ('basic_knowledge', wagtail.core.blocks.PageChooserBlock(page_type=['basicknowledge.BasicKnowledge'], required=True))])), ('assignment', wagtail.core.blocks.StructBlock([('assignment_id', wagtail.snippets.blocks.SnippetChooserBlock(assignments.models.Assignment))])), ('survey', wagtail.core.blocks.StructBlock([('survey_id', wagtail.snippets.blocks.SnippetChooserBlock(surveys.models.Survey))])), ('image_block', wagtail.images.blocks.ImageChooserBlock()), ('image_url_block', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.TextBlock()), ('url', wagtail.core.blocks.URLBlock())])), ('link_block', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.TextBlock()), ('url', wagtail.core.blocks.URLBlock())])), ('solution', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.RichTextBlock(features=['ul', 'bold']))], icon='tick')), ('video_block', wagtail.core.blocks.StructBlock([('url', wagtail.core.blocks.URLBlock())])), ('document_block', wagtail.core.blocks.StructBlock([('url', wagtail.core.blocks.URLBlock())])), ('infogram_block', wagtail.core.blocks.StructBlock([('id', wagtail.core.blocks.TextBlock()), ('title', wagtail.core.blocks.TextBlock())])), ('genially_block', wagtail.core.blocks.StructBlock([('id', wagtail.core.blocks.TextBlock())])), ('thinglink_block', wagtail.core.blocks.StructBlock([('id', wagtail.core.blocks.TextBlock())])), ('subtitle', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.TextBlock())])), ('instruction', wagtail.core.blocks.StructBlock([('url', wagtail.core.blocks.URLBlock()), ('text', wagtail.core.blocks.TextBlock(required=False))])), ('module_room_slug', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.TextBlock())])), ('cms_document_block', wagtail.documents.blocks.DocumentChooserBlock())]))], blank=True, null=True),
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='CustomDocument',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(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)),
|
||||||
|
('collection', models.ForeignKey(default=wagtail.core.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),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
from books.migrate_document_model import migrate_documents_to_custom_document_model
|
||||||
|
|
||||||
|
|
||||||
|
def forwards_func(apps, schema_editor):
|
||||||
|
migrate_documents_to_custom_document_model()
|
||||||
|
|
||||||
|
|
||||||
|
def reverse_func(apps, schema_editor):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
('books', '0035_auto_20220728_0848'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(forwards_func, reverse_func),
|
||||||
|
]
|
||||||
|
|
@ -4,3 +4,4 @@ from .topic import *
|
||||||
from .chapter import *
|
from .chapter import *
|
||||||
from .contentblock import *
|
from .contentblock import *
|
||||||
from .snapshot import *
|
from .snapshot import *
|
||||||
|
from .custom_document import *
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
from wagtail.documents.models import Document, AbstractDocument
|
||||||
|
|
||||||
|
|
||||||
|
class CustomDocument(AbstractDocument):
|
||||||
|
# Custom field example:
|
||||||
|
display_text = models.CharField(
|
||||||
|
max_length=1024, default='')
|
||||||
|
|
||||||
|
admin_form_fields = Document.admin_form_fields + (
|
||||||
|
'display_text',
|
||||||
|
)
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
from wagtail.documents.models import Document
|
||||||
|
|
||||||
|
from books.migrate_document_model import migrate_documents_to_custom_document_model
|
||||||
|
from books.models.custom_document import CustomDocument
|
||||||
|
|
||||||
|
TITLE = 'T9 M2 A2: Quellencheck'
|
||||||
|
|
||||||
|
|
||||||
|
class NewContentBlockMutationTest(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
old_document, created = Document.objects.get_or_create(title=TITLE, file='whatever_is_green.pdf')
|
||||||
|
migrate_documents_to_custom_document_model()
|
||||||
|
|
||||||
|
def test_migrate_creates_new_document(self):
|
||||||
|
self.assertEqual(Document.objects.all().count(), 1)
|
||||||
|
self.assertEqual(Document.objects.filter(title=TITLE).count(), 1)
|
||||||
|
self.assertEqual(CustomDocument.objects.filter(title=TITLE).count(), 1)
|
||||||
|
|
||||||
|
def test_migrate_display_title_migration(self):
|
||||||
|
new_document = CustomDocument.objects.get(title=TITLE)
|
||||||
|
self.assertEqual(new_document.display_text, TITLE)
|
||||||
|
|
||||||
|
def test_migration_is_indempodent(self):
|
||||||
|
migrate_documents_to_custom_document_model()
|
||||||
|
migrate_documents_to_custom_document_model()
|
||||||
|
self.assertEqual(Document.objects.all().count(), 1)
|
||||||
|
self.assertEqual(Document.objects.filter(title=TITLE).count(), 1)
|
||||||
|
self.assertEqual(CustomDocument.objects.filter(title=TITLE).count(), 1)
|
||||||
|
|
@ -362,6 +362,8 @@ GRAPHENE = {
|
||||||
|
|
||||||
# http://docs.wagtail.io/en/v2.1/advanced_topics/settings.html?highlight=urls
|
# http://docs.wagtail.io/en/v2.1/advanced_topics/settings.html?highlight=urls
|
||||||
WAGTAIL_SITE_NAME = 'skillbox'
|
WAGTAIL_SITE_NAME = 'skillbox'
|
||||||
|
WAGTAILDOCS_DOCUMENT_MODEL = 'books.CustomDocument'
|
||||||
|
|
||||||
|
|
||||||
GRAPHQL_QUERIES_DIR = os.path.join(BASE_DIR, '..', 'client', 'src', 'graphql', 'gql', 'queries')
|
GRAPHQL_QUERIES_DIR = os.path.join(BASE_DIR, '..', 'client', 'src', 'graphql', 'gql', 'queries')
|
||||||
GRAPHQL_MUTATIONS_DIR = os.path.join(GRAPHQL_QUERIES_DIR, '../mutations')
|
GRAPHQL_MUTATIONS_DIR = os.path.join(GRAPHQL_QUERIES_DIR, '../mutations')
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,26 @@
|
||||||
|
# Generated by Django 3.2.13 on 2022-07-28 08:48
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
import wagtail.core.blocks
|
||||||
|
import wagtail.core.fields
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('rooms', '0011_alter_roomentry_contents'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='comment',
|
||||||
|
name='room_entry',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments', to='rooms.roomentry'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='roomentry',
|
||||||
|
name='contents',
|
||||||
|
field=wagtail.core.fields.StreamField([('text_block', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.RichTextBlock(features=['ul', 'bold']))])), ('image_url_block', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.TextBlock()), ('url', wagtail.core.blocks.URLBlock())])), ('link_block', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.TextBlock()), ('url', wagtail.core.blocks.URLBlock())])), ('document_block', wagtail.core.blocks.StructBlock([('url', wagtail.core.blocks.URLBlock())])), ('subtitle', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.TextBlock())])), ('video_block', wagtail.core.blocks.StructBlock([('url', wagtail.core.blocks.URLBlock())]))], blank=True, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.2.13 on 2022-07-28 08:48
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('users', '0031_alter_license_isbn'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='license',
|
||||||
|
name='isbn',
|
||||||
|
field=models.CharField(default='978-3-0355-1397-4', max_length=50),
|
||||||
|
),
|
||||||
|
]
|
||||||
Loading…
Reference in New Issue