Skip to content

Commit

Permalink
chore: address PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanttV committed Mar 8, 2024
1 parent bd7281a commit ee5334d
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 26 deletions.
8 changes: 8 additions & 0 deletions openassessment/runtime_imports/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@ def import_waffle_flag():
"""
from edx_toggles.toggles import WaffleFlag
return WaffleFlag


def import_student_module():
"""
Helper method that imports StudentModule from edx-platform at runtime.
"""
from lms.djangoapps.courseware.models import StudentModule
return StudentModule
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
</select>
</div>
<p class="setting-help">
{% trans "Specify whether learners can reset and resubmit their work within the alocated period as long as it has not yet been graded." %}
{% trans "Specify whether learners can reset and resubmit their work within an allocated period as long as it has not yet been graded." %}
</p>
<div id="openassessment_resubmissions_grace_period_wrapper" class="{% if not allow_learner_resubmissions %}is--hidden{% endif %}">
<div class="wrapper-comp-setting">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ <h5 class="message__title">{% trans "We could not reset your response" %}</h5>
<ul class="list list--actions">
<li class="list--actions__item">
<button class="action action--submit reset__submission">
{% trans "Reset your submission to be able to sent it again" %}
{% trans "Reset your submission to be able to send it again" %}
</button>
</li>
</ul>
Expand Down
23 changes: 17 additions & 6 deletions openassessment/xblock/openassessmentblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import pytz

from django.conf import settings
from django.contrib.auth import get_user_model
from django.template.loader import get_template

from bleach.sanitizer import Cleaner
Expand All @@ -21,6 +22,7 @@
from xblock.fields import Boolean, Dict, Integer, List, Scope, String

from openassessment.runtime_imports.functions import reset_student_attempts, get_user_by_username_or_email
from openassessment.runtime_imports.classes import import_student_module
from openassessment.staffgrader.staff_grader_mixin import StaffGraderMixin
from openassessment.workflow.errors import AssessmentWorkflowError
from openassessment.xblock.apis.grades_api import GradesAPI
Expand Down Expand Up @@ -193,13 +195,13 @@ class OpenAssessmentBlock(
resubmissions_grace_period_hours = Integer(
default=0,
scope=Scope.content,
help="The number of hours after the submission due date that resubmissions are allowed."
help="The number of hours after the student's submission date that resubmissions are allowed."
)

resubmissions_grace_period_minutes = Integer(
default=0,
scope=Scope.content,
help="The number of minutes after the submission due date that resubmissions are allowed."
help="The number of minutes after the student's submission date that resubmissions are allowed."
)

rubric_criteria = List(
Expand Down Expand Up @@ -1367,13 +1369,22 @@ def reset_submission(self, data, suffix=""): # pylint: disable=unused-argument
Returns:
dict: A dictionary indication the status with keys 'success' (bool) and 'msg' (str)
"""
StudentModule = import_student_module() # pylint: disable=invalid-name
block_user = self.runtime.service(self, "user").get_current_user()
username = block_user.opt_attrs.get("edx-platform.username")

try:
user = get_user_by_username_or_email(username)
except get_user_model().DoesNotExist as error:
logger.exception(f"An error occurred while resetting the submission: {error}")
return {"success": False, "msg": self._("The user does not exist.")}

try:
block_user = self.runtime.service(self, "user").get_current_user()
user = get_user_by_username_or_email(block_user.opt_attrs.get("edx-platform.username"))
reset_student_attempts(self.course_id, user, self.location, user, True) # pylint: disable=no-member
except Exception as error:
except StudentModule.DoesNotExist as error:
logger.exception(f"An error occurred while resetting the submission: {error}")
return {"success": False, "msg": self._("Error resetting submission.")}
return {"success": False, "msg": self._("There is no submission to reset.")}

return {"success": True, "msg": self._("Submission reset successfully.")}

