Skip to content

Commit

Permalink
Add language column in import, remove locale in export
Browse files Browse the repository at this point in the history
  • Loading branch information
Hlamallama committed Jan 30, 2025
1 parent 58ff445 commit 6a238dc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
15 changes: 11 additions & 4 deletions home/export_content_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@
from openpyxl.workbook import Workbook
from openpyxl.worksheet.worksheet import Worksheet
from wagtail import blocks # type: ignore
from wagtail.coreutils import get_content_languages # type: ignore
from wagtail.models import Locale, Page # type: ignore
from wagtail.query import PageQuerySet # type: ignore

from .models import (ContentPage, ContentPageIndex, HomePage, MessengerBlock,
SMSBlock, USSDBlock, VariationBlock, ViberBlock,
WhatsappBlock)
from .models import (
ContentPage,
ContentPageIndex,
HomePage,
MessengerBlock,
SMSBlock,
USSDBlock,
VariationBlock,
ViberBlock,
WhatsappBlock,
)
from .xlsx_helpers import get_active_sheet

HP_CTYPE = HomePage._meta.verbose_name
Expand Down
27 changes: 17 additions & 10 deletions home/import_content_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,30 @@
from typing import Any
from uuid import uuid4

from django.core.exceptions import (ObjectDoesNotExist, # type: ignore
ValidationError)
from django.core.exceptions import ObjectDoesNotExist, ValidationError # type: ignore
from taggit.models import Tag # type: ignore
from treebeard.exceptions import NodeAlreadySaved # type: ignore
from wagtail.blocks import StructValue # type: ignore; type: ignore
from wagtail.blocks import StructValue # type: ignore
from wagtail.coreutils import get_content_languages # type: ignore
from wagtail.models import Locale, Page # type: ignore
from wagtail.models.sites import Site # type: ignore
from wagtail.rich_text import RichText # type: ignore

from home.import_helpers import (ImportException, parse_file,
validate_using_form)

from .models import (Assessment, ContentPage, ContentPageIndex,
ContentQuickReply, ContentTrigger, HomePage,
MessengerBlock, SMSBlock, USSDBlock, ViberBlock,
WhatsappBlock)
from home.import_helpers import ImportException, parse_file, validate_using_form

from .models import (
Assessment,
ContentPage,
ContentPageIndex,
ContentQuickReply,
ContentTrigger,
HomePage,
MessengerBlock,
SMSBlock,
USSDBlock,
ViberBlock,
WhatsappBlock,
)

PageId = tuple[str, Locale]

Expand Down
5 changes: 3 additions & 2 deletions home/tests/test_content_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def _filter_export_row(self, row: ExpDict, locale: str | None) -> bool:
Determine whether to keep a given export row.
"""
if locale:
if row["locale"] not in [None, "", locale]:
if row.get("locale") not in [None, "", locale]:
return False
return True

Expand Down Expand Up @@ -467,6 +467,7 @@ def export_content(self, locale: str | None = None) -> bytes:
print("-v-CONTENT-v-")
print(content.decode())
print("-^-CONTENT-^-")

return content

def export_ordered_content(self) -> bytes:
Expand Down Expand Up @@ -798,6 +799,7 @@ def test_no_translation_key_default(self, csv_impexp: ImportExport) -> None:
for row in dst:
assert len(row["translation_tag"]) == 36 # uuid with dashes
row["translation_tag"] = ""

assert dst == src

def test_no_translation_key_nondefault(self, csv_impexp: ImportExport) -> None:
Expand Down Expand Up @@ -2436,7 +2438,6 @@ def test_translations_en(self, impexp: ImportExport) -> None:

orig_en = impexp.get_page_json(locale="en")
content = impexp.export_content()

impexp.import_content(content, locale="en")
imported = impexp.get_page_json()
assert imported == orig_en
Expand Down

0 comments on commit 6a238dc

Please sign in to comment.