Add assignment query on server

This commit is contained in:
Ramon Wenger 2018-10-02 10:07:36 +02:00
parent 107b5735e9
commit d35c151cfb
7 changed files with 69 additions and 6 deletions

View File

@ -3,6 +3,7 @@
from graphene.types import Scalar
from graphene_django.converter import convert_django_field
from graphql_relay import to_global_id
from wagtail.core.fields import StreamField
from wagtail.images.models import Image
@ -29,12 +30,12 @@ class GenericStreamFieldType(Scalar):
_value = d['value']
assignment = Assignment.objects.get(pk=_value['assignment_id'])
value = {
'title' : assignment.title,
'assignment': assignment.assignment
'title': assignment.title,
'assignment': assignment.assignment,
'id': to_global_id('AssignmentNode', assignment.pk)
}
d['value'] = value
# value = dict(d['value'])
# if 'document' in value:
# value['document'] = Document.objects.get(id=value['document']).file.url

View File

@ -5,6 +5,8 @@ from graphene_django.debug import DjangoDebug
# noinspection PyUnresolvedReferences
from api import graphene_wagtail # Keep this import exactly here, it's necessary for StreamField conversion
from assignments.schema.mutations import AssignmentMutations
from assignments.schema.queries import AssignmentsQuery
from book.schema.mutations import BookMutations
from filteredbook.schema import BookQuery
@ -14,14 +16,14 @@ from rooms.schema import RoomsQuery
from user.schema import UsersQuery
class Query(UsersQuery, RoomsQuery, ObjectivesQuery, BookQuery, graphene.ObjectType):
class Query(UsersQuery, RoomsQuery, ObjectivesQuery, BookQuery, AssignmentsQuery, graphene.ObjectType):
node = relay.Node.Field()
if settings.DEBUG:
debug = graphene.Field(DjangoDebug, name='__debug')
class Mutation(BookMutations, RoomMutations, graphene.ObjectType):
class Mutation(BookMutations, RoomMutations, AssignmentMutations, graphene.ObjectType):
if settings.DEBUG:
debug = graphene.Field(DjangoDebug, name='__debug')

View File

@ -0,0 +1,24 @@
# Generated by Django 2.0.6 on 2018-10-01 12:54
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('assignments', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='studentsubmission',
name='final',
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name='studentsubmission',
name='assignment',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='submissions', to='assignments.Assignment'),
),
]

View File

@ -23,3 +23,4 @@ class StudentSubmission(TimeStampedModel):
document = models.FilePathField(null=True)
assignment = models.ForeignKey(Assignment, on_delete=models.CASCADE, related_name='submissions')
student = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
final = models.BooleanField(default=False)

View File

@ -0,0 +1,10 @@
from graphene import relay
import graphene
from graphene_django.filter import DjangoFilterConnectionField
from assignments.schema.types import AssignmentNode
class AssignmentsQuery(object):
assignment = relay.Node.Field(AssignmentNode)
assignments = DjangoFilterConnectionField(AssignmentNode)

View File

@ -17,7 +17,11 @@ class AssignmentNode(DjangoObjectType):
class Meta:
model = Assignment
filter_fields = []
interfaces = (relay.Node,)
def resolve_submission(self, info, **kwargs):
return self.submissions.get(student=info.context.user)
return self.submissions.get(student=info.context.user)
def resolve_submissions(self, info, **kwargs):
return self.submissions.all()

View File

@ -0,0 +1,21 @@
# Generated by Django 2.0.6 on 2018-10-01 12:54
from django.db import migrations
import wagtail.core.blocks
import wagtail.core.fields
import wagtail.images.blocks
class Migration(migrations.Migration):
dependencies = [
('book', '0004_auto_20180927_0945'),
]
operations = [
migrations.AlterField(
model_name='contentblock',
name='contents',
field=wagtail.core.fields.StreamField([('text_block', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.RichTextBlock())])), ('basic_knowledge', wagtail.core.blocks.StructBlock([('description', wagtail.core.blocks.RichTextBlock()), ('url', wagtail.core.blocks.URLBlock())])), ('assignment', wagtail.core.blocks.StructBlock([('assignment_id', wagtail.core.blocks.IntegerBlock())])), ('image_block', wagtail.images.blocks.ImageChooserBlock()), ('image_url_block', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.RichTextBlock()), ('url', wagtail.core.blocks.URLBlock())])), ('link_block', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.TextBlock()), ('url', wagtail.core.blocks.URLBlock())])), ('task', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.RichTextBlock())], icon='tick')), ('video_block', wagtail.core.blocks.StructBlock([('url', wagtail.core.blocks.URLBlock())])), ('document_block', wagtail.core.blocks.StructBlock([('url', wagtail.core.blocks.URLBlock())]))], blank=True, null=True),
),
]