in bedrock/contentful/management/commands/update_contentful.py [0:0]
def _check_localisation_complete(self) -> None:
"""In the context of Contentful-sourced data, we consider localisation
to be complete for a specific locale if ALL of the required aspects,
as defined in the config are present. We do NOT check whether
the content makes sense or contains as much content as other locales,
just that they exist in a 'truthy' way.
"""
self.log("\n====================================\nChecking localisation completeness")
seen_count = 0
viable_for_localisation_count = 0
localisation_not_configured_count = 0
localisation_complete_count = 0
for contentful_entry in ContentfulEntry.objects.all():
completeness_spec = LOCALISATION_COMPLETENESS_CHECK_CONFIG.get(contentful_entry.content_type)
seen_count += 1
if completeness_spec:
viable_for_localisation_count += 1
entry_localised_fields_found = set()
data = contentful_entry.data
collected_values = []
for step in completeness_spec:
_value_for_step = self._get_value_from_data(data, step)
if _value_for_step:
entry_localised_fields_found.add(step)
collected_values.append(_value_for_step)
contentful_entry.localisation_complete = all(collected_values)
contentful_entry.save()
if contentful_entry.localisation_complete:
localisation_complete_count += 1
else:
localisation_not_configured_count += 1
self.log(
f"\nChecking {contentful_entry.content_type}:{contentful_entry.locale}:{contentful_entry.contentful_id}"
f"-> Localised? {contentful_entry.localisation_complete}"
)
if completeness_spec and not contentful_entry.localisation_complete:
_missing_fields = set(completeness_spec).difference(entry_localised_fields_found)
self.log(f"These fields were missing localised content: {_missing_fields}")
self.log(
"Localisation completeness checked:"
f"\nFully localised: {localisation_complete_count} of {viable_for_localisation_count} candidates."
f"\nNot configured for localisation: {localisation_not_configured_count}."
f"\nTotal entries checked: {seen_count}."
"\n====================================\n"
)