Skip to content

Commit

Permalink
Merge pull request #33 from Stanford-Online/show-peer-responses-load
Browse files Browse the repository at this point in the history
Show Peer Responses on page load if q answered
  • Loading branch information
caesar2164 authored Dec 4, 2018
2 parents a1ea7a7 + 66ecc58 commit b0690c6
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 30 deletions.
31 changes: 20 additions & 11 deletions freetextresponse/freetextresponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
This is the core logic for the Free-text Response XBlock
"""
from enum import Enum
import pkg_resources
from django.db import IntegrityError
from django.template.context import Context
from django.template.loader import get_template
Expand All @@ -27,10 +26,10 @@

@XBlock.needs("i18n")
class FreeTextResponse(
EnforceDueDates,
MissingDataFetcherMixin,
StudioEditableXBlockMixin,
XBlock,
EnforceDueDates,
MissingDataFetcherMixin,
StudioEditableXBlockMixin,
XBlock,
):
# pylint: disable=too-many-ancestors, too-many-instance-attributes
"""
Expand Down Expand Up @@ -280,6 +279,8 @@ def student_view(self, context={}):
general frame of the FreeTextResponse Question.
"""

display_other_responses = self.display_other_student_responses

self.runtime.service(self, 'i18n')
context.update(
{
Expand All @@ -293,8 +294,8 @@ def student_view(self, context={}):
'used_attempts_feedback': self._get_used_attempts_feedback(),
'visibility_class': self._get_indicator_visibility_class(),
'word_count_message': self._get_word_count_message(),
'display_other_responses': self.display_other_student_responses,
'other_responses': [],
'display_other_responses': display_other_responses,
'other_responses': self.get_other_answers(),
}
)
template = get_template('freetextresponse_view.html')
Expand Down Expand Up @@ -590,7 +591,8 @@ def submit(self, data, suffix=''):
# even if word count is invalid.
self.count_attempts += 1
self._compute_score()
if self.display_other_student_responses and data.get('can_record_response'):
display_other_responses = self.display_other_student_responses
if display_other_responses and data.get('can_record_response'):
self.store_student_response()
result = {
'status': 'success',
Expand All @@ -602,7 +604,7 @@ def submit(self, data, suffix=''):
'user_alert': self._get_user_alert(
ignore_attempts=True,
),
'other_responses': self.get_other_answers(self.get_student_id()),
'other_responses': self.get_other_answers(),
'display_other_responses': self.display_other_student_responses,
'visibility_class': self._get_indicator_visibility_class(),
}
Expand Down Expand Up @@ -652,14 +654,21 @@ def store_student_response(self):

# Want to store extra response so student can still see
# MAX_RESPONSES answers if their answer is in the pool.
self.displayable_answers = self.displayable_answers[-(MAX_RESPONSES+1):]
response_index = -(MAX_RESPONSES+1)
self.displayable_answers = self.displayable_answers[response_index:]

def get_other_answers(self, student_id):
def get_other_answers(self):
"""
Returns at most MAX_RESPONSES answers from the pool.
Does not return answers the student had submitted.
"""
student_id = self.get_student_id()
display_other_responses = self.display_other_student_responses
shouldnt_show_other_responses = not display_other_responses
student_answer_incorrect = self._determine_credit() == Credit.zero
if student_answer_incorrect or shouldnt_show_other_responses:
return []
return_list = [
response
for response in self.displayable_answers
Expand Down
3 changes: 2 additions & 1 deletion freetextresponse/mixins.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""
Mixins for the Free Text Response XBlock
"""
# pylint: disable=too-few-public-methods
import datetime


class EnforceDueDates(object): # pylint: disable=too-few-public-methods
class EnforceDueDates(object):
"""
xBlock Mixin to allow xblocks to check the due date
(taking the graceperiod into account) of the
Expand Down
4 changes: 3 additions & 1 deletion freetextresponse/public/view.css
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,14 @@
}

.freetextresponse .responses-box {
display: none;
margin-top: 10px;
padding: 10px;
background: #fbfbfb;
border: 1px solid #ddd;
}
.freetextresponse .responses-box.hidden {
display: none;
}

.freetextresponse .responses-title {
margin-left: 15px;
Expand Down
22 changes: 14 additions & 8 deletions freetextresponse/public/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,7 @@ function FreeTextResponseView(runtime, element) {
userAlertMessage.text(response.user_alert);
buttonSave.addClass(response.nodisplay_class);
setClassForTextAreaParent(response.indicator_class);
if (!response.user_alert && response.display_other_responses) {
var responseHTML = get_student_responses_html(response.other_responses);
if (responseHTML) {
responseList.html(responseHTML);
}
$element.find('.responses-box').show();
}
displayResponsesIfAnswered(response);

$xblocksContainer.data(cachedAnswerId, $element.find('.student_answer').val());
$xblocksContainer.data(problemProgressId, response.problem_progress);
Expand All @@ -91,17 +85,29 @@ function FreeTextResponseView(runtime, element) {
return false;
});

function get_student_responses_html(responses) {
function getStudentResponsesHtml(responses) {
/*
Convert list of responses to a html string to add to the page
*/
var html = '';
var noResponsesText = responseList.data('noresponse');
responses.forEach(function(item) {
html += '<li class="other-student-responses">' + item.answer + '</li>';
});
html = html || '<li class="no-response">' + noResponsesText + '</li>';
return html;
}

function displayResponsesIfAnswered(response) {
if (!response.display_other_responses) {
$element.find('.responses-box').addClass('hidden');
return;
}
var responseHTML = getStudentResponsesHtml(response.other_responses);
responseList.html(responseHTML);
$element.find('.responses-box').removeClass('hidden');
}

buttonSave.on('click', function () {
buttonSave.text(buttonSave[0].dataset.checking);
runtime.notify('save', {
Expand Down
21 changes: 12 additions & 9 deletions freetextresponse/templates/freetextresponse_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ <h2 class="problem-header">{{ display_name }}</h2>
</div>
{% if display_other_responses %}
<input class="messageCheckbox" type="checkbox" checked>
<span>Allow my response to possibly be visible by other learners after
submitting their response</span>
<span>{% trans "Allow my response to possibly be visible by other learners after submitting their response" %}</span>
<br>
{% endif %}
<div class="capa_alert submission-received">{{ submitted_message }}</div>
Expand All @@ -30,15 +29,19 @@ <h2 class="problem-header">{{ display_name }}</h2>
</div>
<div class="capa_alert user_alert">{{ user_alert }}</div>
{% if display_other_responses %}
<div class="responses-box">
<div class="responses-box {% if not student_answer %}hidden{% endif %}">
<button class="hide-button">
<span class="hide">Hide</span>
<span class="show">Show</span>
<span class="sr">peer responses</span>
<span class="hide">{% trans "Hide" %}</span>
<span class="show">{% trans "Show" %}</span>
<span class="sr">{% trans "peer responses" %}</span>
</button>
<p class="responses-title">Submissions by others</p>
<ul class="response-list">
<li class="no-response">No responses to show at this time</li>
<p class="responses-title">{% trans "Submissions by others" %}</p>
<ul class="response-list" data-noresponse={% trans "No responses to show at this time" %}>
{% for response in other_responses %}
<li class="other-student-responses">{{ response.answer }}</li>
{% empty %}
<li class="no-response">{% trans "No responses to show at this time" %}</li>
{% endfor %}
</ul>
</div>
{% endif %}
Expand Down

0 comments on commit b0690c6

Please sign in to comment.