@XBlock.json_handler
Expand Down
20 changes: 10 additions & 10 deletions openassessment/xblock/test/data/update_xblock.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@
"show_rubric_during_response": false,
"allow_latex": false,
"allow_learner_resubmissions": true,
"resubmissions_grace_period_hours": 0,
"resubmissions_grace_period_minutes": 0,
"resubmissions_grace_period_hours": 1,
"resubmissions_grace_period_minutes": 30,
"leaderboard_show": 0,
"assessments": [
{
Expand Down Expand Up @@ -166,8 +166,8 @@
"show_rubric_during_response": false,
"allow_latex": false,
"allow_learner_resubmissions": true,
"resubmissions_grace_period_hours": 0,
"resubmissions_grace_period_minutes": 0,
"resubmissions_grace_period_hours": 2,
"resubmissions_grace_period_minutes": 59,
"leaderboard_show": 0,
"assessments": [
{
Expand Down Expand Up @@ -227,7 +227,7 @@
"show_rubric_during_response": false,
"allow_latex": false,
"allow_learner_resubmissions": true,
"resubmissions_grace_period_hours": 0,
"resubmissions_grace_period_hours": 3,
"resubmissions_grace_period_minutes": 0,
"leaderboard_show": 0,
"assessments": [
Expand Down Expand Up @@ -300,7 +300,7 @@
"allow_latex": false,
"allow_learner_resubmissions": true,
"resubmissions_grace_period_hours": 0,
"resubmissions_grace_period_minutes": 0,
"resubmissions_grace_period_minutes": 40,
"leaderboard_show": 0,
"title": "My new title.",
"assessments": [
Expand Down Expand Up @@ -361,7 +361,7 @@
"allow_latex": false,
"allow_learner_resubmissions": true,
"resubmissions_grace_period_hours": 0,
"resubmissions_grace_period_minutes": 0,
"resubmissions_grace_period_minutes": 1,
"leaderboard_show": 0,
"title": "My new title.",
"assessments": [
Expand Down Expand Up @@ -421,7 +421,7 @@
"show_rubric_during_response": false,
"allow_latex": false,
"allow_learner_resubmissions": true,
"resubmissions_grace_period_hours": 0,
"resubmissions_grace_period_hours": 1,
"resubmissions_grace_period_minutes": 0,
"leaderboard_show": 0,
"title": "My new title.",
Expand Down Expand Up @@ -482,8 +482,8 @@
"show_rubric_during_response": false,
"allow_latex": false,
"allow_learner_resubmissions": true,
"resubmissions_grace_period_hours": 0,
"resubmissions_grace_period_minutes": 0,
"resubmissions_grace_period_hours": 5,
"resubmissions_grace_period_minutes": 5,
"leaderboard_show": 0,
"title": "My new title.",
"assessments": [
Expand Down
15 changes: 7 additions & 8 deletions openassessment/xblock/utils/allow_resubmission.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,19 @@ def submission_date_exceeded(config_data, submission_data: dict) -> bool:
Returns:
bool: True if the submission date has been exceeded, False otherwise.
"""
ora_due_date = datetime.strptime(config_data.submission_due, "%Y-%m-%dT%H:%M:%S%z")
current_datetime = datetime.now(pytz.UTC)
ora_due_date = ora_due_date.replace(tzinfo=pytz.UTC)
if current_datetime >= ora_due_date:
is_closed, reason, _, _ = config_data.is_closed(step="submission")
if is_closed and reason == "due":
return True

hours = config_data.resubmissions_grace_period_hours
minutes = config_data.resubmissions_grace_period_minutes
if hours == 0 and minutes == 0:
if not hours and not minutes:
return False

delta_time = timedelta(hours=int(hours), minutes=int(minutes))
grace_period = submission_data["created_at"] + delta_time
return current_datetime >= grace_period
current_datetime = datetime.now(pytz.UTC)
grace_period = timedelta(hours=int(hours), minutes=int(minutes))
deadline_datetime = submission_data["created_at"] + grace_period
return current_datetime >= deadline_datetime


def has_been_graded(workflow_data) -> bool:
Expand Down

0 comments on commit ee5334d

Please sign in to comment.