--- a/src/pyams_form/search.py Sun Jul 19 01:55:38 2020 +0200
+++ b/src/pyams_form/search.py Sun Jul 19 01:56:27 2020 +0200
@@ -15,6 +15,7 @@
This module provides a few helpers which can be used in search forms.
"""
+from pyramid.decorator import reify
from pyramid.response import Response
from z3c.form import button, field
from z3c.table.interfaces import IValues
@@ -22,7 +23,7 @@
from zope.schema import TextLine
from pyams_form.form import AddForm
-from pyams_form.interfaces.form import ISearchForm, IWidgetForm
+from pyams_form.interfaces.form import ISearchForm, ISearchFormFactory, IWidgetForm
from pyams_form.schema import ResetButton
from pyams_skin.interfaces import IContentSearch, IInnerPage, ISearchPage
from pyams_skin.layer import IPyAMSLayer
@@ -94,12 +95,18 @@
"""Base search view"""
search_form_factory = SearchForm
- search_form = None
+
+ @reify
+ def search_form(self):
+ form = self.request.registry.queryMultiAdapter((self.context, self.request, self),
+ ISearchFormFactory)
+ if form is None:
+ form = self.search_form_factory(self.context, self.request)
+ return form
def update(self):
"""Update search view"""
# pylint: disable=no-member
- self.search_form = self.search_form_factory(self.context, self.request)
self.search_form.update()