diff --git a/lms/djangoapps/open_ended_grading/controller_query_service.py b/common/lib/xmodule/xmodule/open_ended_grading_classes/controller_query_service.py similarity index 81% rename from lms/djangoapps/open_ended_grading/controller_query_service.py rename to common/lib/xmodule/xmodule/open_ended_grading_classes/controller_query_service.py index 1b124fc116..1dd5c57ad4 100644 --- a/lms/djangoapps/open_ended_grading/controller_query_service.py +++ b/common/lib/xmodule/xmodule/open_ended_grading_classes/controller_query_service.py @@ -1,8 +1,5 @@ import logging -from xmodule.open_ended_grading_classes.grading_service_module import GradingService - -from xmodule.x_module import ModuleSystem -from mitxmako.shortcuts import render_to_string +from grading_service_module import GradingService log = logging.getLogger(__name__) @@ -11,8 +8,8 @@ class ControllerQueryService(GradingService): """ Interface to staff grading backend. """ - def __init__(self, config): - config['system'] = ModuleSystem(None, None, None, render_to_string, None) + def __init__(self, config, system): + config['system'] = system super(ControllerQueryService, self).__init__(config) self.url = config['url'] + config['grading_controller'] self.login_url = self.url + '/login/' @@ -77,3 +74,16 @@ class ControllerQueryService(GradingService): response = self.post(self.take_action_on_flags_url, params) return response + +def convert_seconds_to_human_readable(seconds): + if seconds < 60: + human_string = "{0} seconds".format(seconds) + elif seconds < 60 * 60: + human_string = "{0} minutes".format(round(seconds/60,1)) + elif seconds < (24*60*60): + human_string = "{0} hours".format(round(seconds/(60*60),1)) + else: + human_string = "{0} days".format(round(seconds/(60*60*24),1)) + + eta_string = "{0}".format(human_string) + return eta_string diff --git a/common/lib/xmodule/xmodule/open_ended_grading_classes/open_ended_module.py b/common/lib/xmodule/xmodule/open_ended_grading_classes/open_ended_module.py index 0b546482f4..974d23965f 100644 --- a/common/lib/xmodule/xmodule/open_ended_grading_classes/open_ended_module.py +++ b/common/lib/xmodule/xmodule/open_ended_grading_classes/open_ended_module.py @@ -663,17 +663,21 @@ class OpenEndedModule(openendedchild.OpenEndedChild): Output: Rendered HTML """ #set context variables and render template + eta_string = None if self.state != self.INITIAL: latest = self.latest_answer() previous_answer = latest if latest is not None else self.initial_display post_assessment = self.latest_post_assessment(system) score = self.latest_score() correct = 'correct' if self.is_submission_correct(score) else 'incorrect' + if self.state == self.ASSESSING: + eta_string = self.get_eta() else: post_assessment = "" correct = "" previous_answer = self.initial_display + context = { 'prompt': self.prompt, 'previous_answer': previous_answer, @@ -686,6 +690,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild): 'child_type': 'openended', 'correct': correct, 'accept_file_upload': self.accept_file_upload, + 'eta_message' : eta_string, } html = system.render_template('open_ended.html', context) return html diff --git a/common/lib/xmodule/xmodule/open_ended_grading_classes/openendedchild.py b/common/lib/xmodule/xmodule/open_ended_grading_classes/openendedchild.py index bac254720b..50f9534717 100644 --- a/common/lib/xmodule/xmodule/open_ended_grading_classes/openendedchild.py +++ b/common/lib/xmodule/xmodule/open_ended_grading_classes/openendedchild.py @@ -23,6 +23,7 @@ from xmodule.xml_module import XmlDescriptor from xmodule.modulestore import Location from capa.util import * from peer_grading_service import PeerGradingService +import controller_query_service from datetime import datetime @@ -106,8 +107,10 @@ class OpenEndedChild(object): # completion (doesn't matter if you self-assessed correct/incorrect). self._max_score = static_data['max_score'] self.peer_gs = PeerGradingService(system.open_ended_grading_interface, system) + self.controller_qs = controller_query_service.ControllerQueryService(system.open_ended_grading_interface,system) self.system = system + self.location_string = location try: self.location_string = self.location_string.url() @@ -438,14 +441,14 @@ class OpenEndedChild(object): error_string = ("You need to peer grade {0} more in order to make another submission. " "You have graded {1}, and {2} are required. You have made {3} successful peer grading submissions.") try: - response = self.peer_gs.get_data_for_location(location, student_id) + response = self.peer_gs.get_data_for_location(self.location_string, student_id) count_graded = response['count_graded'] count_required = response['count_required'] student_sub_count = response['student_sub_count'] success = True except: #This is a dev_facing_error - log.error("Could not contact external open ended graders for location {0} and student {1}".format(location,student_id)) + log.error("Could not contact external open ended graders for location {0} and student {1}".format(self.location_string,student_id)) #This is a student_facing_error error_message = "Could not contact the graders. Please notify course staff." return success, allowed_to_submit, error_message @@ -457,3 +460,24 @@ class OpenEndedChild(object): error_message = error_string.format(count_required-count_graded, count_graded, count_required, student_sub_count) return success, allowed_to_submit, error_message + def get_eta(self): + response = self.controller_qs.check_for_eta(self.location_string) + try: + response = json.loads(response) + except: + pass + + success = response['success'] + if isinstance(success, basestring): + success = (success.lower()=="true") + + if success: + eta = controller_query_service.convert_seconds_to_human_readable(response['eta']) + eta_string = "Please check back for your response in at most {0}.".format(eta) + else: + eta_string = "" + + return eta_string + + + diff --git a/lms/djangoapps/open_ended_grading/open_ended_notifications.py b/lms/djangoapps/open_ended_grading/open_ended_notifications.py index c4054895d3..b4ca20079f 100644 --- a/lms/djangoapps/open_ended_grading/open_ended_notifications.py +++ b/lms/djangoapps/open_ended_grading/open_ended_notifications.py @@ -1,7 +1,7 @@ from django.conf import settings from xmodule.open_ended_grading_classes import peer_grading_service from staff_grading_service import StaffGradingService -from open_ended_grading.controller_query_service import ControllerQueryService +from xmodule.open_ended_grading_classes.controller_query_service import ControllerQueryService import json from student.models import unique_id_for_user from courseware.models import StudentModule @@ -93,7 +93,8 @@ def peer_grading_notifications(course, user): def combined_notifications(course, user): - controller_qs = ControllerQueryService(settings.OPEN_ENDED_GRADING_INTERFACE) + system = ModuleSystem(None, None, None, render_to_string, None) + controller_qs = ControllerQueryService(settings.OPEN_ENDED_GRADING_INTERFACE, system) student_id = unique_id_for_user(user) user_is_staff = has_access(user, course, 'staff') course_id = course.id diff --git a/lms/djangoapps/open_ended_grading/views.py b/lms/djangoapps/open_ended_grading/views.py index 77c1cda6bc..76919d4103 100644 --- a/lms/djangoapps/open_ended_grading/views.py +++ b/lms/djangoapps/open_ended_grading/views.py @@ -11,7 +11,8 @@ from django.core.urlresolvers import reverse from student.models import unique_id_for_user from courseware.courses import get_course_with_access -from controller_query_service import ControllerQueryService +from xmodule.x_module import ModuleSystem +from xmodule.open_ended_grading_classes.controller_query_service import ControllerQueryService, convert_seconds_to_human_readable from xmodule.open_ended_grading_classes.grading_service_module import GradingServiceError import json from student.models import unique_id_for_user @@ -22,12 +23,14 @@ from xmodule.modulestore.django import modulestore from xmodule.modulestore import search from django.http import HttpResponse, Http404, HttpResponseRedirect +from mitxmako.shortcuts import render_to_string log = logging.getLogger(__name__) template_imports = {'urllib': urllib} -controller_qs = ControllerQueryService(settings.OPEN_ENDED_GRADING_INTERFACE) +system = ModuleSystem(None, None, None, render_to_string, None) +controller_qs = ControllerQueryService(settings.OPEN_ENDED_GRADING_INTERFACE, system) """ Reverses the URL from the name and the course id, and then adds a trailing slash if @@ -150,6 +153,18 @@ def student_problem_list(request, course_id): problem_url_parts = search.path_to_location(modulestore(), course.id, problem_list[i]['location']) problem_url = generate_problem_url(problem_url_parts, base_course_url) problem_list[i].update({'actual_url': problem_url}) + eta_available = problem_list[i]['eta_available'] + if isinstance(eta_available, basestring): + eta_available = (eta_available.lower() == "true") + + eta_string = "N/A" + if eta_available: + try: + eta_string = convert_seconds_to_human_readable(int(problem_list[i]['eta'])) + except: + #This is a student_facing_error + eta_string = "Error getting ETA." + problem_list[i].update({'eta_string' : eta_string}) except GradingServiceError: #This is a student_facing_error diff --git a/lms/templates/open_ended.html b/lms/templates/open_ended.html index 64defedda4..9fb136cee6 100644 --- a/lms/templates/open_ended.html +++ b/lms/templates/open_ended.html @@ -15,7 +15,12 @@ % elif state in ['done', 'post_assessment'] and correct == 'incorrect':

