diff --git a/server/api/schema.py b/server/api/schema.py index 2bfb147c..f52cc2dd 100644 --- a/server/api/schema.py +++ b/server/api/schema.py @@ -27,7 +27,7 @@ from users.mutations import ProfileMutations class CustomQuery(UsersQuery, AllUsersQuery, ModuleRoomsQuery, RoomsQuery, ObjectivesQuery, BookQuery, AssignmentsQuery, - StudentSubmissionQuery, BasicKnowledgeQuery, PortfolioQuery, SurveysQuery, AllNewsTeasersQuery, graphene.ObjectType): + StudentSubmissionQuery, BasicKnowledgeQuery, PortfolioQuery, SurveysQuery, AllNewsTeasersQuery, graphene.ObjectType): node = relay.Node.Field() if settings.DEBUG: diff --git a/server/basicknowledge/migrations/0008_auto_20211020_1202.py b/server/basicknowledge/migrations/0008_auto_20211020_1202.py new file mode 100644 index 00000000..5194e011 --- /dev/null +++ b/server/basicknowledge/migrations/0008_auto_20211020_1202.py @@ -0,0 +1,27 @@ +# Generated by Django 2.2.24 on 2021-10-20 12:02 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('basicknowledge', '0007_basicknowledge_intro'), + ] + + operations = [ + migrations.CreateModel( + name='InstrumentType', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ('category', models.CharField(choices=[('language_communication', 'Sprache & Kommunikation'), ('society', 'Gesellschaft'), ('interdisciplinary', 'Überfachliches Instrument')], max_length=100)), + ], + ), + migrations.AddField( + model_name='basicknowledge', + name='new_type', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='basicknowledge.InstrumentType'), + ), + ] diff --git a/server/basicknowledge/models.py b/server/basicknowledge/models.py index 128b95f3..dc317e7e 100644 --- a/server/basicknowledge/models.py +++ b/server/basicknowledge/models.py @@ -1,13 +1,31 @@ from django.db import models from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel -from wagtail.core.fields import StreamField, RichTextField +from wagtail.core.fields import RichTextField, StreamField from wagtail.images.blocks import ImageChooserBlock -from books.blocks import LinkBlock, VideoBlock, DocumentBlock, SectionTitleBlock, InfogramBlock, \ - GeniallyBlock, InstrumentTextBlock, SubtitleBlock, ThinglinkBlock +from books.blocks import DocumentBlock, GeniallyBlock, InfogramBlock, InstrumentTextBlock, LinkBlock, SectionTitleBlock, \ + SubtitleBlock, ThinglinkBlock, VideoBlock from core.constants import DEFAULT_RICH_TEXT_FEATURES from core.wagtail_utils import StrictHierarchyPage +LANGUAGE_COMMUNICATION = 'language_communication' +SOCIETY = 'society' +INTERDISCIPLINARY = 'interdisciplinary' + +CATEGORY_CHOICES = ( + (LANGUAGE_COMMUNICATION, 'Sprache & Kommunikation'), + (SOCIETY, 'Gesellschaft'), + (INTERDISCIPLINARY, 'Überfachliches Instrument'), +) + + +class InstrumentType(models.Model): + name = models.CharField(max_length=255) + category = models.CharField( + max_length=100, + choices=CATEGORY_CHOICES + ) + class BasicKnowledge(StrictHierarchyPage): parent_page_types = ['books.book'] @@ -27,19 +45,11 @@ class BasicKnowledge(StrictHierarchyPage): ('subtitle', SubtitleBlock()), ], null=True, blank=True) - LANGUAGE_COMMUNICATION = 'language_communication' - SOCIETY = 'society' - INTERDISCIPLINARY = 'interdisciplinary' - - TYPE_CHOICES = ( - (LANGUAGE_COMMUNICATION, 'Sprache & Kommunikation'), - (SOCIETY, 'Gesellschaft'), - (INTERDISCIPLINARY, 'Überfachliches Instrument'), - ) + new_type = models.ForeignKey(InstrumentType, null=True, on_delete=models.PROTECT) type = models.CharField( max_length=100, - choices=TYPE_CHOICES + choices=CATEGORY_CHOICES ) content_panels = [ diff --git a/server/basicknowledge/queries.py b/server/basicknowledge/queries.py index 3481c057..73cd774d 100644 --- a/server/basicknowledge/queries.py +++ b/server/basicknowledge/queries.py @@ -28,7 +28,7 @@ class InstrumentNode(DjangoObjectType): class BasicKnowledgeQuery(object): instrument = graphene.Field(InstrumentNode, slug=graphene.String(), id=graphene.ID()) - instruments = DjangoFilterConnectionField(InstrumentNode) + instruments = graphene.List(InstrumentNode) def resolve_instrument(self, info, **kwargs): slug = kwargs.get('slug') diff --git a/server/schema.graphql b/server/schema.graphql index 2ca10551..b835edf2 100644 --- a/server/schema.graphql +++ b/server/schema.graphql @@ -461,7 +461,7 @@ type CustomQuery { project(id: ID, slug: String): ProjectNode projects: [ProjectNode] instrument(slug: String, id: ID): InstrumentNode - instruments(offset: Int, before: String, after: String, first: Int, last: Int, slug: String, type: String): InstrumentNodeConnection + instruments: [InstrumentNode] studentSubmission(id: ID!): StudentSubmissionNode assignment(id: ID!): AssignmentNode assignments(offset: Int, before: String, after: String, first: Int, last: Int): AssignmentNodeConnection