Skip to content

Commit

Permalink
Makes xblock due_date & graceperiod aware
Browse files Browse the repository at this point in the history
- Adds mixin to check subsection duedate and course graceperiod
- Pushes version to 0.1.8
  • Loading branch information
Giulio Gratta committed Nov 15, 2017
1 parent ce29dae commit 5e21deb
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 10 deletions.
15 changes: 13 additions & 2 deletions freetextresponse/freetextresponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
from xblock.fragment import Fragment
from xblock.validation import ValidationMessage
from xblockutils.studio_editable import StudioEditableXBlockMixin
from .mixins import EnforceDueDates


@XBlock.needs("i18n")
class FreeTextResponse(StudioEditableXBlockMixin, XBlock):
class FreeTextResponse(EnforceDueDates, StudioEditableXBlockMixin, XBlock):
# pylint: disable=too-many-ancestors, too-many-instance-attributes
"""
Enables instructors to create questions with free-text responses.
Expand Down Expand Up @@ -264,6 +265,7 @@ def student_view(self, context={}):
'problem_progress': self._get_problem_progress(),
'prompt': self.prompt,
'student_answer': self.student_answer,
'is_past_due': self.is_past_due(),
'used_attempts_feedback': self._get_used_attempts_feedback(),
'visibility_class': self._get_indicator_visibility_class(),
'word_count_message': self._get_word_count_message(),
Expand Down Expand Up @@ -539,6 +541,15 @@ def _get_user_alert(self, ignore_attempts=False):
result = self._get_invalid_word_count_message(ignore_attempts)
return result

def _can_submit(self):
if self.is_past_due():
return False
if self.max_attempts == 0:
return True
if self.count_attempts < self.max_attempts:
return True
return False

@XBlock.json_handler
def submit(self, data, suffix=''):
# pylint: disable=unused-argument
Expand All @@ -547,7 +558,7 @@ def submit(self, data, suffix=''):
"""
# Fails if the UI submit/save buttons were shut
# down on the previous sumbisson
if self.max_attempts == 0 or self.count_attempts < self.max_attempts:
if self._can_submit():
self.student_answer = data['student_answer']
# Counting the attempts and publishing a score
# even if word count is invalid.
Expand Down
33 changes: 33 additions & 0 deletions freetextresponse/mixins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
Mixins for the Free Text Response XBlock
"""
import datetime
import pytz
from django.conf import settings

TIME_ZONE = pytz.timezone(getattr(settings, 'TIME_ZONE', pytz.utc.zone))


class EnforceDueDates(object): # pylint: disable=too-few-public-methods
"""
xBlock Mixin to allow xblocks to check the due date
(taking the graceperiod into account) of the
subsection in which they are placed
"""

# These values are pulled from platform.
# They are defaulted to None for tests.
due = None
graceperiod = None

def is_past_due(self):
"""
Determine if component is past-due
"""
now = datetime.datetime.utcnow().replace(tzinfo=TIME_ZONE)
if self.due is not None:
due_date = self.due
if self.graceperiod is not None:
due_date = due_date + self.graceperiod
return now > due_date
return False
14 changes: 8 additions & 6 deletions freetextresponse/templates/freetextresponse_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ <h2 class="problem-header">{{ display_name }}</h2>
</div>
<div class="capa_alert submission-received">{{ submitted_message }}</div>
<div class="action">
<button class="check Submit {{ nodisplay_class }}" data-checking="{% trans "Checking..." %}" data-value={% trans "Submit" %}>
{% trans "Submit" %}
</button>
<button class="save {{ nodisplay_class }}" data-checking="{% trans "Checking..." %}" data-value={% trans "Save" %}>
{% trans "Save" %}
</button>
{% if not is_past_due %}
<button class="check Submit {{ nodisplay_class }}" data-checking="{% trans "Checking..." %}" data-value={% trans "Submit" %}>
{% trans "Submit" %}
</button>
<button class="save {{ nodisplay_class }}" data-checking="{% trans "Checking..." %}" data-value={% trans "Save" %}>
{% trans "Save" %}
</button>
{% endif %}
<div class="used-attempts-feedback" aria-live="polite">{{ used_attempts_feedback }}</div>
</div>
<div class="capa_alert user_alert">{{ user_alert }}</div>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "xblock-free-text-response",
"title": "FreeTextResponse XBlock",
"description": "Enables instructors to create questions with free-text responses.",
"version": "0.1.7",
"version": "0.1.8",
"homepage": "https://github.com/Stanford-Online/xblock-free-text-response",
"author": {
"name": "Azim Pradhan",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def run_tests(self):

setup(
name="xblock-free-text-response",
version="0.1.7",
version="0.1.8",
description="Enables instructors to create questions with free-text responses.",
license='AGPL-3.0',
packages=[
Expand Down

0 comments on commit 5e21deb

Please sign in to comment.