Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix is_past_due function #26

Merged
merged 1 commit into from
Nov 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions freetextresponse/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
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
Expand All @@ -15,19 +11,23 @@ class EnforceDueDates(object): # pylint: disable=too-few-public-methods
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
# These values are pulled from platform.
# They are defaulted to None for tests.
due = getattr(self, 'due', None)
graceperiod = getattr(self, 'graceperiod', None)
# Calculate the current DateTime so we can compare the due date to it.
# datetime.utcnow() returns timezone naive date object.
now = datetime.datetime.utcnow()
if due is not None:
# Remove timezone information from platform provided due date.
# Dates are stored as UTC timezone aware objects on platform.
due = due.replace(tzinfo=None)
if graceperiod is not None:
# Compare the datetime objects (both have to be timezone naive)
due = due + graceperiod
return now > due
return False
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.8",
"version": "0.1.9",
"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.8",
version="0.1.9",
description="Enables instructors to create questions with free-text responses.",
license='AGPL-3.0',
packages=[
Expand Down