-
-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support translatable words within calculated properties in case tiles #34809
Changes from all commits
44fdd0b
4385373
7a9e914
c43aec7
267b662
c1697fb
5151dbf
4ae1b08
54d16b6
3a121dc
64d0085
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
from corehq.apps.app_manager import id_strings | ||
from corehq.apps.app_manager.exceptions import SuiteError | ||
from corehq.apps.app_manager.suite_xml.xml_models import ( | ||
Detail, XPathVariable, TileGroup, Style, EndpointAction | ||
Detail, DetailVariable, XPathVariable, TileGroup, Style, EndpointAction | ||
) | ||
|
||
TILE_DIR = Path(__file__).parent.parent / "case_tile_templates" | ||
|
@@ -113,6 +113,7 @@ def build_case_tile_detail(self, detail, start, end): | |
for template_field in case_tile_template_config(self.detail.case_tile_template).fields: | ||
column = self._get_matched_detail_column(template_field) | ||
context[template_field] = self._get_column_context(column) | ||
context['custom_variables'] = self._get_custom_variables(self.detail.custom_variables_dict) | ||
|
||
# Populate the template | ||
detail_as_string = self._case_tile_template_string.format(**context) | ||
|
@@ -181,14 +182,14 @@ def _get_column_context(self, column): | |
"prefix": escape( | ||
column.header.get(default_lang, "") | ||
), | ||
"format": column.format | ||
"format": column.format, | ||
"variables": '', | ||
"endpoint_action": '', | ||
} | ||
|
||
context['variables'] = '' | ||
if column.format in ["enum", "conditional-enum", "enum-image", "clickable-icon"]: | ||
if column.format in ["enum", "conditional-enum", "enum-image", "clickable-icon", "translatable-enum"]: | ||
context["variables"] = self._get_enum_variables(column) | ||
|
||
context['endpoint_action'] = '' | ||
if column.endpoint_action_id: | ||
context["endpoint_action"] = self._get_endpoint_action(column.endpoint_action_id) | ||
return context | ||
|
@@ -200,6 +201,10 @@ def _get_xpath_function(self, column): | |
else: | ||
xpath_function = self._escape_xpath_function(get_column_generator( | ||
self.app, self.module, self.detail, column).xpath_function) | ||
if column.format == "translatable-enum": | ||
for enum in column.enum: | ||
if enum.key in xpath_function and 'k' + enum.key not in xpath_function: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain the 'k'? I am confused. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when adding the enum keys to the app_strings file, it always uses key_as_variable which prepends a Looking at it again... I definitely could've just made it so it doesn't prepend |
||
xpath_function = xpath_function.replace(enum.key, 'k' + enum.key) | ||
return xpath_function | ||
|
||
@staticmethod | ||
|
@@ -274,3 +279,15 @@ def _compare_fields_by_order(initial_field, incoming_field): | |
elif initial_field.sort_node.order is None: | ||
return incoming_field | ||
return min(initial_field, incoming_field, key=lambda field: field.sort_node.order) | ||
|
||
@staticmethod | ||
def _get_custom_variables(custom_var_dict): | ||
variables = [] | ||
for var_name, var_function in custom_var_dict.items(): | ||
variables.append( | ||
DetailVariable( | ||
name=var_name, | ||
function=var_function | ||
).serialize() | ||
) | ||
return ''.join([bytes(variable).decode('utf-8') for variable in variables]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,6 +117,9 @@ | |
<locale id="cchq.case"/> | ||
</text> | ||
</title> | ||
<variables> | ||
|
||
</variables> | ||
<action> | ||
<display> | ||
<text> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,9 @@ | |
<locale id="cchq.case"/> | ||
</text> | ||
</title> | ||
<variables> | ||
|
||
</variables> | ||
<action> | ||
<display> | ||
<text> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was
endpoint_action
just missing?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, both
variables
andendpoint_action
were set as blank strings later down the function so I just grouped them into the initial dictionary creation