Commit 182b4803 by Braden MacDonald

Cleanups

parent 9699d0a5
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# Copyright (C) 2015 OpenCraft # Copyright (c) 2014-2015 Harvard, edX & OpenCraft
# #
# This software's license gives you freedom; you can copy, convey, # This software's license gives you freedom; you can copy, convey,
# propagate, redistribute and/or modify this program under the terms of # propagate, redistribute and/or modify this program under the terms of
......
# -*- coding: utf-8 -*-
#
# Copyright (c) 2014-2015 Harvard, edX & OpenCraft
#
# This software's license gives you freedom; you can copy, convey,
# propagate, redistribute and/or modify this program under the terms of
# the GNU Affero General Public License (AGPL) as published by the Free
# Software Foundation (FSF), either version 3 of the License, or (at your
# option) any later version of the AGPL published by the FSF.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3". If not, see <http://www.gnu.org/licenses/>.
#
class StepParentMixin(object): class StepParentMixin(object):
""" """
An XBlock mixin for a parent block containing Step children An XBlock mixin for a parent block containing Step children
......
...@@ -30,7 +30,6 @@ from xblock.fields import Scope, String ...@@ -30,7 +30,6 @@ from xblock.fields import Scope, String
from xblock.fragment import Fragment from xblock.fragment import Fragment
from xblockutils.resources import ResourceLoader from xblockutils.resources import ResourceLoader
loader = ResourceLoader(__name__)
# Globals ########################################################### # Globals ###########################################################
......
...@@ -44,11 +44,10 @@ def list2csv(row): ...@@ -44,11 +44,10 @@ def list2csv(row):
""" """
Convert a list to a CSV string (single row) Convert a list to a CSV string (single row)
""" """
f = StringIO() with StringIO() as f:
writer = unicodecsv.writer(f, encoding='utf-8') writer = unicodecsv.writer(f, encoding='utf-8')
writer.writerow(row) writer.writerow(row)
f.seek(0) return f.getvalue()
return f.read()
# Classes ########################################################### # Classes ###########################################################
......
...@@ -34,9 +34,7 @@ from xblock.core import XBlock ...@@ -34,9 +34,7 @@ from xblock.core import XBlock
from xblock.fields import Boolean, Scope, String, Integer, Float, List from xblock.fields import Boolean, Scope, String, Integer, Float, List
from xblock.fragment import Fragment from xblock.fragment import Fragment
from components.title import TitleBlock from components import TitleBlock, SharedHeaderBlock, MentoringMessageBlock
from components.header import SharedHeaderBlock
from components.message import MentoringMessageBlock
from components.step import StepParentMixin, StepMixin from components.step import StepParentMixin, StepMixin
from xblockutils.resources import ResourceLoader from xblockutils.resources import ResourceLoader
...@@ -162,7 +160,7 @@ class MentoringBlock(XBlock, StepParentMixin): ...@@ -162,7 +160,7 @@ class MentoringBlock(XBlock, StepParentMixin):
@property @property
def score(self): def score(self):
"""Compute the student score taking into account the weight of each step.""" """Compute the student score taking into account the weight of each step."""
weights = [float(self.runtime.get_block(step_id).weight) for step_id in self.steps] weights = (float(self.runtime.get_block(step_id).weight) for step_id in self.steps)
total_child_weight = sum(weights) total_child_weight = sum(weights)
if total_child_weight == 0: if total_child_weight == 0:
return (0, 0, 0, 0) return (0, 0, 0, 0)
...@@ -177,22 +175,21 @@ class MentoringBlock(XBlock, StepParentMixin): ...@@ -177,22 +175,21 @@ class MentoringBlock(XBlock, StepParentMixin):
# Migrate stored data if necessary # Migrate stored data if necessary
self.migrate_fields() self.migrate_fields()
title = ""
header = ""
fragment = Fragment() fragment = Fragment()
title = u""
header = u""
child_content = u"" child_content = u""
for child_id in self.children: for child_id in self.children:
child = self.runtime.get_block(child_id) child = self.runtime.get_block(child_id)
if isinstance(child, TitleBlock): if isinstance(child, TitleBlock):
title = child.content title = child.content
continue
elif isinstance(child, SharedHeaderBlock): elif isinstance(child, SharedHeaderBlock):
header = child.render('mentoring_view', context).content header = child.render('mentoring_view', context).content
continue
elif isinstance(child, MentoringMessageBlock): elif isinstance(child, MentoringMessageBlock):
# TODO pass # TODO
continue else:
child_fragment = child.render('mentoring_view', context) child_fragment = child.render('mentoring_view', context)
fragment.add_frag_resources(child_fragment) fragment.add_frag_resources(child_fragment)
child_content += child_fragment.content child_content += child_fragment.content
...@@ -205,17 +202,9 @@ class MentoringBlock(XBlock, StepParentMixin): ...@@ -205,17 +202,9 @@ class MentoringBlock(XBlock, StepParentMixin):
'missing_dependency_url': self.has_missing_dependency and self.next_step_url, 'missing_dependency_url': self.has_missing_dependency and self.next_step_url,
})) }))
fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/mentoring.css')) fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/mentoring.css'))
fragment.add_javascript_url( fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/vendor/underscore-min.js'))
self.runtime.local_resource_url(self, 'public/js/vendor/underscore-min.js')) js_file = 'public/js/mentoring_{}_view.js'.format('assessment' if self.is_assessment else 'standard')
if self.is_assessment: fragment.add_javascript_url(self.runtime.local_resource_url(self, js_file))
fragment.add_javascript_url(
self.runtime.local_resource_url(self, 'public/js/mentoring_assessment_view.js')
)
else:
fragment.add_javascript_url(
self.runtime.local_resource_url(self, 'public/js/mentoring_standard_view.js')
)
fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/mentoring.js')) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/mentoring.js'))
fragment.add_resource(loader.load_unicode('templates/html/mentoring_attempts.html'), "text/html") fragment.add_resource(loader.load_unicode('templates/html/mentoring_attempts.html'), "text/html")
fragment.add_resource(loader.load_unicode('templates/html/mentoring_grade.html'), "text/html") fragment.add_resource(loader.load_unicode('templates/html/mentoring_grade.html'), "text/html")
......
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