Skip to content

Commit

Permalink
refactor: Move warnings to remarks column
Browse files Browse the repository at this point in the history
  • Loading branch information
drikusroor committed Aug 21, 2024
1 parent c50f5b0 commit e64223c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
26 changes: 16 additions & 10 deletions backend/experiment/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ class ExperimentAdmin(InlineActionsModelAdminMixin, NestedModelAdmin):
"dashboard",
"phases",
"active",
"status",
)
fields = [
"slug",
Expand Down Expand Up @@ -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
Expand All @@ -400,15 +409,12 @@ def remarks(self, obj):
return format_html(
"\n".join(
[
f'<span class="badge badge-{remark["level"]} whitespace-nowrap text-xs mt-1" title="{remark.get("title") if remark.get("title") else remark["message"]}">{remark["message"]}</span>'
f'<span class="badge badge-{remark["level"]} whitespace-nowrap text-xs mt-1" title="{remark.get("title") if remark.get("title") else remark["message"]}">{remark["message"]}</span><br>'
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)
Expand Down
15 changes: 4 additions & 11 deletions backend/experiment/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,16 @@ 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)
for block, missing_languages in missing_content_blocks:
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(
'<span class="success-sign"><img src="/static/admin/img/icon-yes.svg" alt="No problems"></span>'
)
warnings_text = "\n".join(warnings)

warnings_html = format_html(
'<span class="warning-sign" data-toggle="tooltip" title="{}"> <img src="/static/admin/img/icon-alert.svg" alt="Warning"> </span>'.format(
"\n".join(warnings)
)
)
print(warnings_text)

return warnings_html
return warnings_text

0 comments on commit e64223c

Please sign in to comment.