Incorrect.

% elif state == 'assessing': - Submitted for grading. + Submitted for grading. + % if eta_message is not None: + ${eta_message} + % endif + + % endif % if hidden: diff --git a/lms/templates/open_ended_problems/open_ended_problems.html b/lms/templates/open_ended_problems/open_ended_problems.html index 07d379fe32..3709fb2de6 100644 --- a/lms/templates/open_ended_problems/open_ended_problems.html +++ b/lms/templates/open_ended_problems/open_ended_problems.html @@ -27,7 +27,8 @@ Problem Name Status - Type of Grading + Grader Type + ETA %for problem in problem_list: @@ -40,6 +41,9 @@ ${problem['grader_type']} + + ${problem['eta_string']} + %endfor diff --git a/lms/templates/peer_grading/peer_grading_problem.html b/lms/templates/peer_grading/peer_grading_problem.html index 853fa750e8..87559ec877 100644 --- a/lms/templates/peer_grading/peer_grading_problem.html +++ b/lms/templates/peer_grading/peer_grading_problem.html @@ -43,8 +43,8 @@

Please include some written feedback as well.

-

Flag this submission for review by course staff (use if the submission contains inappropriate content):

-

I do not know how to grade this question:

+
Flag this submission for review by course staff (use if the submission contains inappropriate content)
+
I do not know how to grade this question