{"id":19756375,"url":"https://github.com/mara/mara-page","last_synced_at":"2025-04-30T11:33:27.021Z","repository":{"id":18559990,"uuid":"84608323","full_name":"mara/mara-page","owner":"mara","description":"Minimal API for defining pages of Flask-based backends independently from the actual backend infrastructure","archived":false,"fork":false,"pushed_at":"2023-11-21T15:25:50.000Z","size":2389,"stargazers_count":4,"open_issues_count":1,"forks_count":5,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-22T13:19:38.135Z","etag":null,"topics":["acl","backend","flask","mara","navigation"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mara.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-10T23:10:45.000Z","updated_at":"2023-01-27T08:42:12.000Z","dependencies_parsed_at":"2023-02-15T07:15:56.396Z","dependency_job_id":null,"html_url":"https://github.com/mara/mara-page","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mara%2Fmara-page","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mara%2Fmara-page/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mara%2Fmara-page/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mara%2Fmara-page/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mara","download_url":"https://codeload.github.com/mara/mara-page/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251691619,"owners_count":21628357,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["acl","backend","flask","mara","navigation"],"created_at":"2024-11-12T03:15:43.759Z","updated_at":"2025-04-30T11:33:25.213Z","avatar_url":"https://github.com/mara.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mara page\n\n[![mara-page](https://github.com/mara/mara-page/actions/workflows/build.yaml/badge.svg)](https://github.com/mara/mara-page/actions/workflows/build.yaml)\n[![PyPI - License](https://img.shields.io/pypi/l/mara-page.svg)](https://github.com/mara/mara-page/blob/main/LICENSE)\n[![PyPI version](https://badge.fury.io/py/mara-page.svg)](https://badge.fury.io/py/mara-page)\n[![Slack Status](https://img.shields.io/badge/slack-join_chat-white.svg?logo=slack\u0026style=social)](https://communityinviter.com/apps/mara-users/public-invite)\n\nMinimal API for defining pages of Flask-based backends independently from the actual backend infrastructure.\n\nWhen a web app is spread across many independent Flask blueprints, then this library can be used to add\n\n- navigation entries\n- page titles\n- resource-based ACL protection\n- page-specific CSS and JS files\n\nwithout having access to a global layout or the Flask app.\n\n\nThe library provides a drop-in werkzeug ``Response`` class that is enriched with additional information that a\nbackend can use to render the final html page.\n\n## Example\n\nThis is a simple web ui for displaying the current time:\n\n```python\n\"\"\"Clock UI\"\"\"\n\nimport flask\nfrom awesome_clock import clock\nfrom mara_page import acl, navigation, response, bootstrap, _\n\n# The flask blueprint that handles\nblueprint = flask.Blueprint('awesome_clock', __name__, url_prefix='/clock', static_folder='static')\n\n# Defines an ACL resource (needs to be handled by the application)\nacl_resource = acl.AclResource('Clock')\n\n\ndef navigation_entry():\n    \"\"\"Defines a part of the navigation tree (needs to be handled by the application)\"\"\"\n    return navigation.NavigationEntry(\n        label='Awesome clock', icon='clock-o', description='Something that tells the time',\n        children=[\n            navigation.NavigationEntry(\n                label='What time is it now?',\n                uri_fn=lambda: flask.url_for('awesome_clock.clock_page', when='now'),\n                icon='question-circle', description='Should be able to display the current time'),\n\n            navigation.NavigationEntry(\n                label='And now?', icon='refresh', description='For the impatient',\n                uri_fn=lambda: flask.url_for('awesome_clock.clock_page', when='and-now'))\n        ])\n\n\n@blueprint.route('/\u003cstring:when\u003e')\n@acl.require_permission(acl_resource)  # Requires permission to the `'Clock'` resource\ndef clock_page(when: str):\n    \"\"\"Defines the `/clock` page\"\"\"\n    return response.Response(\n        # The actual page content (can be also a call to `flask.render_template`\n        # or anything else that produces a string)\n        html=bootstrap.card(header_left=_.h1['What time is it now?'],\n                            body=[_.p['The current time is ', str(clock.what_time_is_it_now())],\n                                  _.img(src=flask.url_for('awesome_clock.static', filename='cuckoo-clock.jpg'),\n                                        style='max-width:100%')]),\n        # The page title\n        title='Awesome clock',\n\n        # Action buttons\n        action_buttons=[\n            response.ActionButton('javascript:location.reload()', 'Refresh', 'Refresh clock', 'refresh'),\n            response.ActionButton('javascript:location.reload()', 'Update', 'Refresh clock', 'clock-o')\n        ]\n    )\n```\n\nIt is up to the actual Flask app to define how to render such a response and what to do with the ACL resources and navigation entries.\nThe [mara app](https://github.com/mara/mara-app) will render the response like this:\n\n![Example backend](https://github.com/mara/mara-page/raw/main/docs/_static/awesome-clock.png)\n\n## Links\n\n* Documentation: https://mara-page.readthedocs.io/\n* Changes: https://mara-page.readthedocs.io/en/latest/changes.html\n* PyPI Releases: https://pypi.org/project/mara-page/\n* Source Code: https://github.com/mara/mara-page\n* Issue Tracker: https://github.com/mara/mara-page/issues\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmara%2Fmara-page","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmara%2Fmara-page","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmara%2Fmara-page/lists"}