From e64223c4d5af2e36c337722d54300d7f065ade13 Mon Sep 17 00:00:00 2001 From: Drikus Roor Date: Wed, 21 Aug 2024 20:09:18 +0200 Subject: [PATCH] refactor: Move warnings to remarks column --- backend/experiment/admin.py | 26 ++++++++++++++++---------- backend/experiment/utils.py | 15 ++++----------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/backend/experiment/admin.py b/backend/experiment/admin.py index 42d4b2527..8aed000e6 100644 --- a/backend/experiment/admin.py +++ b/backend/experiment/admin.py @@ -270,7 +270,6 @@ class ExperimentAdmin(InlineActionsModelAdminMixin, NestedModelAdmin): "dashboard", "phases", "active", - "status", ) fields = [ "slug", @@ -383,13 +382,23 @@ def remarks(self, obj): } ) - if not remarks_array: - remarks_array.append({"level": "success", "message": "✅ All good", "title": "No issues found."}) - supported_languages = obj.translated_content.values_list("language", flat=True).distinct() - # TODO: Check if all blocks support the same languages as the experiment - # Implement this when the blocks have been updated to support multiple languages + missing_content_block_translations = check_missing_translations(obj) + + print(missing_content_block_translations) + + if missing_content_block_translations: + remarks_array.append( + { + "level": "warning", + "message": "🌍 Missing block content", + "title": missing_content_block_translations, + } + ) + + if not remarks_array: + remarks_array.append({"level": "success", "message": "✅ All good", "title": "No issues found."}) # TODO: Check if all theme configs support the same languages as the experiment # Implement this when the theme configs have been updated to support multiple languages @@ -400,15 +409,12 @@ def remarks(self, obj): return format_html( "\n".join( [ - f'{remark["message"]}' + f'{remark["message"]}
' for remark in remarks_array ] ) ) - def status(self, obj): - return check_missing_translations(obj) - def save_model(self, request, obj, form, change): # Check for missing translations missing_content_blocks = get_missing_content_blocks(obj) diff --git a/backend/experiment/utils.py b/backend/experiment/utils.py index 57beaca2c..5efb03565 100644 --- a/backend/experiment/utils.py +++ b/backend/experiment/utils.py @@ -110,7 +110,7 @@ def get_missing_content_blocks(experiment: Experiment) -> List[Tuple[Block, List return missing_content_blocks -def check_missing_translations(experiment: Experiment): +def check_missing_translations(experiment: Experiment) -> str: warnings = [] missing_content_blocks = get_missing_content_blocks(experiment) @@ -118,15 +118,8 @@ def check_missing_translations(experiment: Experiment): missing_language_flags = [get_flag_emoji(language) for language in missing_languages] warnings.append(f"Block {block.name} does not have content in {', '.join(missing_language_flags)}") - if not warnings: - return format_html( - 'No problems' - ) + warnings_text = "\n".join(warnings) - warnings_html = format_html( - ' Warning '.format( - "\n".join(warnings) - ) - ) + print(warnings_text) - return warnings_html + return warnings_text