Claude code ... ugh. I think it's right, but the *style* ... SMH. At least you'll know exactly what you did.
I suggest you save yourself some future grief. Try asking Claude for a patch that makes the 'required' parameter of that call to forms.CharField an attribute of MailingList, and make it configurable via the REST interface. At the same time, ask it for a program to configure that attribute via its REST endpoint. (This could be a call to the curl or wget command line utilities.)
I tried to phrase the spec for the patch sufficiently accurately that Claude might do the right thing with it.
Note that in any case you're likely to get multiple instances of "Harry Potter", "Donald John Trump", and "asdf". Not sure if you want to try to do anything about that. :-)
Steve
iMark writes:
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.
================================================================================
Mailman-users mailing list -- mailman-users@mailman3.org To unsubscribe send an email to mailman-users-leave@mailman3.org https://lists.mailman3.org/mailman3/lists/mailman-users.mailman3.org/ Archived at: https://lists.mailman3.org/archives/list/mailman-users@mailman3.org/message/...
This message sent to steve@turnbull.jp
-- GNU Mailman consultant (installation, migration, customization) Sirius Open Source https://www.siriusopensource.com/ Software systems consulting in Europe, North America, and Japan