Skip to content

Commit c64dfce

Browse files
committed
pages: update cli for creating pages to new invenio-pages version
1 parent bd03224 commit c64dfce

File tree

2 files changed

+54
-30
lines changed

2 files changed

+54
-30
lines changed

invenio_app_ils/cli.py

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
from invenio_circulation.pidstore.pids import CIRCULATION_LOAN_PID_TYPE
2727
from invenio_db import db
2828
from invenio_indexer.api import RecordIndexer
29-
from invenio_pages import Page
29+
from invenio_pages.proxies import current_pages_service
30+
from invenio_pages.records.errors import PageNotFoundError
31+
from invenio_access.permissions import system_identity
3032
from invenio_pidstore.models import PersistentIdentifier, PIDStatus
3133
from invenio_pidstore.providers.recordid_v2 import RecordIdProviderV2
3234
from invenio_search import current_search
@@ -1605,33 +1607,52 @@ def page_data(page):
16051607
.decode("utf8")
16061608
)
16071609

1608-
pages = [
1609-
Page(
1610-
url="/about",
1611-
title="About",
1612-
description="About",
1613-
content="InvenioILS about page",
1614-
template_name="invenio_pages/default.html",
1615-
),
1616-
Page(
1617-
url="/contact",
1618-
title="Contact",
1619-
description="Contact",
1620-
content="You can contact InvenioILS developers on "
1621-
'<a href="https://gitter.im/inveniosoftware/invenio">'
1622-
"our chatroom</a>",
1623-
template_name="invenio_pages/default.html",
1624-
),
1625-
Page(
1626-
url="/guide/search",
1627-
title="Search guide",
1628-
description="Search guide",
1629-
content=page_data("search_guide.html"),
1630-
template_name="invenio_pages/default.html",
1631-
),
1610+
pages_data = [
1611+
{
1612+
"url": "/about",
1613+
"title": "About",
1614+
"description": "About",
1615+
"content": "InvenioILS about page",
1616+
},
1617+
{
1618+
"url": "/contact",
1619+
"title": "Contact",
1620+
"description": "Contact",
1621+
"content": (
1622+
"You can contact InvenioILS developers on "
1623+
'<a href="https://gitter.im/inveniosoftware/invenio">'
1624+
"our chatroom</a>"
1625+
),
1626+
},
1627+
{
1628+
"url": "/guide/search",
1629+
"title": "Search guide",
1630+
"description": "Search guide",
1631+
"template": "search_guide.html",
1632+
},
16321633
]
1633-
with db.session.begin_nested():
1634-
Page.query.delete()
1635-
db.session.add_all(pages)
1636-
db.session.commit()
1637-
click.echo("static pages created :)")
1634+
1635+
_supported_languages = current_app.config.get("I18N_LANGUAGES", [("en", "English")])
1636+
1637+
for entry in pages_data:
1638+
url = entry["url"]
1639+
for lang in _supported_languages:
1640+
lang_code = lang[0]
1641+
try:
1642+
current_pages_service.read_by_url(system_identity, url, lang_code)
1643+
except PageNotFoundError:
1644+
page_data = {
1645+
"url": url,
1646+
"title": entry.get("title", ""),
1647+
"description": entry.get("description", ""),
1648+
"lang": lang_code,
1649+
"template_name": current_app.config["PAGES_DEFAULT_TEMPLATE"],
1650+
"content": (
1651+
page_data(entry["template"])
1652+
if entry.get("template")
1653+
else entry.get("content", "")
1654+
),
1655+
}
1656+
current_pages_service.create(system_identity, page_data)
1657+
1658+
click.echo("Static pages created :)")

invenio_app_ils/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,3 +1078,6 @@ def _(x):
10781078

10791079
# Use default frontpage
10801080
THEME_FRONTPAGE = False
1081+
1082+
# Default template to render.
1083+
PAGES_DEFAULT_TEMPLATE = "invenio_pages/default.html"

0 commit comments

Comments
 (0)