A question on new grid

146 views
Skip to first unread message

David Manns

unread,
Aug 7, 2024, 11:18:10 AM8/7/24
to py4web
I belatedly discovered a problem with (at least one of) my grids:
grid = Grid(path, (db.Reservations.Member==member.id)&(db.Reservations.Event==event.id),
orderby=~db.Reservations.Host|db.Reservations.Lastname|db.Reservations.Firstname,
columns=[db.Reservations.Lastname, db.Reservations.Firstname, db.Reservations.Notes,
Column('Selection', lambda row: res_selection(row.id),),
Column('Price', lambda row: res_unitcost(row.id)),
Column('Status', lambda row: res_status(row.id))],
headings=['Last', 'First', 'Notes', 'Selection', 'Price', 'Status'],
deletable=lambda row: write and (ismember!='Y' or row.Provisional or row.Waitlist),
details=not write,
editable=lambda row: write and (ismember!='Y' or row['Provisional'] or row['Waitlist']),
create=write and (ismember!='Y' or not event.Guests or (len(all_guests)<event.Guests)),
grid_class_style=grid_style, formstyle=form_style, validation=validate, show_id=ismember!='Y')


This is a bit modal, the edit/delete buttons display or not depending on whether the request is from a regular (ismember=='Y') or admin user as well as fields in the record. Failed in the ismember=='Y' case (which I had missed in earlier testing). Just like the case with Fields referenced in Column lambda functions.

I can fix thus:
grid = Grid(path, (db.Reservations.Member==member.id)&(db.Reservations.Event==event.id),
orderby=~db.Reservations.Host|db.Reservations.Lastname|db.Reservations.Firstname,
columns=[db.Reservations.Lastname, db.Reservations.Firstname, db.Reservations.Notes,
Column('Selection', lambda row: res_selection(row.id),
required_fields=[db.Reservations.Provisional, db.Reservations.Waitlist]),
Column('Price', lambda row: res_unitcost(row.id)),
Column('Status', lambda row: res_status(row.id))],
headings=['Last', 'First', 'Notes', 'Selection', 'Price', 'Status'],
deletable=lambda row: write and (ismember!='Y' or row.Provisional or row.Waitlist),
details=not write,
editable=lambda row: write and (ismember!='Y' or row['Provisional'] or row['Waitlist']),
create=write and (ismember!='Y' or not event.Guests or (len(all_guests)<event.Guests)),
grid_class_style=grid_style, formstyle=form_style, validation=validate, show_id=ismember!='Y')


but I'm not sure how I would fix if I didn't have at least one Column in which to stash the required fields list.

Perhaps add a 'required_fields" option to the grid itself?

Would it be practicable to auto-detect required fields in lamba functions both in Columns and elsewhere?

David

Massimo DiPierro

unread,
Aug 7, 2024, 11:56:00 AM8/7/24
to David Manns, py4web

that would be too much magic. we could add an explicit list of required_field as you suggest. in that case, does Column need required_fields?


--
You received this message because you are subscribed to the Google Groups "py4web" group.
To unsubscribe from this group and stop receiving emails from it, send an email to py4web+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/py4web/d419184e-9347-444e-a404-674f30434f94n%40googlegroups.com.

David Manns

unread,
Aug 7, 2024, 12:22:17 PM8/7/24
to py4web
That's what I thought. With a required_fields option in grid, it would technically be redundant within Column, but perhaps best to deprecate it rather than remove it to maintain backward compatability? Within Column, it actually functions as if it were a grid level option, so its more logically a grid parameter.

And it would be nice to have a note in the docs that fields used in lambda functions need to be added to required_fields if not included in columns list.

Jim Steil

unread,
Aug 7, 2024, 3:28:35 PM8/7/24
to py4web
I added required_fields to Column() because in my use cases the required fields were specifically required for that column and nowhere else in the grid. That, and we were trying to keep the grid signature uncluttered. I'm fine with changing it, will require lots of updates to my existing code, but that shouldn't take more than 1/2 an hour to fix. I'm working now to catch up with the latest grid changes. Broke a number of my apps as well as the htmx integration I'd been using. It will take me some time to get that all back up. If only there were more time in the day....

-JIm

Massimo DiPierro

unread,
Aug 7, 2024, 4:34:53 PM8/7/24
to Jim Steil, py4web
Sorry Jim. Same boat here.

Jim Steil

unread,
Aug 7, 2024, 4:39:39 PM8/7/24
to py4web
The price of progress, right? It all goes to making the product better. Happy to see all the activity lately, just sorry I don't have the time to contribute more

-Jim

Massimo DiPierro

unread,
Aug 7, 2024, 4:43:10 PM8/7/24
to Jim Steil, py4web

this seems like a good time to add some regression tests.


David Manns

unread,
Aug 7, 2024, 5:49:05 PM8/7/24
to py4web
I applaud the desire to keep the grid signature clean.

But I submit that I might not be the only oddball to use lambda functions to control the presence/absence of edit/delete buttons depending on fields that need to be required, so I vote for a grid parameter 'required_fields'

Py4web is a brilliant piece of design, you guys are amazing!

David

Massimo

unread,
Aug 9, 2024, 8:45:20 PM8/9/24
to py4web
for now I added a Grid level required_fields 
Reply all
Reply to author
Forward
Message has been deleted
0 new messages