Merge branch 'hotfix/spellcheck-new-data-structure' into develop
This commit is contained in:
commit
1f4cfb41e7
|
|
@ -1,8 +1,6 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import graphene
|
import graphene
|
||||||
from django.conf import settings
|
|
||||||
from graphene import relay
|
|
||||||
|
|
||||||
# class SpellCheckPartNode(graphene.ObjectType):
|
# class SpellCheckPartNode(graphene.ObjectType):
|
||||||
# sentence = graphene.String()
|
# sentence = graphene.String()
|
||||||
|
|
@ -12,11 +10,13 @@ from graphene import relay
|
||||||
# corrected = graphene.String()
|
# corrected = graphene.String()
|
||||||
from api.utils import get_object
|
from api.utils import get_object
|
||||||
from assignments.models import Assignment
|
from assignments.models import Assignment
|
||||||
|
from django.conf import settings
|
||||||
|
from graphene import relay
|
||||||
from spellcheck.client import TaskbaseClient
|
from spellcheck.client import TaskbaseClient
|
||||||
|
|
||||||
|
|
||||||
def sentence_offset_to_snake_case(result):
|
def sentence_offset_to_snake_case(result):
|
||||||
result['sentence_offset'] = result['sentenceOffset']
|
result["sentence_offset"] = result["sentenceOffset"]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -42,27 +42,40 @@ class SpellCheck(relay.ClientIDMutation):
|
||||||
@classmethod
|
@classmethod
|
||||||
def mutate_and_get_payload(cls, root, info, **kwargs):
|
def mutate_and_get_payload(cls, root, info, **kwargs):
|
||||||
user = info.context.user
|
user = info.context.user
|
||||||
text = kwargs.get('text')
|
text = kwargs.get("text")
|
||||||
assignment_id = kwargs.get('assignment')
|
assignment_id = kwargs.get("assignment")
|
||||||
|
|
||||||
assignment = get_object(Assignment, assignment_id)
|
assignment = get_object(Assignment, assignment_id)
|
||||||
|
|
||||||
client = TaskbaseClient(settings.TASKBASE_USER, settings.TASKBASE_PASSWORD, settings.TASKBASE_BASEURL)
|
client = TaskbaseClient(
|
||||||
|
settings.TASKBASE_USER,
|
||||||
|
settings.TASKBASE_PASSWORD,
|
||||||
|
settings.TASKBASE_BASEURL,
|
||||||
|
)
|
||||||
|
|
||||||
if assignment.taskbase_id is None or assignment.taskbase_id == '':
|
if assignment.taskbase_id is None or assignment.taskbase_id == "":
|
||||||
# we need to use another user (with more privileges) here, because why not
|
# we need to use another user (with more privileges) here, because why not
|
||||||
superclient = TaskbaseClient(settings.TASKBASE_SUPERUSER, settings.TASKBASE_SUPERPASSWORD,
|
superclient = TaskbaseClient(
|
||||||
settings.TASKBASE_BASEURL)
|
settings.TASKBASE_SUPERUSER,
|
||||||
|
settings.TASKBASE_SUPERPASSWORD,
|
||||||
|
settings.TASKBASE_BASEURL,
|
||||||
|
)
|
||||||
superclient.register_assignment(assignment)
|
superclient.register_assignment(assignment)
|
||||||
|
|
||||||
data = json.loads(client.spellcheck(assignment.taskbase_id, text))
|
data = json.loads(client.spellcheck(assignment.taskbase_id, text))
|
||||||
|
|
||||||
|
# it seems that there is new nesting inside the data, we're interested in the gradingFeedback
|
||||||
|
feedback = data["gradingFeedback"]
|
||||||
|
|
||||||
# the property is called sentenceOffset, but graphene expects the property to be called sentence_offset.
|
# the property is called sentenceOffset, but graphene expects the property to be called sentence_offset.
|
||||||
# we convert it manually here. fixme: is there a better way to declare this in the SpellCheckStepNode?
|
# we convert it manually here. fixme: is there a better way to declare this in the SpellCheckStepNode?
|
||||||
transformed_results = list(map(lambda x: x['part'], data['steps']))
|
transformed_results = list(map(lambda x: x["part"], feedback["steps"]))
|
||||||
return cls(correct=data['correct'] == 'CORRECT', results=[
|
return cls(
|
||||||
|
correct=feedback["correct"] == "CORRECT",
|
||||||
|
results=[
|
||||||
sentence_offset_to_snake_case(result) for result in transformed_results
|
sentence_offset_to_snake_case(result) for result in transformed_results
|
||||||
])
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SpellCheckMutations:
|
class SpellCheckMutations:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue