Customise Postorius templates?
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.
Is there a 'best' way for this? I'd also like to eventually share them with the community and maybe add them to the repo if people want that....but for now I'll start with my own experiments. (and if there is documentation I have missed for this, let me know!)
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 var/templates directory has a specific structure and is only for custom list specific, domain specific and sitewide templates used for notifications from Mailman core. It has nothing to do with Postorius or HyperKitty templates.
Is there a 'best' way for this? I'd also like to eventually share them with the community and maybe add them to the repo if people want that....but for now I'll start with my own experiments. (and if there is documentation I have missed for this, let me know!)
I don't know about a best
way, but the way I do this is to keep all
local mods as patches to the base and apply those patches as part of the
upgrade process.
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
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 var/templates directory has a specific structure and is only for custom list specific, domain specific and sitewide templates used for notifications from Mailman core. It has nothing to do with Postorius or HyperKitty templates.
Is there a 'best' way for this? I'd also like to eventually share them with the community and maybe add them to the repo if people want that....but for now I'll start with my own experiments. (and if there is documentation I have missed for this, let me know!)
I don't know about a
best
way, but the way I do this is to keep all local mods as patches to the base and apply those patches as part of the upgrade process.
The best way to do this would be utilize Django’s template loader. See here1 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 the TEMPLATES
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.
One important point to note here is that we can’t promise to not break your custom template in future, because the values passed in the template’s context is not a public or stable API. So, it is technically possible for us to remove/change the variables that are being passed. In practice, I can’t remember when was the last time I removed a variable, so this would work better than patching since you are doing “radical customisation”, which Mark isn’t.
-- thanks, Abhilash Raj (maxking)
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.
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)
- 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
- 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
- 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!)
Cheers,
Duane
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)
On Mon, 7 Feb 2022 at 19:30, Abhilash Raj <maxking@asynchronous.in> wrote:
I hadn’t tried it when I sent email, but when I tried it locally on Postorius, it seems to work for me.
Good to know it seems to work for you. Means it is possible and I was missing something obvious ;-)
In the end, using the full path and spelling postorius correctly were the two crucial steps.
Now off to customise.
Is anyone out there working on an overhaul of the web interface templates (e.g. more mobile friendly, classes or selectors on all key html tags, css updates, re-ordering individual HTML file structure, etc)? I'm not currently anticipating adding/changing any of the includes. I'm wanting to make the web interfaces look like 2022 and would love to then share that with the community (may take 6 ish months) - something that could make the project more attractive (literally) to people.
Cheers,
Duane.
Duane Raymond writes:
Is anyone out there working on an overhaul of the web interface templates
Yes. There's a big accessibility project being done by a well-resourced organization. If you're going to be doing the kind of substantial work you describe, write me off-list and I'll do some introductions. (That applies to anybody reading this; project participation is by introduction, "well-resourced" doesn't mean "infinite" ;-), but anybody making a substantial contribution has need-to-know.)
I'm not sure how much is still publicly available since the ownership change, but you might want to look at the Affinity and Empathy projects at emwd.com. The code is PHP but you may get some ideas from the UIs.
Steve
Hi Stephan!
On Tue, 8 Feb 2022 at 07:02, Stephen J. Turnbull <stephenjturnbull@gmail.com> wrote:
Duane Raymond writes:
Is anyone out there working on an overhaul of the web interface templates
Yes. There's a big accessibility project being done by a well-resourced organization.
Great - I'll follow up offlist
I'm not sure how much is still publicly available since the ownership change, but you might want to look at the Affinity and Empathy projects at emwd.com. The code is PHP but you may get some ideas from the UIs.
Yes - that is one one the UIs I've been looking at (available via archive.org if it goes offline). I've also looked at https://gaggle.email and other platforms for UI ideas.
I'm still in the scoping-out phase, but am thinking at adapting hyperkitty as the homepage as it has built-in all the variables for list activity (if archived) which means I can leverage the participation and message info to create an enticing, vibrant overview. and then deep link into the postorious interface for list management. subscription management.
Cheers,
Duane
The REST API provides a means to customise templates on a list, domain or site context.
https://docs.mailman3.org/projects/mailman/en/latest/src/mailman/rest/docs/t...
We use a very simple script that takes a text file from the current directory and, when run locally on a MM3 server, uses the REST API to update the template on a site context, thus affecting all lists and all domains on the same server.
from mailman.testing.documentation import call_http
def update_template(template_name, template_file):
""" Update the specified template """
print("Updating", template_name)
call_http(
'http://localhost:8001/3.1/uris',
{
template_name: template_file
},
method='PATCH',
username="restadmin",
password="restpass"
)
update_template(
"list:admin:action:post",
"file:///home/ubuntu/mm3-templates/list:admin:action:post.txt"
)
The API documentation lists out the various template names that can be used.
On Mon, 7 Feb 2022 at 08:46, Philip Colmer <philip.colmer@linaro.org> wrote:
The REST API provides a means to customise templates on a list, domain or site context.
https://docs.mailman3.org/projects/mailman/en/latest/src/mailman/rest/docs/t...
Perhaps I misunderstood, but this seems to focus on the email message templates, and not html Postorius and Hyperkitty templates....or were you suggesting I adapt the script below for use with patches and Postorius and Hyperkitty templates? Seems like a plausible idea of the django template method Abhilash Raj pointed me to doesn't work.
We use a very simple script that takes a text file from the current directory and, when run locally on a MM3 server, uses the REST API to update the template on a site context, thus affecting all lists and all domains on the same server.
from mailman.testing.documentation import call_http def update_template(template_name, template_file): """ Update the specified template """ print("Updating", template_name) call_http( 'http://localhost:8001/3.1/uris', { template_name: template_file }, method='PATCH', username="restadmin", password="restpass" ) update_template( "list:admin:action:post", "file:///home/ubuntu/mm3-templates/list:admin:action:post.txt" )
The API documentation lists out the various template names that can be used.
https://lists.mailman3.org/mailman3/lists/mailman-users.mailman3.org/
My apologies. I misunderstood what you were trying to achieve.
Apologies for the noise :-)
On Mon, 7 Feb 2022, 11:57 Duane Raymond, <duane@fairsay.com> wrote:
On Mon, 7 Feb 2022 at 08:46, Philip Colmer <philip.colmer@linaro.org> wrote:
The REST API provides a means to customise templates on a list, domain or site context.
https://docs.mailman3.org/projects/mailman/en/latest/src/mailman/rest/docs/t...
Perhaps I misunderstood, but this seems to focus on the email message templates, and not html Postorius and Hyperkitty templates....or were you suggesting I adapt the script below for use with patches and Postorius and Hyperkitty templates? Seems like a plausible idea of the django template method Abhilash Raj pointed me to doesn't work.
We use a very simple script that takes a text file from the current directory and, when run locally on a MM3 server, uses the REST API to update the template on a site context, thus affecting all lists and all domains on the same server.
from mailman.testing.documentation import call_http def update_template(template_name, template_file): """ Update the specified template """ print("Updating", template_name) call_http( 'http://localhost:8001/3.1/uris', { template_name: template_file }, method='PATCH', username="restadmin", password="restpass" ) update_template( "list:admin:action:post", "file:///home/ubuntu/mm3-templates/list:admin:action:post.txt" )
The API documentation lists out the various template names that can be used.
https://lists.mailman3.org/mailman3/lists/mailman-users.mailman3.org/
participants (5)
-
Abhilash Raj
-
Duane Raymond
-
Mark Sapiro
-
Philip Colmer
-
Stephen J. Turnbull