Move the per user filter code in simple_form
authorMagnus Hagander <magnus@hagander.net>
Fri, 21 Nov 2025 08:16:44 +0000 (09:16 +0100)
committerMagnus Hagander <magnus@hagander.net>
Wed, 26 Nov 2025 11:09:43 +0000 (12:09 +0100)
This needs to be explicitly set after each instantiation of a form, not
in a shared location below since some operations have already happened
at that time.

pgweb/util/helpers.py

index 3c436eb202d701fd2c2b5e3d283fe816887560e1..f68534f40e4714cc2c49e92cd9fc7494d47ea4ce 100644 (file)
@@ -52,6 +52,8 @@ def simple_form(instancetype, itemid, request, formclass, formtemplate='base/for
 
         # Process this form
         form = formclass(data=request.POST, instance=instance)
+        if hasattr(form, 'filter_by_user'):
+            form.filter_by_user(request.user)
         for fn in form.fields:
             if fn in getattr(instancetype, 'markdown_fields', []):
                 form.fields[fn].validators.append(MarkdownValidator)
@@ -165,9 +167,8 @@ def simple_form(instancetype, itemid, request, formclass, formtemplate='base/for
     else:
         # Generate form
         form = formclass(instance=instance)
-
-    if hasattr(form, 'filter_by_user'):
-        form.filter_by_user(request.user)
+        if hasattr(form, 'filter_by_user'):
+            form.filter_by_user(request.user)
 
     for fn in form.fields:
         if fn in getattr(instancetype, 'markdown_fields', []):