On 4/25/23 2:14 PM, Andrew Hodgson wrote:
Mark Sapiro wrote:
The script at https://www.msapiro.net/scripts/clean_users.py has been updated. As before, it has settings to control whether Django users are deleted if there is a corresponding Mailman user with no memberships or only if there is no corresponding Mailman user, and whether or not Mailman users with no >memberships are deleted.
Thanks, I ran this script and it did delete a load of Mailman users, I got output similar to this: <User "" (47600399411039288509336192576257642185) at 0x7fb17a6a35e0> deleted from Mailman
Why aren't we seeing the actual address here?
That was a choice I made. you could change
with transaction():
user_manager.delete_user(mm_user)
print(f'{mm_user} deleted from Mailman')
to
with transaction():
try:
email = user.preferred_address.email
except AttributeError:
email = 'no_preferred_address'
user_manager.delete_user(mm_user)
print(f'{email} deleted from Mailman')
to display the email address from the user's preferred_address if the user has one. All users should have one, but I've seen cases where there isn't one.
It could also be
email = user.addresses[0].email
which might be better.
In the above case, the empty string, "", is the user's display_name which in this case is empty, and the number in parentheses is the UUID of the user expressed as a decimal integer which isn't really useful. My thought was the display_name was as useful as anything, but obviously not if it's empty.
I actually started with the preferred_address.email code above, but in testing, I got the 'no_preferred_address' result with the one deleted user so I, perhaps erroneously, went with the representation of the user. I'll probably update the script again.
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan