|
26 | 26 | from invenio_circulation.pidstore.pids import CIRCULATION_LOAN_PID_TYPE |
27 | 27 | from invenio_db import db |
28 | 28 | 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 |
30 | 32 | from invenio_pidstore.models import PersistentIdentifier, PIDStatus |
31 | 33 | from invenio_pidstore.providers.recordid_v2 import RecordIdProviderV2 |
32 | 34 | from invenio_search import current_search |
@@ -1605,33 +1607,52 @@ def page_data(page): |
1605 | 1607 | .decode("utf8") |
1606 | 1608 | ) |
1607 | 1609 |
|
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 | + }, |
1632 | 1633 | ] |
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 :)") |
0 commit comments