Skip to content

Commit

Permalink
chore: consume self assessment api in mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
muselesscreator committed Aug 14, 2023
1 parent 9891485 commit dd599e9
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 48 deletions.
26 changes: 21 additions & 5 deletions openassessment/xblock/api/assessments/self_assessment.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@ def __init__(self, block):
self._workflow = WorkflowAPI(block);

@property
def problem_closed(self):
return self._is_closed.problem_closed
def is_self_complete(self):
return self._workflow.is_self_complete

@property
def closed_reason(self):
return self._is_closed.reason
def is_cancelled(self):
return self._workflow.is_cancelled

@property
def is_complete(self):
return self._workflow.is_self or self._is_closed.problem_closed

@property
def problem_closed(self):
return self._is_closed.problem_closed

@property
def due_date(self):
Expand All @@ -32,7 +40,15 @@ def start_date(self):

@property
def is_due(self):
return self.is_closed.due_date < DISTANT_FUTURE
return self._is_closed.is_due

@property
def is_past_due(self):
return self._is_closed.is_past_due

@property
def is_not_available_yet(self):
return self._is_closed.is_not_available_yet

@property
def assessment(self):
Expand Down
42 changes: 14 additions & 28 deletions openassessment/xblock/self_assessment_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ def self_path_and_context(self):
SelfAssessmentRequestError: Error occurred while checking if we had a self-assessment.
"""
# Import is placed here to avoid model import at project startup.
from submissions import api as submission_api
from .api.assessments.self_assessment import SelfAssessmentAPI
step_data = SelfAssessmentAPI(self)

path = 'openassessmentblock/self/oa_self_unavailable.html'
problem_closed, reason, start_date, due_date = self.is_closed(step="self-assessment")
user_preferences = get_user_preferences(self.runtime.service(self, 'user'))

context = {
Expand All @@ -74,36 +74,29 @@ def self_path_and_context(self):
# We display the due date whether the problem is open or closed.
# If no date is set, it defaults to the distant future, in which
# case we don't display the date.
if due_date < DISTANT_FUTURE:
context['self_due'] = due_date
if step_data.is_due:
context['self_due'] = step_data.due_date

# If we haven't submitted yet, `workflow` will be an empty dict,
# and `workflow_status` will be None.
workflow = self.get_workflow_info()
workflow_status = workflow.get('status')
self_complete = workflow.get('status_details', {}).get('self', {}).get('complete', False)
if workflow_status == 'cancelled':
if step_data.is_cancelled:
path = 'openassessmentblock/self/oa_self_cancelled.html'
# Sets the XBlock boolean to signal to Message that it WAS able to grab a submission
self.no_peers = True

elif self_complete:
elif step_data.is_self_complete:
path = 'openassessmentblock/self/oa_self_complete.html'
elif workflow_status == 'self' or problem_closed:
assessment = self_api.get_assessment(workflow.get("submission_uuid"))

if assessment is not None:
elif step_data.is_complete
if step_data.assessment is not None:
path = 'openassessmentblock/self/oa_self_complete.html'
elif problem_closed:
if reason == 'start':
elif step_data.problem_closed:
if step_data.is_not_available_yet:
context["self_start"] = start_date
path = 'openassessmentblock/self/oa_self_unavailable.html'
elif reason == 'due':
elif step_data.is_past_due:
path = 'openassessmentblock/self/oa_self_closed.html'
else:
submission = submission_api.get_submission(self.submission_uuid)
context["rubric_criteria"] = self.rubric_criteria_with_labels
context["self_submission"] = create_submission_dict(submission, self.prompts)
context["self_submission"] = step_data.submission_dict
if self.rubric_feedback_prompt is not None:
context["rubric_feedback_prompt"] = self.rubric_feedback_prompt

Expand All @@ -112,7 +105,7 @@ def self_path_and_context(self):

# Determine if file upload is supported for this XBlock and what kind of files can be uploaded.
context["file_upload_type"] = self.file_upload_type
context['self_file_urls'] = self.get_download_urls_from_submission(submission)
context['self_file_urls'] = step_data.file_urls

path = 'openassessmentblock/self/oa_self_assessment.html'
else:
Expand Down Expand Up @@ -143,14 +136,7 @@ def self_assess(self, data, suffix=''): # pylint: disable=unused-argument
}

try:
assessment = self_api.create_assessment(
self.submission_uuid,
self.get_student_item_dict()['student_id'],
data['options_selected'],
clean_criterion_feedback(self.rubric_criteria, data['criterion_feedback']),
data['overall_feedback'],
create_rubric_dict(self.prompts, self.rubric_criteria_with_labels)
)
assessment = SelfAssessmentApi(self).create_assessment(data)
self.publish_assessment_event("openassessmentblock.self_assess", assessment)

# After we've created the self-assessment, we need to update the workflow.
Expand Down
30 changes: 15 additions & 15 deletions openassessment/xblock/student_training_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def training_path_and_context(self):
`context` is a dict.
"""
training_api = StudentTrainingAPI(self)
step_data = StudentTrainingAPI(self)

# Retrieve the status of the workflow.
# If no submissions have been created yet, the status will be None.
Expand All @@ -84,50 +84,50 @@ def training_path_and_context(self):
context['user_timezone'] = user_preferences['user_timezone']
context['user_language'] = user_preferences['user_language']

if not training_api.has_workflow:
if not step_data.has_workflow:
return template, context

# If the student has completed the training step, then show that the step is complete.
# We put this condition first so that if a student has completed the step, it *always*
# shows as complete.
# We're assuming here that the training step always precedes the other assessment steps
# (peer/self) -- we may need to make this more flexible later.
if training_api.is_cancelled:
if step_data.is_cancelled:
template = 'openassessmentblock/student_training/student_training_cancelled.html'
elif training_api.is_complete:
elif step_data.is_complete:
template = 'openassessmentblock/student_training/student_training_complete.html'

# If the problem is closed, then do not allow students to access the training step
elif training_api.is_not_available_yet:
context['training_start'] = training_api.start_date
elif step_data.is_not_available_yet:
context['training_start'] = step_data.start_date
template = 'openassessmentblock/student_training/student_training_unavailable.html'
elif training_api.is_past_due:
context['training_due'] = training_api.due_date
elif step_data.is_past_due:
context['training_due'] = step_data.due_date
template = 'openassessmentblock/student_training/student_training_closed.html'

# If we're on the training step, show the student an example
# We do this last so we can avoid querying the student training API if possible.
else:
if not training_api.training_module:
if not step_data.training_module:
return template, context

if training_api.is_due:
context['training_due'] = training_api.due_date
if step_data.is_due:
context['training_due'] = step_data.due_date

# Report progress in the student training workflow (completed X out of Y)
context['training_num_available'] = training_api.num_available
context['training_num_completed'] = training_api.num_completed
context['training_num_available'] = step_data.num_available
context['training_num_completed'] = step_data.num_completed
context['training_num_current'] = context['training_num_completed'] + 1

# Retrieve the example essay for the student to submit
# This will contain the essay text, the rubric, and the options the instructor selected.
example_context = training_api.example_context
example_context = step_data.example_context
if example_context.error_message:
logger.error(example_context.error_message)
template = "openassessmentblock/student_training/student_training_error.html"
else:
context['training_essay'] = example_context.essay_context
context['training_rubric'] = training_api.example_rubric
context['training_rubric'] = step_data.example_rubric
template = 'openassessmentblock/student_training/student_training.html'

return template, context
Expand Down

0 comments on commit dd599e9

Please sign in to comment.