Skip to content

Commit

Permalink
Merge pull request #33502 from dimagi/riese/empty_style
Browse files Browse the repository at this point in the history
Do not set style if it is not configured
  • Loading branch information
MartinRiese authored Sep 19, 2023
2 parents 3440466 + c3b5ec3 commit 9a08d95
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
16 changes: 9 additions & 7 deletions corehq/apps/app_manager/suite_xml/features/case_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
module_uses_inline_search,
)


TILE_DIR = Path(__file__).parent.parent / "case_tile_templates"


Expand All @@ -27,7 +26,7 @@ class CaseTileTemplates(models.TextChoices):
ONE_TWO_ONE_ONE = ("one_two_one_one", _("Title row, second row with two cells, third and "
"fourth rows, and map"))
ONE_3X_TWO_4X_ONE_2X = ("one_3X_two_4X_one_2X", _("Three upper rows, four rows with two cells, two lower rows "
"and map"))
"and map"))
ONE_TWO_TWO = ("one_two_two", _("Title row, second row with two cells, third row with two cells"))
ICON_TEXT_GRID = ("icon_text_grid", _("2 x 3 grid of image and text"))

Expand Down Expand Up @@ -88,11 +87,14 @@ def build_case_tile_detail(self):

for column_info in self.detail_column_infos:
# column_info is an instance of DetailColumnInfo named tuple.
style = Style(grid_x=column_info.column.grid_x, grid_y=column_info.column.grid_y,
grid_height=column_info.column.height, grid_width=column_info.column.width,
horz_align=column_info.column.horizontal_align,
vert_align=column_info.column.vertical_align,
font_size=column_info.column.font_size)
style = None
if any(field is not None for field in [column_info.column.grid_x, column_info.column.grid_y,
column_info.column.height, column_info.column.width]):
style = Style(grid_x=column_info.column.grid_x, grid_y=column_info.column.grid_y,
grid_height=column_info.column.height, grid_width=column_info.column.width,
horz_align=column_info.column.horizontal_align,
vert_align=column_info.column.vertical_align,
font_size=column_info.column.font_size)
fields = get_column_generator(
self.app, self.module, self.detail,
detail_type=self.detail_type,
Expand Down
36 changes: 36 additions & 0 deletions corehq/apps/app_manager/tests/test_suite_custom_case_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,39 @@ def test_custom_case_tile_address(self, *args):
app.create_suite(),
"./detail[@id='m0_case_short']/field[1]"
)

def test_custom_case_tile_empty_style(self, *args):
app = Application.new_app('domain', 'Untitled Application')

module = app.add_module(Module.new_module('Untitled Module', None))
module.case_type = 'patient'
module.case_details.short.case_tile_template = "custom"
module.case_details.short.columns = [
DetailColumn(
header={'en': 'a'},
model='case',
field='a',
format='plain'
),
]

self.assertXmlPartialEqual(
"""
<partial>
<field>
<header>
<text>
<locale id="m0.case_short.case_a_1.header"/>
</text>
</header>
<template>
<text>
<xpath function="a"/>
</text>
</template>
</field>
</partial>
""",
app.create_suite(),
"./detail[@id='m0_case_short']/field[1]"
)

0 comments on commit 9a08d95

Please sign in to comment.