Skip to content

Commit

Permalink
Fix the FTR XBlock for Hawthorn
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarIthawi committed Dec 24, 2018
1 parent c8f49f9 commit f27f026
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
20 changes: 11 additions & 9 deletions freetextresponse/freetextresponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from enum import Enum
from django.db import IntegrityError
from django.template.context import Context
from django.template.loader import get_template
from django.utils.translation import ungettext
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext
Expand All @@ -17,6 +16,7 @@
from xblock.fields import String
from xblock.fragment import Fragment
from xblock.validation import ValidationMessage
from xblockutils.resources import ResourceLoader
from xblockutils.studio_editable import StudioEditableXBlockMixin
from .mixins import EnforceDueDates, MissingDataFetcherMixin

Expand All @@ -35,6 +35,9 @@ class FreeTextResponse(
"""
Enables instructors to create questions with free-text responses.
"""

loader = ResourceLoader(__name__)

@staticmethod
def workbench_scenarios():
"""
Expand Down Expand Up @@ -240,8 +243,7 @@ def workbench_scenarios():

def build_fragment(
self,
template,
context_dict,
rendered_template,
initialize_js_func,
additional_css=[],
additional_js=[],
Expand All @@ -250,8 +252,7 @@ def build_fragment(
"""
Creates a fragment for display.
"""
context = Context(context_dict)
fragment = Fragment(template.render(context))
fragment = Fragment(rendered_template)
for item in additional_css:
url = self.runtime.local_resource_url(self, item)
fragment.add_css_url(url)
Expand All @@ -278,9 +279,7 @@ def student_view(self, context={}):
(Fragment): The HTML Fragment for this XBlock, which determines the
general frame of the FreeTextResponse Question.
"""

display_other_responses = self.display_other_student_responses

self.runtime.service(self, 'i18n')
context.update(
{
Expand All @@ -298,10 +297,13 @@ def student_view(self, context={}):
'other_responses': self.get_other_answers(),
}
)
template = get_template('freetextresponse_view.html')
template = self.loader.render_django_template(
'templates/freetextresponse_view.html',
context=Context(context),
i18n_service=self.runtime.service(self, 'i18n'),
)
fragment = self.build_fragment(
template,
context,
initialize_js_func='FreeTextResponseView',
additional_css=[
'public/view.css',
Expand Down
18 changes: 14 additions & 4 deletions freetextresponse/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@

from xblock.field_data import DictFieldData
from xblock.validation import ValidationMessage
from xblockutils.resources import ResourceLoader

from django.db import IntegrityError
from django.template.loader import get_template
from django.template.context import Context

from .freetextresponse import Credit
from .freetextresponse import FreeTextResponse
Expand Down Expand Up @@ -56,7 +57,13 @@ def make_an_xblock(cls, **kw):
Helper method that creates a Free-text Response XBlock
"""
course_id = SlashSeparatedCourseKey('foo', 'bar', 'baz')
runtime = Mock(course_id=course_id)
runtime = Mock(
course_id=course_id,
service=Mock(
# Is there a cleaner mock to the `i18n` service?
return_value=Mock(_catalog={}),
),
)
scope_ids = Mock()
field_data = DictFieldData(kw)
xblock = FreeTextResponse(runtime, field_data, scope_ids)
Expand Down Expand Up @@ -182,10 +189,13 @@ def test_build_fragment_prompt_html(self):
context = {
'prompt': studio_settings_prompt,
}
template = get_template('freetextresponse_view.html')
loader = ResourceLoader('freetextresponse')
template = loader.render_django_template(
'templates/freetextresponse_view.html',
context=Context(context),
)
fragment = self.xblock.build_fragment(
template,
context,
initialize_js_func='FreeTextResponseView',
additional_css=[],
additional_js=[],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "xblock-free-text-response",
"title": "FreeTextResponse XBlock",
"description": "Enables instructors to create questions with free-text responses.",
"version": "0.3.1",
"version": "0.4.0",
"homepage": "https://github.com/Stanford-Online/xblock-free-text-response",
"author": {
"name": "Azim Pradhan",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ddt
django<1.9,>=1.8
git+https://github.com/edx/XBlock.git#egg=XBlock
git+https://github.com/edx/xblock-utils.git@v1.0.0#egg=xblock-utils==v1.0.0
git+https://github.com/edx/xblock-utils.git@v1.1.1#egg=xblock-utils==v1.1.1
git+https://github.com/edx/opaque-keys.git@27dc382ea587483b1e3889a3d19cbd90b9023a06#egg=opaque-keys
-e .
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def run_tests(self):

setup(
name="xblock-free-text-response",
version="0.3.1",
version="0.4.0",
description="Enables instructors to create questions with free-text responses.",
license='AGPL-3.0',
packages=[
Expand Down Expand Up @@ -57,6 +57,7 @@ def run_tests(self):
package_data={
"freetextresponse": [
'public/*',
'templates/*',
],
},
classifiers=[
Expand Down

0 comments on commit f27f026

Please sign in to comment.