Alternatives to the DataGridField / NamedFile / NamedImage mess?

I have a (very big) content type (a Program) that uses a data grid field to store Courses, and one of the attributes of a course is a syllabus (e.g. a PDF).

I've been stuck trying to get around

I've stepped through the z3c.form and datagridfield code and, ugh, I'm sure there are reasons why z3c.form is this complex, but perhaps my brain will never grasp them. OTOH, this is my first really deep dive into it.

Assuming I can't figure out this bug, what would a good UI alternative be for storing these courses? There can be a variable number of courses. The Program type is folderish, so I suppose I could just have it contain Course objects.

We use DataGridField or more often ag-Grid for presenting and managing record-like data.


1 Like

Do you use DGF with NamedFile or NamedImage fields in the row schema? That is the particular bug I refer to: you can set the file (or image) and save, but if you edit the main content item again, whether you modify the file or leave it untouched ("Keep existing file"), when you try to save the main content item, the file shows as not having been set and causes a validation error.

As @davisagli mentioned in that issue 6 years ago (and I think in another response to a post of mine when I had a similar issue with PFG and DGF ~3-4 years ago), the problem is that the DGF reconstructs the contained widgets on save, incorrectly in the case of NamedFile and NamedImage widgets because the nochange action in the POST is not handled during that reconstruction.

For my concrete example: I use this schema for the datagrid rows representing a course:

This is the course schema:

This is where I use the datagrid:

But this problem isn't specific to my code. The general case is DGF and either NamedFile or NamedImage.

To follow up: I gave up on using DGF with NamedFile fields. Instead, I created a new contained content type that includes the NamedFile fields.