fix: add make_form()
and make_grid()
methods on web handler
to allow override
This commit is contained in:
parent
74e2a4f0e2
commit
448dc9fc79
|
@ -26,7 +26,7 @@ Web Handler
|
|||
|
||||
from wuttjamaican.app import GenericHandler
|
||||
|
||||
from wuttaweb import static
|
||||
from wuttaweb import static, forms, grids
|
||||
|
||||
|
||||
class WebHandler(GenericHandler):
|
||||
|
@ -122,3 +122,23 @@ class WebHandler(GenericHandler):
|
|||
default='wuttaweb.menus:MenuHandler')
|
||||
self.menu_handler = self.app.load_object(spec)(self.config)
|
||||
return self.menu_handler
|
||||
|
||||
def make_form(self, request, **kwargs):
|
||||
"""
|
||||
Make and return a new :class:`~wuttaweb.forms.base.Form`
|
||||
instance, per the given ``kwargs``.
|
||||
|
||||
This is the "base" factory which merely invokes the
|
||||
constructor.
|
||||
"""
|
||||
return forms.Form(request, **kwargs)
|
||||
|
||||
def make_grid(self, request, **kwargs):
|
||||
"""
|
||||
Make and return a new :class:`~wuttaweb.grids.base.Grid`
|
||||
instance, per the given ``kwargs``.
|
||||
|
||||
This is the "base" factory which merely invokes the
|
||||
constructor.
|
||||
"""
|
||||
return grids.Grid(request, **kwargs)
|
||||
|
|
|
@ -30,7 +30,7 @@ from pyramid import httpexceptions
|
|||
from pyramid.renderers import render_to_response
|
||||
from pyramid.response import FileResponse
|
||||
|
||||
from wuttaweb import forms, grids
|
||||
from wuttaweb import grids
|
||||
|
||||
|
||||
class View:
|
||||
|
@ -75,7 +75,8 @@ class View:
|
|||
This is the "base" factory which merely invokes the
|
||||
constructor.
|
||||
"""
|
||||
return forms.Form(self.request, **kwargs)
|
||||
web = self.app.get_web_handler()
|
||||
return web.make_form(self.request, **kwargs)
|
||||
|
||||
def make_grid(self, **kwargs):
|
||||
"""
|
||||
|
@ -85,7 +86,8 @@ class View:
|
|||
This is the "base" factory which merely invokes the
|
||||
constructor.
|
||||
"""
|
||||
return grids.Grid(self.request, **kwargs)
|
||||
web = self.app.get_web_handler()
|
||||
return web.make_grid(self.request, **kwargs)
|
||||
|
||||
def make_grid_action(self, key, **kwargs):
|
||||
"""
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
|
||||
from wuttaweb import handler as mod, static
|
||||
from wuttaweb.forms import Form
|
||||
from wuttaweb.grids import Grid
|
||||
from wuttaweb.menus import MenuHandler
|
||||
from tests.util import WebTestCase
|
||||
|
||||
|
@ -62,3 +64,13 @@ class TestWebHandler(WebTestCase):
|
|||
handler = self.make_handler()
|
||||
menus = handler.get_menu_handler()
|
||||
self.assertIsInstance(menus, MenuHandler)
|
||||
|
||||
def test_make_form(self):
|
||||
handler = self.make_handler()
|
||||
form = handler.make_form(self.request)
|
||||
self.assertIsInstance(form, Form)
|
||||
|
||||
def test_make_grid(self):
|
||||
handler = self.make_handler()
|
||||
grid = handler.make_grid(self.request)
|
||||
self.assertIsInstance(grid, Grid)
|
||||
|
|
Loading…
Reference in a new issue