Browse Source

fix(hadis): fallback status_text to hadis_status.description in sqlite export

master
Mohsen Taba 1 week ago
parent
commit
ab1d3d3b37
  1. 34
      apps/hadis/management/commands/export_hadis_sqlite.py

34
apps/hadis/management/commands/export_hadis_sqlite.py

@ -207,6 +207,31 @@ class Command(BaseCommand):
CREATE INDEX IF NOT EXISTS idx_corr_hadis ON hadith_corrections(hadis_id);
""")
def _is_empty_localized_data(self, val):
if not val:
return True
if isinstance(val, (list, tuple)):
if len(val) == 0:
return True
for item in val:
if isinstance(item, dict):
txt = item.get('text') or item.get('title') or item.get('description') or ''
if str(txt).strip():
return False
elif str(item).strip():
return False
return True
if isinstance(val, dict):
if not val:
return True
for k, v in val.items():
if str(v).strip():
return False
return True
if isinstance(val, str) and not val.strip():
return True
return False
def _export_categories(self, cursor):
cats = HadisCategory.objects.all()
rows = [
@ -343,6 +368,13 @@ class Command(BaseCommand):
'detail': getattr(exp, 'detail', '')
})
# Status description fallback: use hadis_status_text if present and non-empty, otherwise fallback to hadis_status.description
status_desc_raw = h.hadis_status_text
if self._is_empty_localized_data(status_desc_raw) and h.hadis_status:
status_desc_raw = h.hadis_status.description
status_text_val = json.dumps(status_desc_raw, ensure_ascii=False) if isinstance(status_desc_raw, (dict, list)) else (status_desc_raw or '')
hadis_rows.append((
h.id,
h.slug,
@ -358,7 +390,7 @@ class Command(BaseCommand):
json.dumps(status_title, ensure_ascii=False) if isinstance(status_title, (dict, list)) else (status_title or ''),
status_color or '',
status_code or '',
json.dumps(h.hadis_status_text, ensure_ascii=False) if isinstance(h.hadis_status_text, (dict, list)) else (h.hadis_status_text or ''),
status_text_val,
json.dumps(tags_list, ensure_ascii=False),
json.dumps(refs_list, ensure_ascii=False),
json.dumps(ref_imgs_list, ensure_ascii=False),

Loading…
Cancel
Save