Skip to content

Commit

Permalink
feat: add status updates for interactions in the student view (#26)
Browse files Browse the repository at this point in the history
* feat: add status updates for interactions in the student view
  • Loading branch information
mariajgrimaldi authored Oct 12, 2023
1 parent 0ae9fbd commit 67ef880
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
32 changes: 31 additions & 1 deletion h5pxblock/h5pxblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import logging
import pkg_resources
from enum import Enum

from django.conf import settings
from django.utils import timezone
Expand All @@ -30,6 +31,14 @@

H5P_STORAGE = get_h5p_storage()


class SubmissionStatus(Enum):
"""Submission options for the assignment."""

NOT_ATTEMPTED = _("Not attempted")
COMPLETED = _("Completed")


@XBlock.wants('user')
@XBlock.wants('i18n')
class H5PPlayerXBlock(XBlock, CompletableXBlockMixin):
Expand Down Expand Up @@ -128,6 +137,23 @@ class H5PPlayerXBlock(XBlock, CompletableXBlockMixin):
scope=Scope.settings,
)

weighted_score = Float(
display_name=_("Problem weighted score"),
help=_(
"Defines the weighted score of this problem. If "
"the value is not set, the problem is worth one point."
),
scope=Scope.user_state,
default=0,
)

submission_status = String(
display_name=_("Submission status"),
help=_("The submission status of the assignment."),
default=SubmissionStatus.NOT_ATTEMPTED.value,
scope=Scope.user_state,
)

h5p_content_meta = Dict(scope=Scope.content)
has_author_view = True

Expand All @@ -153,7 +179,7 @@ def render_template(self, template_path, context):
context,
i18n_service=self.runtime.service(self, 'i18n'),
)

def max_score(self):
return self.points

Expand Down Expand Up @@ -346,6 +372,7 @@ def result_handler(self, data, suffix=''):
try:
self.emit_completion(1.0)
save_completion = True
self.submission_status = SubmissionStatus.COMPLETED.value
except BaseException as exp:
log.error("Error while marking completion %s", exp)

Expand All @@ -370,6 +397,9 @@ def result_handler(self, data, suffix=''):
except BaseException as exp:
log.error("Error while publishing score %s", exp)

if save_score and score > self.weighted_score:
self.weighted_score = score

return Response(
json.dumps({"result": {"save_completion": save_completion, "save_score": save_score}}),
content_type="application/json",
Expand Down
3 changes: 3 additions & 0 deletions h5pxblock/static/html/h5pxblock.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

{% if h5pblock.h5p_content_json_path %}
<div class="h5pxblock_block">
{% if h5pblock.has_score %}
<p> ({{ h5pblock.weighted_score}}/{{ h5pblock.points | floatformat:1 }} {% trans "points" %}) {% trans h5pblock.submission_status %}</p>
{% endif %}
<div class="d-flex justify-content-center spinner-container">
<div class="spinner-border" role="status">
<span class="sr-only">{% trans "Loading..." %}</span>
Expand Down

0 comments on commit 67ef880

Please sign in to comment.