Skip to content

Commit

Permalink
Merge pull request #17 from dmitry-viskov/pylti1p3-2-0-0
Browse files Browse the repository at this point in the history
Update PyLTI1p3 version (up to 2.0.0)
  • Loading branch information
dmitry-viskov authored Nov 29, 2022
2 parents 5670d2d + a9acd4d commit e6ea171
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 78 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM python:3.6.6-alpine3.7
FROM python:3.10.7-alpine3.16

RUN apk add --update \
build-base libffi-dev openssl-dev \
xmlsec xmlsec-dev \
&& rm -rf /var/cache/apk/*

ADD requirements.txt /tmp
RUN pip install --upgrade pip==21.1.1
RUN pip install --upgrade pip
RUN pip install -r /tmp/requirements.txt

EXPOSE 9001
Expand Down
12 changes: 12 additions & 0 deletions configs/game.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,17 @@
"private_key_file": "private2.key",
"public_key_file": "public2.key",
"deployment_ids": ["deployment-id"]
}],
"http://moodle.test": [{
"default": true,
"client_id": "LyRl2z2Ai4Vxgok",
"auth_login_url": "http://moodle.test/mod/lti/auth.php",
"auth_token_url": "http://moodle.test/mod/lti/token.php",
"auth_audience": null,
"key_set_url": "http://moodle.test/mod/lti/certs.php",
"key_set": null,
"private_key_file": "private.key",
"public_key_file": "public.key",
"deployment_ids": ["1"]
}]
}
3 changes: 1 addition & 2 deletions game/game/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'game',
'debug_toolbar',
]

MIDDLEWARE = [
'game.middleware.SameSiteMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
]

ROOT_URLCONF = 'game.urls'
Expand All @@ -61,6 +59,7 @@

SESSION_COOKIE_NAME = 'sessionid'
SESSION_COOKIE_SAMESITE = None # should be set as 'None' for Django >= 3.1
CSRF_COOKIE_SAMESITE = None
SESSION_COOKIE_SECURE = False # should be True in case of HTTPS usage (production)
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

Expand Down
24 changes: 8 additions & 16 deletions game/game/urls.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
from django.conf import settings
from django.conf.urls import url
from django.urls import include, path
from django.urls import re_path
from .views import login, launch, get_jwks, configure, score, scoreboard

urlpatterns = [
url(r'^login/$', login, name='game-login'),
url(r'^launch/$', launch, name='game-launch'),
url(r'^jwks/$', get_jwks, name='game-jwks'),
url(r'^configure/(?P<launch_id>[\w-]+)/(?P<difficulty>[\w-]+)/$', configure, name='game-configure'),
url(r'^api/score/(?P<launch_id>[\w-]+)/(?P<earned_score>[\w-]+)/(?P<time_spent>[\w-]+)/$', score,
name='game-api-score'),
url(r'^api/scoreboard/(?P<launch_id>[\w-]+)/$', scoreboard, name='game-api-scoreboard'),
re_path(r'^login/$', login, name='game-login'),
re_path(r'^launch/$', launch, name='game-launch'),
re_path(r'^jwks/$', get_jwks, name='game-jwks'),
re_path(r'^configure/(?P<launch_id>[\w-]+)/(?P<difficulty>[\w-]+)/$', configure, name='game-configure'),
re_path(r'^api/score/(?P<launch_id>[\w-]+)/(?P<earned_score>[\w-]+)/(?P<time_spent>[\w-]+)/$', score,
name='game-api-score'),
re_path(r'^api/scoreboard/(?P<launch_id>[\w-]+)/$', scoreboard, name='game-api-scoreboard'),
]

if settings.DEBUG:
import debug_toolbar
urlpatterns = [
path('__debug__/', include(debug_toolbar.urls)),
] + urlpatterns
130 changes: 75 additions & 55 deletions game/game/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,40 +139,51 @@ def score(request, launch_id, earned_score, time_spent):
earned_score = int(earned_score)
time_spent = int(time_spent)

grades = message_launch.get_ags()
sc = Grade()
sc.set_score_given(earned_score)\
.set_score_maximum(100)\
.set_timestamp(timestamp)\
.set_activity_progress('Completed')\
.set_grading_progress('FullyGraded')\
.set_user_id(sub)

sc_line_item = LineItem()
sc_line_item.set_tag('score')\
.set_score_maximum(100)\
.set_label('Score')
if resource_link_id:
sc_line_item.set_resource_id(resource_link_id)

grades.put_grade(sc, sc_line_item)

tm = Grade()
tm.set_score_given(time_spent)\
.set_score_maximum(999)\
.set_timestamp(timestamp)\
.set_activity_progress('Completed')\
.set_grading_progress('FullyGraded')\
.set_user_id(sub)

tm_line_item = LineItem()
tm_line_item.set_tag('time')\
.set_score_maximum(999)\
.set_label('Time Taken')
if resource_link_id:
tm_line_item.set_resource_id(resource_link_id)

result = grades.put_grade(tm, tm_line_item)
ags = message_launch.get_ags()

if ags.can_create_lineitem():
sc = Grade()
sc.set_score_given(earned_score)\
.set_score_maximum(100)\
.set_timestamp(timestamp)\
.set_activity_progress('Completed')\
.set_grading_progress('FullyGraded')\
.set_user_id(sub)

sc_line_item = LineItem()
sc_line_item.set_tag('score')\
.set_score_maximum(100)\
.set_label('Score')
if resource_link_id:
sc_line_item.set_resource_id(resource_link_id)

ags.put_grade(sc, sc_line_item)

tm = Grade()
tm.set_score_given(time_spent)\
.set_score_maximum(999)\
.set_timestamp(timestamp)\
.set_activity_progress('Completed')\
.set_grading_progress('FullyGraded')\
.set_user_id(sub)

tm_line_item = LineItem()
tm_line_item.set_tag('time')\
.set_score_maximum(999)\
.set_label('Time Taken')
if resource_link_id:
tm_line_item.set_resource_id(resource_link_id)

result = ags.put_grade(tm, tm_line_item)
else:
sc = Grade()
sc.set_score_given(earned_score) \
.set_score_maximum(100) \
.set_timestamp(timestamp) \
.set_activity_progress('Completed') \
.set_grading_progress('FullyGraded') \
.set_user_id(sub)
result = ags.put_grade(sc)

return JsonResponse({'success': True, 'result': result.get('body')})

Expand All @@ -193,33 +204,42 @@ def scoreboard(request, launch_id):

ags = message_launch.get_ags()

score_line_item = LineItem()
score_line_item.set_tag('score') \
.set_score_maximum(100) \
.set_label('Score')
if resource_link_id:
score_line_item.set_resource_id(resource_link_id)

scores = ags.get_grades(score_line_item)

time_line_item = LineItem()
time_line_item.set_tag('time') \
.set_score_maximum(999) \
.set_label('Time Taken')
if resource_link_id:
time_line_item.set_resource_id(resource_link_id)

times = ags.get_grades(time_line_item)
if ags.can_create_lineitem():
score_line_item = LineItem()
score_line_item.set_tag('score') \
.set_score_maximum(100) \
.set_label('Score')
if resource_link_id:
score_line_item.set_resource_id(resource_link_id)

score_line_item = ags.find_or_create_lineitem(score_line_item)
scores = ags.get_grades(score_line_item)

time_line_item = LineItem()
time_line_item.set_tag('time') \
.set_score_maximum(999) \
.set_label('Time Taken')
if resource_link_id:
time_line_item.set_resource_id(resource_link_id)

time_line_item = ags.find_or_create_lineitem(time_line_item)
times = ags.get_grades(time_line_item)
else:
scores = ags.get_grades()
times = None

members = message_launch.get_nrps().get_members()
scoreboard_result = []

for sc in scores:
result = {'score': sc['resultScore']}
for tm in times:
if tm['userId'] == sc['userId']:
result['time'] = tm['resultScore']
break
if times is None:
result['time'] = 'Not set'
else:
for tm in times:
if tm['userId'] == sc['userId']:
result['time'] = tm['resultScore']
break
for member in members:
if member['user_id'] == sc['userId']:
result['name'] = member.get('name', 'Unknown')
Expand Down
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cryptography==3.2.1
django==3.1.13
django-debug-toolbar==2.2.1
PyLTI1p3==1.9.1
django==4.1.1
PyLTI1p3==2.0.0

0 comments on commit e6ea171

Please sign in to comment.