Le 2026-11-28 22:25, Washington Odhiambo a écrit :
Give Claude the task. Should be very easy for Claude :-)
On Sun, Nov 29, 2026 at 1:17 AM iMark <imark@posteo.net> wrote: The server has multiple lists on it. For just 2 of the lists I'm attempting to make the Name a required field when subscribing.
Many thanks for pointing me there. Claude delivered the answer. Here it is:
Save this as /tmp/patch_postorius.py
import re import shutil import sys
PATH = "/opt/mailman/venv/lib/python3.11/site-packages/postorius/views/list.py" LISTS = [ "mylistname.mydomain.com", "otherlistname.otherdomain.com", ]
src = open(PATH).read() if "NAME_REQUIRED_LISTS" in src: sys.exit("Already patched (or has manual edits). Restore the stock file first.")
shutil.copy(PATH, PATH + ".orig")
1. Module-level constant, inserted before the first top-level class
const = "NAME_REQUIRED_LISTS = {\n" + "".join(f" '{l}',\n" for l in LISTS) + "}\n\n\n" m = re.search(r"^class ", src, re.M) if not m: sys.exit("No top-level class found.") src = src[:m.start()] + const + src[m.start():]
2. POST handler: enforce on submit
pat_post = re.compile(r"^([ \t]*)form = ListAnonymousSubscribe\(request\.POST\)\n", re.M) if len(pat_post.findall(src)) != 1: sys.exit("POST form line not found exactly once; patch manually.") src = pat_post.sub( lambda m: ( f"{m.group(1)}form = ListAnonymousSubscribe(request.POST)\n" f"{m.group(1)}if self.mailing_list.list_id.lower() in NAME_REQUIRED_LISTS:\n" f"{m.group(1)} form.fields['display_name'].required = True\n" f"{m.group(1)} form.fields['display_name'].label = _('Your name')\n" ), src, )
3. Summary page: show the form as required
pat_sum = re.compile( r"^([ \t]*)data\['anonymous_subscription_form'\] = ListAnonymousSubscribe\(\)\n", re.M ) if len(pat_sum.findall(src)) != 1: sys.exit("Summary form line not found exactly once; patch manually.") src = pat_sum.sub( lambda m: ( f"{m.group(1)}anon_form = ListAnonymousSubscribe()\n" f"{m.group(1)}if self.mailing_list.list_id.lower() in NAME_REQUIRED_LISTS:\n" f"{m.group(1)} anon_form.fields['display_name'].required = True\n" f"{m.group(1)} anon_form.fields['display_name'].label = _('Your name')\n" f"{m.group(1)}data['anonymous_subscription_form'] = anon_form\n" ), src, )
open(PATH, "w").write(src) print("Patched. Original saved as", PATH + ".orig")
================================================================================ Then run:
/opt/mailman/venv/bin/python /tmp/patch_postorius.py
diff -u /opt/mailman/venv/lib/python3.11/site-packages/postorius/views/list.py.orig /opt/mailman/venv/lib/python3.11/site-packages/postorius/views/list.py
/opt/mailman/venv/bin/python -m py_compile /opt/mailman/venv/lib/python3.11/site-packages/postorius/views/list.py
Review the diff output. It should show only three hunks: the constant, the POST check, and the summary form. If py_compile prints nothing, restart uwsgi/gunicorn.
Save that diff -u output somewhere safe, since pip install -U postorius will overwrite the change. You can reapply it with patch -p0 or just rerun the script.
This covers anonymous subscribers only, as you asked. Logged-in users still see the name as optional.
If the script exits with a "not found exactly once" message, paste the lines around ListAnonymousSubscribe from your file and I'll adjust the patterns.
================================================================================