Skip to content

Commit

Permalink
Merge pull request #200 from WycliffeAssociates/handle-tn-condensed
Browse files Browse the repository at this point in the history
Handle tn condensed
  • Loading branch information
PurpleGuitar authored Jun 5, 2024
2 parents b6dd9c7 + 1c7268b commit 1f1fcbb
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 26 deletions.
7 changes: 3 additions & 4 deletions backend/document/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ class Settings(BaseSettings):
(which have higher priority).
"""

REPO_URL_DICT_KEY: str = "../download-scripture?repo_url"
ALT_REPO_URL_DICT_KEY: str = "/download-scripture?repo_url"

# The location where the JSON data file that we use to lookup
# location of resources is located.
TRANSLATIONS_JSON_LOCATION: HttpUrl
Expand Down Expand Up @@ -119,7 +116,7 @@ class Settings(BaseSettings):
*EN_USFM_RESOURCE_TYPES,
]
TN_RESOURCE_TYPES: Sequence[str] = ["tn"]
EN_TN_RESOURCE_TYPES: Sequence[str] = ["tn-wa"]
EN_TN_RESOURCE_TYPES: Sequence[str] = ["tn-wa", "tn-condensed"]
ALL_TN_RESOURCE_TYPES: Sequence[str] = [*EN_TN_RESOURCE_TYPES, *TN_RESOURCE_TYPES]
TQ_RESOURCE_TYPES: Sequence[str] = ["tq"]
EN_TQ_RESOURCE_TYPES: Sequence[str] = ["tq-wa"]
Expand Down Expand Up @@ -294,6 +291,7 @@ def api_test_url(self) -> str:
"ulb-wa": "https://content.bibletranslationtools.org/WycliffeAssociates/en_ulb",
"udb-wa": "https://content.bibletranslationtools.org/WycliffeAssociates/en_udb",
"tn-wa": "https://content.bibletranslationtools.org/WycliffeAssociates/en_tn",
"tn-condensed": "https://content.bibletranslationtools.org/WycliffeAssociates/en_tn_condensed",
"tw-wa": "https://content.bibletranslationtools.org/WycliffeAssociates/en_tw",
"tq-wa": "https://content.bibletranslationtools.org/WycliffeAssociates/en_tq",
"bc-wa": "https://content.bibletranslationtools.org/WycliffeAssociates/en_bc",
Expand All @@ -309,6 +307,7 @@ def api_test_url(self) -> str:
"ulb-wa": "Unlocked Literal Bible (ULB)",
# "udb-wa": "Unlocked Dynamic Bible (UDB)",
"tn-wa": "ULB Translation Notes",
"tn-condensed": "ULB Condensed Translation Notes",
"tq-wa": "ULB Translation Questions",
"tw-wa": "ULB Translation Words",
"bc-wa": "Bible Commentary",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def assemble_content_by_lang_then_book(
key=lambda book_content_unit: book_content_unit.lang_name,
)

book_id_map = dict((id, pos) for pos, id in enumerate(BOOK_NAMES.keys()))
book_id_map = dict((id, pos) for pos, id in enumerate(book_names.keys()))

for language, group_by_lang in groupby(
book_units_sorted_by_language,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ def chapter_intro(
hr: HtmlContent = HtmlContent("<hr/>"),
) -> Iterable[HtmlContent]:
"""Get the chapter intro."""
if book_content_unit and chapter_num in book_content_unit.chapters:
if (
book_content_unit
and chapter_num in book_content_unit.chapters
and book_content_unit.chapters[chapter_num].intro_html
):
yield book_content_unit.chapters[chapter_num].intro_html
yield hr
else:
Expand Down Expand Up @@ -321,7 +325,11 @@ def chapter_commentary(
hr: HtmlContent = HtmlContent("<hr/>"),
) -> Iterable[HtmlContent]:
"""Get the chapter commentary."""
if book_content_unit and chapter_num in book_content_unit.chapters:
if (
book_content_unit
and chapter_num in book_content_unit.chapters
and book_content_unit.chapters[chapter_num].commentary
):
yield book_content_unit.chapters[chapter_num].commentary
yield hr
else:
Expand Down
2 changes: 1 addition & 1 deletion backend/document/domain/document_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,8 +891,8 @@ def copy_file_to_docker_output_dir(
Copy file to docker_container_document_output_dir.
"""
assert exists(filepath)
logger.debug("About to cp file to %s", document_output_dir)
shutil.copy(filepath, document_output_dir)
logger.debug("About to cp file: %s to directory: %s", filepath, document_output_dir)


@worker.app.task(
Expand Down
23 changes: 5 additions & 18 deletions backend/document/domain/resource_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,30 +72,17 @@ def _lookup(

def _parse_repo_url(
url: str,
repo_url_dict_key: str = settings.REPO_URL_DICT_KEY,
alt_repo_url_dict_key: str = settings.ALT_REPO_URL_DICT_KEY,
) -> Optional[str]:
"""
Given a URL of the form
../download-scripture?repo_url=https%3A%2F%2Fgit.door43.org%2Fburje_duro%2Fam_gen_text_udb&book_name=Genesis,
return the repo_url query parameter value.
https://doc.bibleineverylanguage.org/transfer/repo_url=https%3A%2F%2Fcontent.bibletranslationtools.org%2Fdcs-mirror%2Fparfait-ayanou_abu_eph_text_reg&book_name=Ephesians
return the repo_url value.
"""
if url is None:
return None
result = urllib_parse.parse_qs(url)
result_lst = []
try:
result_lst = result[repo_url_dict_key]
except KeyError:
logger.debug(
"repo_url_dict_key: %s, is not the right key for this url: %s, trying %s key instead",
repo_url_dict_key,
url,
alt_repo_url_dict_key,
)
result_lst = result[alt_repo_url_dict_key]
if result_lst:
return result_lst[0]
result_parts = url.split("repo_url=")
if len(result_parts) == 2:
return result_parts[1]
return None


Expand Down
69 changes: 69 additions & 0 deletions tests/e2e/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1642,3 +1642,72 @@ def test_fa_ulb_tn_lbo_1c_chapter() -> None:
},
)
check_result(response, suffix="docx")


@pytest.mark.docx
def test_en_ulb_wa_col_en_tn_condensed_col_language_book_order_with_no_email_1c_docx() -> None:
"""
Produce chapter interleaved document for English scripture and
translation notes for the book of Colossians.
"""
with TestClient(app=app, base_url=settings.api_test_url()) as client:
response = client.post(
"/documents_docx",
json={
# "email_address": settings.TO_EMAIL_ADDRESS,
"assembly_strategy_kind": model.AssemblyStrategyEnum.LANGUAGE_BOOK_ORDER,
"assembly_layout_kind": model.AssemblyLayoutEnum.ONE_COLUMN,
"layout_for_print": False,
"chunk_size": model.ChunkSizeEnum.CHAPTER,
"generate_pdf": False,
"generate_epub": False,
"generate_docx": True,
"resource_requests": [
{
"lang_code": "en",
"resource_type": "ulb-wa",
"book_code": "col",
},
{
"lang_code": "en",
"resource_type": "tn-condensed",
"book_code": "col",
},
],
},
)
check_result(response, suffix="docx")


def test_en_ulb_wa_col_en_tn_condensed_col_language_book_order_with_no_email_1c() -> None:
"""
Produce chapter interleaved document for English scripture and
translation notes for the book of Colossians.
"""
with TestClient(app=app, base_url=settings.api_test_url()) as client:
response = client.post(
"/documents_docx",
json={
# "email_address": settings.TO_EMAIL_ADDRESS,
"assembly_strategy_kind": model.AssemblyStrategyEnum.LANGUAGE_BOOK_ORDER,
"assembly_layout_kind": model.AssemblyLayoutEnum.ONE_COLUMN,
"layout_for_print": False,
"chunk_size": model.ChunkSizeEnum.CHAPTER,
"generate_pdf": False,
"generate_epub": False,
"generate_docx": False,
"resource_requests": [
{
"lang_code": "en",
"resource_type": "ulb-wa",
"book_code": "col",
},
{
"lang_code": "en",
"resource_type": "tn-condensed",
"book_code": "col",
},
],
},
)
check_finished_document_with_verses_success(response, suffix="pdf")

0 comments on commit 1f1fcbb

Please sign in to comment.