Skip to content

Commit

Permalink
Fix LTI Tool linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ihalaij1 committed May 30, 2023
1 parent 1998a0e commit a250bdb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
1 change: 0 additions & 1 deletion lti_tool/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.conf.urls import url

from . import views
from exercise.views import SubmissionPollView
from course.urls import INSTANCE_URL_PREFIX, MODULE_URL_PREFIX
from exercise.urls import EXERCISE_URL_PREFIX, SUBMISSION_URL_PREFIX

Expand Down
9 changes: 4 additions & 5 deletions lti_tool/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from datetime import datetime

from django.conf import settings
from django.contrib.auth.models import User
from pylti1p3.grade import Grade
Expand All @@ -13,21 +13,20 @@ def get_launch_url(request):
target_link_uri = request.POST.get('target_link_uri', request.GET.get('target_link_uri'))
if not target_link_uri:
logger.error('Missing "target_link_uri" param')
raise Exception('Missing "target_link_uri" param')
raise Exception('Missing "target_link_uri" param') # pylint: disable=broad-exception-raised
return target_link_uri

def get_tool_conf():
# Cannot default to DjangoDbToolConf() in settings.py due to models not being initialized yet
if hasattr(settings, "LTI_TOOL_CONF"):
return settings.LTI_TOOL_CONF
else:
return DjangoDbToolConf()
return DjangoDbToolConf()

def get_launch_data_storage():
return DjangoCacheDataStorage()

def send_lti_points(request, submission):
from exercise.exercise_summary import UserExerciseSummary
from exercise.exercise_summary import UserExerciseSummary # pylint: disable=import-outside-toplevel
exercise = submission.exercise
request.COOKIES['lti1p3-session-id'] = submission.meta_data.get('lti-session-id')
try:
Expand Down
36 changes: 22 additions & 14 deletions lti_tool/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@ def post(self, request, *args, **kwargs):
last_name=self.message_launch_data["family_name"],
)
profile = self.user.userprofile
profile.language = self.message_launch_data["https://purl.imsglobal.org/spec/lti/claim/launch_presentation"]["locale"]
profile.student_id = self.message_launch_data["https://purl.imsglobal.org/spec/lti/claim/lis"]["person_sourcedid"]
profile.language = (
self.message_launch_data["https://purl.imsglobal.org/spec/lti/claim/launch_presentation"]["locale"]
)
profile.student_id = (
self.message_launch_data["https://purl.imsglobal.org/spec/lti/claim/lis"]["person_sourcedid"]
)
# Note: profile.organization is not set since we can't know it
# based on the LTI launch.
profile.save()
Expand All @@ -86,36 +90,34 @@ def post(self, request, *args, **kwargs):
roles = self.message_launch_data["https://purl.imsglobal.org/spec/lti/claim/roles"]
is_course_teacher = instance.is_course_staff(self.user)
if "http://purl.imsglobal.org/vocab/lis/v2/membership#Learner" in roles and not is_course_teacher:
enrolment_success = instance.enroll_student(self.user)
instance.enroll_student(self.user)

if "exercise_path" in launch_params:
url_params = {
k: launch_params[k] for k in ["exercise_path", "module_slug", "course_slug", "instance_slug"]
}
return redirect("lti-exercise", **url_params)
elif "module_slug" in launch_params:
if "module_slug" in launch_params:
url_params = {
k: launch_params[k] for k in ["module_slug", "course_slug", "instance_slug"]
}
return redirect("lti-module", **url_params)
elif "course_slug" in launch_params and "instance_slug" in launch_params:
if "course_slug" in launch_params and "instance_slug" in launch_params:
url_params = {
k: launch_params[k] for k in ["course_slug", "instance_slug"]
}
return redirect("lti-course", **url_params)
else:
raise LtiException("Invalid parameters for an LTI launch")
elif message_launch.is_deep_link_launch():
raise LtiException("Invalid parameters for an LTI launch")
if message_launch.is_deep_link_launch():
return redirect("lti-select-content")
else:
raise LtiException("Invalid LTI launch type")
raise LtiException("Invalid LTI launch type")


class LtiSessionMixin(BaseMixin):

@method_decorator(xframe_options_exempt)
def dispatch(self, *args, **kwargs):
return super().dispatch(*args, **kwargs)
def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)

def parse_lti_session_params(self):
launch_id = self.request.session.get("lti-launch-id", None)
Expand Down Expand Up @@ -269,7 +271,13 @@ def post(self, request, *args, **kwargs):
"course_slug": kwargs['course_slug'],
"instance_slug": kwargs['instance_slug']
})
.set_title("{}: {}".format(pick_localized(self.course.name, 'en'), pick_localized(self.instance.instance_name, 'en'))))
.set_title(
"{}: {}".format(
pick_localized(self.course.name, 'en'),
pick_localized(self.instance.instance_name, 'en')
)
)
)
return HttpResponse(deep_link.output_response_form([resource]))

# Get list of modules in course
Expand Down Expand Up @@ -340,7 +348,7 @@ def post(self, request, *args, **kwargs):
.set_score_maximum(self.exercise.max_points)
.set_label(pick_localized(str(self.exercise), 'en')))
ags.find_or_create_lineitem(li)
except AttributeError as e:
except AttributeError:
logger.info("Importing LTI exercise with no max_points attribute")

# Send activity settings
Expand Down

0 comments on commit a250bdb

Please sign in to comment.