On 2/15/23 07:52, Jeremy Stanley wrote:
Thanks, I'm still doing my best to wrap my brain around how Django uses database migrations to create sites (seems like a very strange use of a migration, I'm only accustomed to seeing them applied for database schema updates).
I don't think it does. There are a couple of migrations at django/contrib/sites/migrations, but these are only the initial creation of the model and an update to make the domain field unique.
Why do you think it creates sites in this way.
Once I work out how to script site creation, I'm still not completely finding the explanations I need for how to map them to domains in Mailman though.
The Mailman documentation about domains says "Domains are how Mailman interacts with email host names and web host names" but doesn't actually go on to say (that I can find anywhere) how it actually associates them.
Mailman core doesn't associate domains with Django sites. Mailman core knows nothing about a web UI. The association between Mailman core domains and Django sites is via Postorius. It doesn't exist in Mailman core. When Postorius sees a new domain from core, it assigns it a web_host based on the current web host accessing Postorius.
I can see in the API docs that a POST to the domains endpoint will create a new domain with a specific mail_host FQDN, but there's some association somewhere of that to a web host (Django site), right?
No. The only association is if Postorius is creating the domain in core, vs something else creating it via the REST API, Postorius will assign it a web_host in it's own Domain model, and that web host must be an existing Django site, which is only created via Django.
How is that set or manipulated through the API? Or is that something which has to be set directly in Django's data structures instead?
Yes, A new site has to be created in Django. Even Postorius doesn't do that.
To recap, on creation of a mailing list server I want to populate it automatically with multiple lists on different domains and have dynamic SITE_ID=0 domain guessing performed so that the correct site name and list filtering is performed depending on which domain name is used in a URL the client requests. I believe I need to have the automation perform the following steps:
Instantiate the Mailman installation and run initial migrations with SITE_ID=1 in order to avoid the problem mentioned in the docs about not using SITE_ID=0 until the tables have been populated, then switch the settings.py to use SITE_ID=0 once done.
Create the individual sites I need in Django (Mailman web hosts) by creating and applying database migrations.
No. You create the sites via Django, but not by creating and applying database migrations.
Create the individual domains I need in Mailman (Mailman mail hosts) through its REST API.
"Somehow" tell Mailman (or Django?) which mail hosts correspond to what web hosts.
Neither Mailman nor Django. It's Postorius which maintains the relationship between Django sites which it calls web_hosts and domains.
As I said, I'm still trying to understand how to make step 2 happen (Django has a steep learning curve for me), but beyond that I'm unsure how to do step 4 at all. I can do all of this through the WebUI of course, and have confirmed that it works as expected when I do, I'm just trying to work out the automation so that our other sysadmins don't have to perform these steps by hand the next time we need to rebuild the server.
Step 2.
$ django_admin shell
>>> from django.contrib.sites.models import Site
>>> new_site = Site(id=5, domain='5.example.com', name='display_name')
>>> new_site.save()
Of course the values are up to you and you can omit the id= to have Django assign the first available..
Once you've done step 2, you need to create a domain in Postorius. Look at the code behind Postorius add new domain. Or you can create the domain in core via REST, but you then have to modify it in Postorius to associate the correct site.
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan