Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement way of sending Acos grading results to LTI platform #1166

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions exercise/async_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def _post_async_submission(request, exercise, submission, errors=None):
submission.feedback = form.cleaned_data["feedback"]
submission.grading_data = post_data

# Acos-submissions initialize this as an empty string for some reason; fix here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Submission.meta_data field uses our old custom JSONField that is simply a normal TextField with some extra JSON parsing. Thus, its default value is an empty string. In the case of Acos exercises, no value is set to the submission.meta_data field before this point. The submission is created here:

submission = Submission.objects.create(exercise=self.exercise)

if submission.meta_data == "":
submission.meta_data = {}
if form.cleaned_data["lti_launch_id"]:
submission.meta_data["lti-launch-id"] = form.cleaned_data["lti_launch_id"]

if form.cleaned_data["error"]:
submission.set_error()
else:
Expand Down
11 changes: 7 additions & 4 deletions exercise/exercise_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ def get_load_url(
)
return self._build_service_url(
language, students,
ordinal, url_name, submission_url
ordinal, url_name, submission_url, lti_launch_id=request.session.get("lti-launch-id")
)
return super().get_load_url(language, request, students, url_name, ordinal)

Expand Down Expand Up @@ -994,20 +994,23 @@ def modify_post_parameters(self, data, files, user, students, request, url):
"""
pass

def _build_service_url(self, language, students, ordinal_number, url_name, submission_url):
def _build_service_url(self, language, students, ordinal_number, url_name, submission_url, lti_launch_id=None):
"""
Generates complete URL with added parameters to the exercise service.
"""
uid_str = '-'.join(sorted(str(profile.user.id) for profile in students)) if students else ''
return update_url_params(self.get_service_url(language), {
params = {
"max_points": self.max_points,
"max_submissions": self.max_submissions,
"submission_url": build_aplus_url(submission_url),
"post_url": build_aplus_url(str(self.get_url(url_name)), user_url=True),
"uid": uid_str,
"ordinal_number": ordinal_number,
"lang": language,
})
}
if lti_launch_id:
params["lti_launch_id"] = lti_launch_id
return update_url_params(self.get_service_url(language), params)

@property
def can_regrade(self):
Expand Down
1 change: 1 addition & 0 deletions exercise/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class SubmissionCallbackForm(forms.Form):
feedback = forms.CharField(required=False)
notify = forms.CharField(required=False)
grading_payload = forms.CharField(required=False)
lti_launch_id = forms.CharField(required=False)
error = forms.BooleanField(required=False)

def clean(self):
Expand Down