Skip to content

Commit

Permalink
pages: added has_custom_view flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Fatimah committed Feb 18, 2024
1 parent 615c88a commit 67f69a8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
6 changes: 3 additions & 3 deletions invenio_pages/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def wrap_errorhandler(app):
existing_handler = None

if existing_handler:
app.error_handler_spec[None][404][
NotFound
] = lambda error: handle_not_found(error, wrapped=existing_handler)
app.error_handler_spec[None][404][NotFound] = (
lambda error: handle_not_found(error, wrapped=existing_handler)
)
else:
app.error_handler_spec.setdefault(None, {}).setdefault(404, {})
app.error_handler_spec[None][404][NotFound] = handle_not_found
Expand Down
10 changes: 9 additions & 1 deletion invenio_pages/records/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class PageModel(db.Model, Timestamp):
template_name = db.Column(db.String(70), nullable=False)
"""Page template name."""

has_custom_view = db.Column(db.Boolean(), nullable=False, default=False)
"""Page custom view flag."""

@classmethod
def create(self, data):
"""Create a new page."""
Expand All @@ -56,6 +59,7 @@ def create(self, data):
content=data.get("content", ""),
description=data.get("description", ""),
template_name=data["template_name"],
has_custom_view=data.get("has_custom_view", False),
)
db.session.add(obj)

Expand Down Expand Up @@ -143,7 +147,11 @@ def __repr__(self):
Used on Page admin view in inline model.
:returns: unambiguous page representation.
"""
return "URL: %s, title: %s" % (self.url, self.title)
return "URL: %s, title: %s, has_custom_view: %s" % (
self.url,
self.title,
self.has_custom_view,
)


class PageList(db.Model):
Expand Down
1 change: 1 addition & 0 deletions invenio_pages/services/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ class PageSchema(Schema):
content = DynamicSanitizedHTML()
description = fields.String()
template_name = fields.String()
has_custom_view = fields.Boolean()
created = TZDateTime(timezone=timezone.utc, format="iso", dump_only=True)
updated = TZDateTime(timezone=timezone.utc, format="iso", dump_only=True)
3 changes: 2 additions & 1 deletion invenio_pages/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def register_pages():
current_app.view_functions["invenio_pages.view"] = view

for page in Page.query.all():
_add_url_rule(page.url)
if not page.has_custom_view: # Check if page does not have a custom view
_add_url_rule(page.url)


@blueprint.app_template_filter("render_string")
Expand Down

0 comments on commit 67f69a8

Please sign in to comment.