From 91aa7b06ceb3366254f32c2826532129b9ca639d Mon Sep 17 00:00:00 2001 From: Carlos de la Guardia Date: Mon, 5 Jan 2015 00:13:01 -0600 Subject: [PATCH] MIT: CCX. Handle setting dates for blocks Add date widget for setting start and due dates for the course sections, plus simple server side validation for avoiding db corruption from bad dates Add immediate feedback for date validation errors --- lms/djangoapps/pocs/views.py | 21 +++++++++++++++++++-- lms/templates/pocs/coach_dashboard.html | 10 ++++++++++ lms/templates/pocs/schedule.html | 25 ++++++++++++++++++++++--- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/lms/djangoapps/pocs/views.py b/lms/djangoapps/pocs/views.py index 62711aeb79..5d4bd4fa32 100644 --- a/lms/djangoapps/pocs/views.py +++ b/lms/djangoapps/pocs/views.py @@ -231,6 +231,22 @@ def set_grading_policy(request, course): return redirect(url) +def validate_date(year, month, day, hour, minute): + # avoid corrupting db if bad dates come in + valid = True + if year < 0: + valid = False + if month < 1 or month > 12: + valid = False + if day < 1 or day > 31: + valid = False + if hour < 0 or hour > 23: + valid = False + if minute < 0 or minute > 59: + valid = False + return valid + + def parse_date(datestring): """ Generate a UTC datetime.datetime object from a string of the form @@ -240,8 +256,9 @@ def parse_date(datestring): date, time = datestring.split(' ') year, month, day = map(int, date.split('-')) hour, minute = map(int, time.split(':')) - return datetime.datetime( - year, month, day, hour, minute, tzinfo=pytz.UTC) + if validate_date(year, month, day, hour, minute): + return datetime.datetime( + year, month, day, hour, minute, tzinfo=pytz.UTC) return None diff --git a/lms/templates/pocs/coach_dashboard.html b/lms/templates/pocs/coach_dashboard.html index 1fb6e8f6d8..7f19666e02 100644 --- a/lms/templates/pocs/coach_dashboard.html +++ b/lms/templates/pocs/coach_dashboard.html @@ -14,6 +14,16 @@ <%static:css group='style-course'/> +<%block name="jsextra"> + + + + + <%include file="/courseware/course_navigation.html" args="active_page='poc_coach'" />
diff --git a/lms/templates/pocs/schedule.html b/lms/templates/pocs/schedule.html index 94788a7c6d..4e443a5c8a 100644 --- a/lms/templates/pocs/schedule.html +++ b/lms/templates/pocs/schedule.html @@ -70,10 +70,10 @@

-
+
- - + +
@@ -138,6 +138,15 @@