-
Notifications
You must be signed in to change notification settings - Fork 2
Adds breadcrumbs to search resutls for Topic and News #2282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
ae72f66
0ece469
6cc9cb1
713a697
1d0b009
bd1b9d2
d32a3d6
7e0f149
8ecbaff
502a4cc
80facd9
ce6a0c9
7f971d5
104a248
b96c10f
c74f7c3
56b3905
2026859
baa55ab
8952372
35e646e
2a354c7
7f19e29
a9d6c18
73ae86d
b26baad
e4cc346
e2006d1
c531b26
0c8c712
325f9d2
1aa413e
f7fe90c
2314336
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remember to also register the layouts for |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| from onegov.core.request import CoreRequest | ||
| from onegov.core.security import Private | ||
| from onegov.core.utils import normalize_for_url | ||
| from onegov.org.layout import DefaultLayout, Layout | ||
| from onegov.org.models import News, TANAccessCollection, Topic | ||
| from onegov.page import Page, PageCollection | ||
| from onegov.user import User | ||
|
|
@@ -283,3 +284,21 @@ def analytics_provider(self) -> AnalyticsProvider | None: | |
| if name := self.app.org.analytics_provider_name: | ||
| return self.app.available_analytics_providers.get(name) | ||
| return None | ||
|
|
||
| def get_layout(self, model: object) -> Layout | DefaultLayout: | ||
| """ | ||
| Get the registered layout for a model instance. | ||
| """ | ||
| layout_registry = self.app.config.layout_registry | ||
| model_type = model if isinstance(model, type) else type(model) | ||
|
|
||
| layout_class = None | ||
| for cls in model_type.mro(): | ||
| layout_class = layout_registry.get(cls) | ||
| if layout_class: | ||
| break | ||
|
|
||
| if layout_class is None: | ||
| layout_class = DefaultLayout | ||
|
|
||
| return layout_class(model, self) | ||
Daverball marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+288
to
+304
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could probably simplify this by instead relying on a @dispatch_method()
def get_layout_class(self, model: object) -> type[Layout] | None:
return None
...
@Framework.predicate(Framework.get_layout_class, name="model", default=None, index=ClassIndex)
def model_predicate(self, model: object) -> type:
return model if isinstance(model, type) else model.__class__which simplifies def get_layout(self, model: object) -> Layout:
"""
Get the registered layout for a model instance.
"""
layout_class = self.app.get_layout_class(model)
if layout_class is None:
layout_class = DefaultLayout
return layout_class(model, self)You could also register a which simplifies def get_layout(self, model: object) -> Layout:
"""
Get the registered layout for a model instance.
"""
layout_class = self.app.get_layout_class(model)
assert layout_class is not None
return layout_class(model, self)and lets you override the fallback in You then also no longer need a registry for the def perform(self, layout: type[Layout], app_class: type[Framework]) -> None:
app_class.get_layout_class.register(layout, model=self.model) |
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type annotation for
layout_registryshould bedict[type, type]instead ofdict[type, Layout]since the layout parameter represents a layout class (type), not an instance of the Layout directive class. The perform method stores layout classes in the registry, not Layout directive instances.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cleaned up the type annotations to still include
Layout, but otherwise a correct suggestion.