diff --git a/server/api/graphene_wagtail.py b/server/api/graphene_wagtail.py index 4f335910..3b42571c 100644 --- a/server/api/graphene_wagtail.py +++ b/server/api/graphene_wagtail.py @@ -81,9 +81,10 @@ def augment_fields(raw_data): logger.error('Survey {} does not exist'.format(survey_id)) if _type == 'basic_knowledge' or _type == 'instrument': _value = data['value'] - basic_knowledge = BasicKnowledge.objects.get(pk=_value['basic_knowledge']) + instrument = BasicKnowledge.objects.get(pk=_value['basic_knowledge']) _value.update({ - 'slug': basic_knowledge.slug + 'slug': instrument.slug, + 'foreground': instrument.new_type.category.foreground }) data['value'] = _value diff --git a/server/books/migrations/0037_alter_contentblock_type.py b/server/books/migrations/0037_alter_contentblock_type.py new file mode 100644 index 00000000..ca0ab12c --- /dev/null +++ b/server/books/migrations/0037_alter_contentblock_type.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.13 on 2022-09-15 13:39 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('books', '0036_alter_contentblock_contents'), + ] + + operations = [ + migrations.AlterField( + model_name='contentblock', + name='type', + field=models.CharField(choices=[('normal', 'Normal'), ('base_communication', 'Instrument Sprache & Kommunikation'), ('task', 'Auftrag'), ('instrument', 'Instrument'), ('base_society', 'Instrument Gesellschaft'), ('base_interdisciplinary', 'Überfachliches Instrument')], default='normal', max_length=100), + ), + ] diff --git a/server/books/migrations/0038_auto_20220915_1340.py b/server/books/migrations/0038_auto_20220915_1340.py new file mode 100644 index 00000000..3069b5e0 --- /dev/null +++ b/server/books/migrations/0038_auto_20220915_1340.py @@ -0,0 +1,17 @@ +# Generated by Django 3.2.13 on 2022-09-15 13:40 + +from django.db import migrations + +def migrate_instruments(apps, schema_editor): + ContentBlock = apps.get_model('books', 'ContentBlock') + ContentBlock.objects.filter(type__startswith='base_').update(type='instrument') + +class Migration(migrations.Migration): + + dependencies = [ + ('books', '0037_alter_contentblock_type'), + ] + + operations = [ + migrations.RunPython(migrate_instruments, migrations.RunPython.noop) + ] diff --git a/server/books/migrations/0039_alter_contentblock_type.py b/server/books/migrations/0039_alter_contentblock_type.py new file mode 100644 index 00000000..db6d3135 --- /dev/null +++ b/server/books/migrations/0039_alter_contentblock_type.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.13 on 2022-09-15 14:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('books', '0038_auto_20220915_1340'), + ] + + operations = [ + migrations.AlterField( + model_name='contentblock', + name='type', + field=models.CharField(choices=[('normal', 'Normal'), ('task', 'Auftrag'), ('instrument', 'Instrument')], default='normal', max_length=100), + ), + ] diff --git a/server/books/models/contentblock.py b/server/books/models/contentblock.py index 1bd999b6..bc744823 100644 --- a/server/books/models/contentblock.py +++ b/server/books/models/contentblock.py @@ -26,17 +26,13 @@ class ContentBlock(StrictHierarchyPage): verbose_name_plural = 'Inhaltsblöcke' NORMAL = 'normal' - BASE_COMMUNICATION = 'base_communication' TASK = 'task' - BASE_SOCIETY = 'base_society' - BASE_INTERDISCIPLINARY = 'base_interdisciplinary' + INSTRUMENT = 'instrument' TYPE_CHOICES = ( (NORMAL, 'Normal'), - (BASE_COMMUNICATION, 'Instrument Sprache & Kommunikation'), (TASK, 'Auftrag'), - (BASE_SOCIETY, 'Instrument Gesellschaft'), - (BASE_INTERDISCIPLINARY, 'Überfachliches Instrument'), + (INSTRUMENT, 'Instrument'), ) # blocks without owner are visible by default, need to be hidden for each class diff --git a/server/books/schema/nodes/content.py b/server/books/schema/nodes/content.py index fd02c724..cebd3b03 100644 --- a/server/books/schema/nodes/content.py +++ b/server/books/schema/nodes/content.py @@ -2,6 +2,8 @@ import graphene from graphene import relay from graphene_django import DjangoObjectType +from basicknowledge.models import BasicKnowledge +from basicknowledge.queries import InstrumentCategoryNode from books.models import ContentBlock from books.schema.interfaces.contentblock import ContentBlockInterface from books.utils import are_solutions_enabled_for @@ -40,6 +42,7 @@ class ContentBlockNode(DjangoObjectType, HiddenAndVisibleForMixin): mine = graphene.Boolean() bookmarks = graphene.List(ContentBlockBookmarkNode) original_creator = graphene.Field('users.schema.PublicUserNode') + instrument_category = graphene.Field(InstrumentCategoryNode) class Meta: model = ContentBlock @@ -80,6 +83,17 @@ class ContentBlockNode(DjangoObjectType, HiddenAndVisibleForMixin): content_block=self ) + @staticmethod + def resolve_instrument_category(root: ContentBlock, info, **kwargs): + if root.type == ContentBlock.INSTRUMENT: + for content in root.contents.raw_data: + if content['type'] == 'instrument' or content['type'] == 'basic_knowledge': + _id = content['value']['basic_knowledge'] + instrument = BasicKnowledge.objects.get(id=_id) + category = instrument.new_type.category + return category + return None + def process_module_room_slug_block(content): if content['type'] == 'module_room_slug': diff --git a/server/schema.graphql b/server/schema.graphql index cd8c68d8..7a19e840 100644 --- a/server/schema.graphql +++ b/server/schema.graphql @@ -299,6 +299,7 @@ type ContentBlockNode implements Node & ContentBlockInterface { mine: Boolean bookmarks: [ContentBlockBookmarkNode] originalCreator: PublicUserNode + instrumentCategory: InstrumentCategoryNode } type ContentBlockNodeConnection { @@ -511,7 +512,7 @@ type InstrumentBookmarkNode implements Node { instrument: InstrumentNode! } -type InstrumentCategoryNode { +type InstrumentCategoryNode implements Node { id: ID! name: String! background: String! @@ -539,7 +540,7 @@ type InstrumentNodeEdge { cursor: String! } -type InstrumentTypeNode { +type InstrumentTypeNode implements Node { id: ID! name: String! category: InstrumentCategoryNode