On Feb 7, 2022, at 4:35 AM, Duane Raymond <duane@fairsay.com> wrote:
On Mon, 7 Feb 2022 at 00:56, Abhilash Raj <maxking@asynchronous.in> wrote:
On Feb 1, 2022, at 11:01 AM, Mark Sapiro <mark@msapiro.net> wrote:
On 2/1/22 09:47, Duane Raymond wrote:
Hi, I'm looking to do some radical customisation of the Postorius (and Hyperkitty) templates over the next 6 ish months and was wondering if there is a 'best practice' way to do this that will survive updates to MM3. I've searched around and not found much and also tested copying
venv/lib/python3.7/site-packages/postorius/templates/postorius/lists/summary.html
to var/templates/lists/summary.html As suggested in some posts - but it didn't seem to pick up the customisation - only customisations in the venv path worked - and they get overwritten on update.
The best way to do this would be utilize Django’s template loader. See here[1] for the documentation on how you can do this. You want to put the path where you are putting the templates under
DIRS
option of theTEMPLATES
section.Do make sure that you are keeping the directory structure correct so that Django can discover them. Like, Hyperkitty’s base.html should be in
/custom/path/hyperkitty/base.html
, where/custom/path
is what you’ve setup in DIRS setting above.
I hadn’t tried it when I sent email, but when I tried it locally on Postorius, it seems to work for me.
This looks promising! I've not got it working yet, but this is what I've tried:
- Created folder 'custom' in the mm root (in my case: /opt/mailman/mm/)
- Copied the files and folders from postorius/templates/postorius/* and hyperkitty/templates/hyperkitty/* to the custom/ folder (not the full postorius/templates/postorius/ match, just evening in the second postorius/ dirrectory)
Note that you want to copy from “src/postorius/templates” directory to your "/opt/mailman/mm/custom” directory. It is important that you retain the “postorius” and “hyperkitty” directories.
Here is what I have in my settings.py:
'DIRS': [],
'DIRS': ['/Users/maxking/Documents/mm3/postorius/example_project/templates’],
And here is the structure of the templates directory you are seeing above:
$ tree /Users/maxking/Documents/mm3/postorius/example_project/templates /Users/maxking/Documents/mm3/postorius/example_project/templates └── postorius └── lists └── summary.html
Note that I am only overriding the Summary page here.
- Recursive update of permissions of the custom/ folder and files to be mailman
- Updated /opt/mailman/mm/settings.py by changing "'DIRS': []" to "'DIRS': [BASE_DIR, '/custom/']" in the "TEMPLATES =" section
Note that you don’t want [“BASE_DIR”, “/custom/“] here, the comma is the wrong value here. The docs I mentioned have a “/“.
Although, it is possible that even “/“ since that needs BASE_DIR to be a Path datatype and not string.
Easiest thing with least surprise would be to use the full path, atleast to ensure that template discovery works as expected.
- Edited the original AND copied postorius/lists/summary.html to have a small change in the footer of each so I know what version it is serving
Since I was running a dev server, it doesn’t need restart, but simply restarting gunicorn should should do it. You don’t need to restart anything else.
- Restarted: gunicorn qcluster mailman nginx and cleared browser cache
- Reloaded the 'info' page of a few lists to see which version ti was serving
Variants: I've also changed the DIRS value to the hard-coded path: /opt/mailman/mm/custom
Result: it is still serving the default/original Postorius template vs the custom one.
Any suggestions for things I should do to make it use the /custom/ folder instead? Any recompiling or other actions beyond just restarting? (I probably don't need to restart qcluster and maybe not even mailman core for this to take effect but I do it just in case!)
Hope that helps.
-- thanks, Abhilash Raj (maxking)