-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Handle placeholders being added and removed from templates when … #63
base: master
Are you sure you want to change the base?
Conversation
…saving existing objects. * Don't assume the queryset order matches the formset initial data order, which can change when placeholders are moved in a template. Match initial data to placeholder instance by slot name instead of index. * If a placeholder exists in the database but no longer exists in the template, and therefore has no initial data, get the slot name from orphaned placeholders by index. This is a best guess and might be wrong? * Add a sanity check (raises KeyError). We should *always* be able to find initial data for a new placeholder. We can probably remove this check?
This still doesn't quite work, but I found some more issues while implementing your suggested changes (loop to cache queryset, remove Another edge case I discovered is when placeholders exist in the database and are removed from the template. I've tried to handle that with a Unfortunately, I think the original problem The core problem is that when editing an existing object, some placeholders will exist in the database and some will not. When the formset is rendered for placeholders that are not in the database, they have no I don't much time to dig much deeper right now, but if you can further point me in the right direction I can keep trying. If we're not going to call Is it OK to get orphaned placeholders by index, like I am doing here? |
Just to answer a few of your questions quickly:
In standard Django, When writing this code, I've uses step-through debugging in PyCharm to get this code working, because the inner workings of the formset/inlineadmin code is complex. By walking through the formset code - even through |
Is changing the layout client side the same as changing the template used by a layout? If not, should it be? I haven't tested for this problem when switching layouts, only when altering the actual template that defines placeholders for a given layout. If this "marked for deletion" thing happens via client side JS when layout is switched, I guess it won't happen when a template that defines layouts is altered and the page is reloaded. This is causing us problems both when new placeholders are added, and existing placeholders are removed. So, how and where would I attempt to imitate this "on layout switch" behaviour on every page load, when the number of placeholders and slot name for placeholders defined in the template no longer match existing placeholders in the database? |
Good points. The server-side support is indeed lacking, and the client-side hid that mostly because layout switching was the only option at first. I would vote for getting server-support proper too. When opening a page, I'd expect all placeholders to look good, and in the right order. That would imply that When saving, the situation should be saved, and any old orphaned placeholders can be cleaned up. This seems like to cleanest route to me. You never expect a save using a GET call, only when the user actually saves something. |
Thanks. I'll take another look at updating One potential issue though is that the class is named
|
Yes, I'm fine with merging that class with the |
…saving existing objects.
can change when placeholders are moved in a template. Match initial data to
placeholder instance by slot name instead of index.
and therefore has no initial data, get the slot name from orphaned
placeholders by index. This is a best guess and might be wrong?
initial data for a new placeholder. We can probably remove this check?