Add category information to instrument queries
This commit is contained in:
parent
bd87999487
commit
37e4461a22
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
),
|
||||
]
|
||||
|
|
@ -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)
|
||||
]
|
||||
|
|
@ -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),
|
||||
),
|
||||
]
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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':
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue