Rewrite SQLFORM.grid() as class

35 views
Skip to first unread message

iiij...@gmail.com

unread,
Oct 18, 2013, 1:09:34 PM10/18/13
to web2py-d...@googlegroups.com
Would it make sense to rewrite the SQLFORM.grid() method as a class. For example:
class SQLGrid(DIV):
def __init__(self, ...):
def __call__(self):
# build and return grid
def header(self):
# return grid header
def paginator(self):
# return grid paginator
def search_widget(self):
# return grid search widget

And then for backwards compatibility:
class SQLFORM(FORM):
def grid(...)
return = SQLGrid(*args, *kwargs)()
Some advantages:
  • The code would be more readable as smaller class methods.
  • Many nested functions in grid() could be methods.
  • Variables like exportManager and the ui dicts could be class properties.
  • Methods could be used to build components, eg header, paginator, buttons, search_widget
  • The class could be subclassed for customization.
  • To create custom components, subclass and override methods as needed.
  • Easier to test.
I haven't been involved in developing the grid so possibly I've overlooked something. I'd be willing to put some time in getting it started, but I'd need help with the design.

Jim Karsten

Massimo DiPierro

unread,
Oct 19, 2013, 6:09:01 PM10/19/13
to web2py-d...@googlegroups.com
it would make sense. In particular it would make sense to change the way parameters are passed to the grid and allow to change the state of the object through its properties.

--
-- mail from:GoogleGroups "web2py-developers" mailing list
make speech: web2py-d...@googlegroups.com
unsubscribe: web2py-develop...@googlegroups.com
details : http://groups.google.com/group/web2py-developers
the project: http://code.google.com/p/web2py/
official : http://www.web2py.com/
---
You received this message because you are subscribed to the Google Groups "web2py-developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py-develop...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Anthony

unread,
Oct 19, 2013, 7:44:59 PM10/19/13
to web2py-d...@googlegroups.com
Yes. The current grid method is very long and difficult to follow -- it could really benefit from some code re-organization. This may also make it easier for users to swap out some of the standard output with custom formatting.

Anthony
Reply all
Reply to author
Forward
0 new messages