3
0
Fork 0

fix: add make_form() and make_grid() methods on web handler

to allow override
This commit is contained in:
Lance Edgar 2024-12-11 22:06:33 -06:00
parent 74e2a4f0e2
commit 448dc9fc79
3 changed files with 38 additions and 4 deletions

View file

@ -26,7 +26,7 @@ Web Handler
from wuttjamaican.app import GenericHandler from wuttjamaican.app import GenericHandler
from wuttaweb import static from wuttaweb import static, forms, grids
class WebHandler(GenericHandler): class WebHandler(GenericHandler):
@ -122,3 +122,23 @@ class WebHandler(GenericHandler):
default='wuttaweb.menus:MenuHandler') default='wuttaweb.menus:MenuHandler')
self.menu_handler = self.app.load_object(spec)(self.config) self.menu_handler = self.app.load_object(spec)(self.config)
return self.menu_handler 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)

View file

@ -30,7 +30,7 @@ from pyramid import httpexceptions
from pyramid.renderers import render_to_response from pyramid.renderers import render_to_response
from pyramid.response import FileResponse from pyramid.response import FileResponse
from wuttaweb import forms, grids from wuttaweb import grids
class View: class View:
@ -75,7 +75,8 @@ class View:
This is the "base" factory which merely invokes the This is the "base" factory which merely invokes the
constructor. 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): def make_grid(self, **kwargs):
""" """
@ -85,7 +86,8 @@ class View:
This is the "base" factory which merely invokes the This is the "base" factory which merely invokes the
constructor. 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): def make_grid_action(self, key, **kwargs):
""" """

View file

@ -1,6 +1,8 @@
# -*- coding: utf-8; -*- # -*- coding: utf-8; -*-
from wuttaweb import handler as mod, static from wuttaweb import handler as mod, static
from wuttaweb.forms import Form
from wuttaweb.grids import Grid
from wuttaweb.menus import MenuHandler from wuttaweb.menus import MenuHandler
from tests.util import WebTestCase from tests.util import WebTestCase
@ -62,3 +64,13 @@ class TestWebHandler(WebTestCase):
handler = self.make_handler() handler = self.make_handler()
menus = handler.get_menu_handler() menus = handler.get_menu_handler()
self.assertIsInstance(menus, MenuHandler) 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)