Commit 4808d543 by Xavier Antoviaque

Compile a full dump of the students answers

parent 32ca54f3
from .answer import AnswerBlock
from .dataviewer import MentoringDataViewerBlock
from .quizz import QuizzBlock, QuizzTipBlock
from .table import MentoringTableBlock, MentoringTableColumnBlock
from .mentoring import MentoringBlock
from .table import MentoringTableBlock, MentoringTableColumnBlock
......@@ -101,7 +101,7 @@ class AnswerBlock(XBlock):
if not name:
raise ValueError, 'AnswerBlock.name field need to be set to a non-null/empty value'
# TODO Use a random user id
# TODO Use anonymous_user_id
student_id = self.scope_ids.user_id
answer_data, created = Answer.objects.get_or_create(
......
# -*- coding: utf-8 -*-
# Imports ###########################################################
import logging
import json
from webob import Response
from xblock.core import XBlock
from xblock.fragment import Fragment
from .models import Answer
from .utils import load_resource, render_template
# Globals ###########################################################
log = logging.getLogger(__name__)
# Classes ###########################################################
class MentoringDataViewerBlock(XBlock):
"""
An XBlock allowing the instructor team to read/export all the student answers
"""
def student_view(self, context):
html = render_template('templates/html/dataviewer.html', {
'self': self,
})
fragment = Fragment(html)
fragment.add_javascript(load_resource('static/js/vendor/jquery.handsontable.full.js'))
fragment.add_javascript(load_resource('static/js/dataviewer.js'))
fragment.add_css(load_resource('static/css/vendor/jquery.handsontable.full.css'))
fragment.add_css(load_resource('static/css/dataviewer.css'))
fragment.initialize_js('MentoringDataViewerBlock')
return fragment
def studio_view(self, context):
return Fragment(u'Studio view body')
@XBlock.handler
def get_data(self, request, suffix=''):
response_json = json.dumps({'data': self.get_data_list()})
return Response(response_json, content_type='application/json')
def get_data_list(self):
answers = Answer.objects.all().order_by('student_id', 'name')
answers_names = Answer.objects.values_list('name', flat=True).distinct().order_by('name')
data = [['student_id'] + list(answers_names)]
row = []
cur_student_id = None
cur_col = None
for answer in answers:
if answer.student_id != cur_student_id:
if row:
data.append(row)
row = [answer.student_id]
cur_student_id = answer.student_id
cur_col = 0
while answer.name != answers_names[cur_col]:
row.append('')
cur_col += 1
row.append(answer.student_input)
cur_col += 1
if row:
data.append(row)
return data
@staticmethod
def workbench_scenarios():
"""
Sample scenarios which will be displayed in the workbench
"""
return [
("Mentoring - Page 999, Intructors data viewer",
load_resource('templates/xml/999_dataviewer.xml')),
]
......@@ -2,6 +2,7 @@ from setuptools import setup
BLOCKS = [
'mentoring = mentoring:MentoringBlock',
'mentoring-dataviewer = mentoring:MentoringDataViewerBlock',
'mentoring-table = mentoring:MentoringTableBlock',
'column = mentoring:MentoringTableColumnBlock',
'answer = mentoring:AnswerBlock',
......
.mentoring-dataviewer .mentoring-dataviewer-table {
overflow: scroll;
margin: 10px;
}
function MentoringDataViewerBlock(runtime, element) {
var handlerUrl = runtime.handlerUrl(element, 'get_data');
$.get(handlerUrl, function(result) {
$('.mentoring-dataviewer .mentoring-dataviewer-table', element).handsontable({
data: result.data,
colWidths: 300,
rowHeaders: true,
colHeaders: true,
stretchH: 'all'
});
}, 'json');
}
......@@ -39,7 +39,7 @@ function MentoringBlock(runtime, element) {
data[child.name] = callIfExists(child, 'submit');
}
}
var handlerUrl = runtime.handlerUrl(element, 'submit')
var handlerUrl = runtime.handlerUrl(element, 'submit');
$.post(handlerUrl, JSON.stringify(data)).success(handleSubmitResults);
});
......
This source diff could not be displayed because it is too large. You can view the blob instead.
<div class="mentoring-dataviewer">
<div class="mentoring-dataviewer-table"></div>
</div>
<vertical>
<html>
<h3>Answers data</h3>
</html>
<mentoring-dataviewer></mentoring-dataviewer>
</vertical>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment