Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xblock-utils
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
xblock-utils
Commits
3dd2fce4
Commit
3dd2fce4
authored
Sep 06, 2016
by
Braden MacDonald
Committed by
GitHub
Sep 06, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #38 from open-craft/studio-edit-i18n
Fix translation of field names and help text in studio_view
parents
c79f6836
60af41a8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
3 deletions
+34
-3
requirements.txt
+1
-1
setup.py
+1
-1
tests/integration/test_studio_editable.py
+24
-0
xblockutils/studio_editable.py
+8
-1
No files found.
requirements.txt
View file @
3dd2fce4
...
@@ -3,4 +3,4 @@
...
@@ -3,4 +3,4 @@
# XBlock
# XBlock
# This is not in/from PyPi, since it moves fast
# This is not in/from PyPi, since it moves fast
-e git+https://github.com/edx/XBlock.git@
tag-master-2015-05-22#egg=XBlock
-e git+https://github.com/edx/XBlock.git@
xblock-0.4.10#egg=XBlock==0.4.10
setup.py
View file @
3dd2fce4
...
@@ -35,7 +35,7 @@ def package_data(pkg, root_list):
...
@@ -35,7 +35,7 @@ def package_data(pkg, root_list):
setup
(
setup
(
name
=
'xblock-utils'
,
name
=
'xblock-utils'
,
version
=
'1.0.
2
'
,
version
=
'1.0.
3
'
,
description
=
'Various utilities for XBlocks'
,
description
=
'Various utilities for XBlocks'
,
packages
=
[
packages
=
[
'xblockutils'
,
'xblockutils'
,
...
...
tests/integration/test_studio_editable.py
View file @
3dd2fce4
...
@@ -106,6 +106,16 @@ class TestEditableXBlock_StudioView(StudioEditableBaseTest):
...
@@ -106,6 +106,16 @@ class TestEditableXBlock_StudioView(StudioEditableBaseTest):
self
.
assert_unchanged
(
block
,
orig_values
,
explicitly_set
=
True
)
self
.
assert_unchanged
(
block
,
orig_values
,
explicitly_set
=
True
)
@XBlock.register_temp_plugin
(
EditableXBlock
,
"editable"
)
@XBlock.register_temp_plugin
(
EditableXBlock
,
"editable"
)
def
test_no_i18n
(
self
):
"""
Test that the studio_view doesn't call block.ugettext since the block hasn't indicated
@XBlock.wants("i18n") or @XBlock.needs("i18n")
"""
with
mock
.
patch
.
object
(
EditableXBlock
,
"ugettext"
)
as
mock_ugettext
:
self
.
set_up_root_block
()
mock_ugettext
.
assert_not_called
()
@XBlock.register_temp_plugin
(
EditableXBlock
,
"editable"
)
def
test_explicit_overrides
(
self
):
def
test_explicit_overrides
(
self
):
"""
"""
Test that we can override the defaults with the same value as the default, and that the
Test that we can override the defaults with the same value as the default, and that the
...
@@ -211,6 +221,7 @@ def fancy_list_values_provider_b(block):
...
@@ -211,6 +221,7 @@ def fancy_list_values_provider_b(block):
return
[{
"display_name"
:
"Robert"
,
"value"
:
"bob"
},
{
"display_name"
:
"Alexandra"
,
"value"
:
"alex"
}]
return
[{
"display_name"
:
"Robert"
,
"value"
:
"bob"
},
{
"display_name"
:
"Alexandra"
,
"value"
:
"alex"
}]
@XBlock.wants
(
"i18n"
)
class
FancyXBlock
(
StudioEditableXBlockMixin
,
XBlock
):
class
FancyXBlock
(
StudioEditableXBlockMixin
,
XBlock
):
"""
"""
A Studio-editable XBlock with lots of fields and fancy features
A Studio-editable XBlock with lots of fields and fancy features
...
@@ -304,6 +315,19 @@ class TestFancyXBlock_StudioView(StudioEditableBaseTest):
...
@@ -304,6 +315,19 @@ class TestFancyXBlock_StudioView(StudioEditableBaseTest):
return
self
.
load_root_xblock
()
return
self
.
load_root_xblock
()
@XBlock.register_temp_plugin
(
FancyXBlock
,
"fancy"
)
@XBlock.register_temp_plugin
(
FancyXBlock
,
"fancy"
)
def
test_i18n
(
self
):
"""
Test that field names and help text get translated using the XBlock runtime's ugettext
method.
"""
with
mock
.
patch
.
object
(
FancyXBlock
,
"ugettext"
,
side_effect
=
lambda
text
:
text
[::
-
1
]):
self
.
set_up_root_block
()
bool_field
=
self
.
browser
.
find_element_by_css_selector
(
'li[data-field-name=bool_normal]'
)
self
.
assertIn
(
"Normal Boolean Field"
[::
-
1
],
bool_field
.
text
)
string_with_help_field
=
self
.
browser
.
find_element_by_css_selector
(
'li[data-field-name=string_with_help]'
)
self
.
assertIn
(
"Learn more about"
[::
-
1
],
string_with_help_field
.
text
)
@XBlock.register_temp_plugin
(
FancyXBlock
,
"fancy"
)
def
test_no_changes_with_defaults
(
self
):
def
test_no_changes_with_defaults
(
self
):
"""
"""
If we load the edit form and then save right away, there should be no changes.
If we load the edit form and then save right away, there should be no changes.
...
...
xblockutils/studio_editable.py
View file @
3dd2fce4
...
@@ -13,7 +13,6 @@ StudioEditableXBlockMixin to your XBlock.
...
@@ -13,7 +13,6 @@ StudioEditableXBlockMixin to your XBlock.
import
json
import
json
import
logging
import
logging
from
django.utils.translation
import
ugettext
from
xblock.core
import
XBlock
from
xblock.core
import
XBlock
from
xblock.fields
import
Scope
,
JSONField
,
List
,
Integer
,
Float
,
Boolean
,
String
,
DateTime
from
xblock.fields
import
Scope
,
JSONField
,
List
,
Integer
,
Float
,
Boolean
,
String
,
DateTime
from
xblock.exceptions
import
JsonHandlerError
,
NoSuchViewError
from
xblock.exceptions
import
JsonHandlerError
,
NoSuchViewError
...
@@ -107,6 +106,14 @@ class StudioEditableXBlockMixin(object):
...
@@ -107,6 +106,14 @@ class StudioEditableXBlockMixin(object):
(
DateTime
,
'datepicker'
),
(
DateTime
,
'datepicker'
),
(
JSONField
,
'generic'
),
# This is last so as a last resort we display a text field w/ the JSON string
(
JSONField
,
'generic'
),
# This is last so as a last resort we display a text field w/ the JSON string
)
)
if
self
.
service_declaration
(
"i18n"
):
ugettext
=
self
.
ugettext
else
:
def
ugettext
(
text
):
""" Dummy ugettext method that doesn't do anything """
return
text
info
=
{
info
=
{
'name'
:
field_name
,
'name'
:
field_name
,
'display_name'
:
ugettext
(
field
.
display_name
)
if
field
.
display_name
else
""
,
'display_name'
:
ugettext
(
field
.
display_name
)
if
field
.
display_name
else
""
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment