Skip to content

Commit

Permalink
new labels during processing licences in layout.json
Browse files Browse the repository at this point in the history
  • Loading branch information
alex75 committed Aug 23, 2024
1 parent 75eca1d commit 528162b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
7 changes: 4 additions & 3 deletions cads_catalogue/layout_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def manage_licence_section(
blocks = new_section.get("blocks", [])
replacements = 0
for i, block in enumerate(copy.deepcopy(blocks)):
if block.get("type") == "licence":
if block.get("type") == "licence_widget":
licence_uid = block["licence-id"]
try:
licence = [
Expand Down Expand Up @@ -296,7 +296,7 @@ def build_licence_block2(
}
licence_blocks.append(licence_block)
new_block = {
"type": "licences",
"type": "licence_block",
"id": "licences_section",
"title": "Licence",
"details": {"licences": licence_blocks},
Expand All @@ -322,7 +322,7 @@ def manage_licence_section2(
blocks = new_section.get("blocks", [])
for i, block in enumerate(copy.deepcopy(blocks)):
if (
block.get("type") == "licences"
block.get("type") == "licence_block"
and block.get("id") == "licences_section"
and "details" in block
):
Expand All @@ -339,6 +339,7 @@ def manage_licence_section2(
raise ValueError(f"not found licence {licence_uid}")
licence_objs.append(licence_obj)
new_block = build_licence_block2(licence_objs, doc_storage_url)
new_block["title"] = blocks[i].get("title", new_block["title"])
del blocks[i]
blocks.insert(i, new_block)
elif block.get("type") in ("section", "accordion"):
Expand Down
10 changes: 5 additions & 5 deletions tests/data/layout1.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@
"caption": "Variables"
},
{
"type": "licences",
"type": "licence_block",
"id": "licences_section",
"title": "Licences",
"title": "a title",
"details": {
"licences": [
{
Expand All @@ -153,9 +153,9 @@
"id": "d_download",
"blocks": [
{
"title": "Licence",
"title": "A title to not override",
"id": "licence",
"type": "licence",
"type": "licence_block",
"details": {
"licences": [
{
Expand Down Expand Up @@ -224,7 +224,7 @@
"type": "section",
"blocks": [
{
"type": "licence",
"type": "licence_widget",
"licence-id": "licence-to-use-copernicus-products",
"id": "licence-to-use-copernicus-products"
}
Expand Down
10 changes: 5 additions & 5 deletions tests/data/layout2.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@
"caption": "Variables"
},
{
"type": "licences",
"type": "licence_block",
"id": "licences_section",
"title": "Licence",
"title": "a title",
"details": {
"licences": [
{
Expand Down Expand Up @@ -161,9 +161,9 @@
"id": "d_download",
"blocks": [
{
"title": "Licence",
"title": "A title to not override",
"id": "licence",
"type": "licence",
"type": "licence_block",
"details": {
"licences": [
{
Expand Down Expand Up @@ -232,7 +232,7 @@
"type": "section",
"blocks": [
{
"type": "licence",
"type": "licence_widget",
"licence-id": "licence-to-use-copernicus-products",
"id": "licence-to-use-copernicus-products"
}
Expand Down
8 changes: 4 additions & 4 deletions tests/test_30_layout_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ def test_transform_licences_blocks(tmpdir, session_obj: sa.orm.sessionmaker):
all_licences = session.scalars(sa.select(database.Licence)).all()
# create a test layout.json
layout_path = os.path.join(str(tmpdir), "layout.json")
block1 = {"licence-id": all_licences[0].licence_uid, "type": "licence"}
block1 = {"licence-id": all_licences[0].licence_uid, "type": "licence_widget"}
block2 = {
"type": "link",
"id": "test-link-id",
"title": "a link",
"href": "http://a-link.html",
}
block3 = {"licence-id": all_licences[1].licence_uid, "type": "licence"}
block3 = {"licence-id": all_licences[1].licence_uid, "type": "licence_widget"}
sections = [
{"id": "overview", "blocks": [block1, block2, block3]},
{"id": "overview2", "blocks": [block2, block3]},
Expand Down Expand Up @@ -105,14 +105,14 @@ def test_transform_licences_blocks(tmpdir, session_obj: sa.orm.sessionmaker):
}

# build a nested version
block1 = {"licence-id": all_licences[0].licence_uid, "type": "licence"}
block1 = {"licence-id": all_licences[0].licence_uid, "type": "licence_widget"}
block2 = {
"type": "link",
"id": "test-link-id",
"title": "a link",
"href": "http://a-link.html",
}
block3 = {"licence-id": all_licences[1].licence_uid, "type": "licence"}
block3 = {"licence-id": all_licences[1].licence_uid, "type": "licence_widget"}
section1 = {"id": "overview", "blocks": [block1, block2, block3]}
section2 = {"id": "overview2", "blocks": [block2, block3]}
section3 = {"id": "section1", "type": "section", "blocks": [block1, block3]}
Expand Down

0 comments on commit 528162b

Please sign in to comment.