Skip to content

Harden admin tree state sync and add strict admin mode#43

Merged
TimurKady merged 1 commit intomainfrom
update-gettreesignature-to-include-_path
Mar 2, 2026
Merged

Harden admin tree state sync and add strict admin mode#43
TimurKady merged 1 commit intomainfrom
update-gettreesignature-to-include-_path

Conversation

@TimurKady
Copy link
Copy Markdown
Owner

Motivation

  • Prevent client-side restoration of stale expanded-state after server-side tree changes by making the tree signature more robust and optionally disabling local restores in strict mode.
  • Ensure DB-driven rendering avoids expensive per-row cached methods for critical visual cues (child presence, depth) to improve correctness and performance.
  • Remove inconsistent local state after successful drag-and-drop moves so UI reflects the authoritative server snapshot after reload.

Description

  • Added TREENODE_STRICT_ADMIN_MODE setting (treenode/settings.py) to enable a strict admin mode that disables client-side localStorage restoration of expanded state.
  • Extended the changelist HTML to expose data-strict-admin-mode on the #changelist container and injected the flag from the admin view (treenode/admin/admin.py -> changelist_view).
  • Expanded client getTreeSignature() in treenode/static/treenode/js/treenode_admin.js to include row order (index) and data-path (_path) and read data-strict-admin-mode; in strict mode the JS drops the stored state instead of restoring it.
  • After a successful move/ AJAX call the client now removes the model-scoped expanded-state key from localStorage before calling location.reload() to avoid restoring stale state (treenode_admin.js).
  • Emit data-path (from _path) and use _depth directly in server-rendered rows for both initial and AJAX row rendering by updating AdminMixin and AJAX row template (treenode/admin/mixin.py, treenode/templates/treenode/admin/treenode_ajax_rows.html).
  • Reduce per-row cached-method usage by annotating changelist queryset with tn_children_count=Count('children') and using that annotated value (with fallback) for toggle/icon decisions and by using _depth for indentation (treenode/admin/admin.py, treenode/templatetags/treenode_admin.py).

Testing

  • Ran python -m compileall treenode to validate Python files compile successfully (succeeded).
  • Attempted python -m django test treenode.tests but it failed in this environment because DJANGO_SETTINGS_MODULE is not configured (test runner not available here).
  • Attempted pytest -q but pytest-django could not auto-discover a Django project in this environment (no manage.py / configured project), so full test run was not possible here.

Codex Task

@TimurKady TimurKady merged commit 26faeed into main Mar 2, 2026
4 checks passed
@TimurKady TimurKady deleted the update-gettreesignature-to-include-_path branch March 2, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant