From a3625e2d3a6fa52264e8d4a7a49b95792b8cc85b Mon Sep 17 00:00:00 2001 From: Jon Wood Date: Sun, 7 Jan 2024 15:18:09 +0000 Subject: [PATCH 1/3] Allow specifying which list to subscribe to --- apps/base/__init__.py | 6 +++++- apps/common/__init__.py | 14 +++++++++++++- config/development-example.cfg | 4 +++- templates/about/contact.html | 2 +- templates/home/_mailing_list_form.html | 5 ++++- templates/home/before-sales.html | 2 +- templates/home/cancelled-time-machine.html | 2 +- templates/home/cancelled.html | 2 +- templates/home/sales_block.html | 2 +- templates/purchase/speakers.html | 2 +- templates/purchase/tickets.html | 2 +- templates/subscribe.html | 2 +- templates/tickets/cutoff.html | 2 +- 13 files changed, 34 insertions(+), 13 deletions(-) diff --git a/apps/base/__init__.py b/apps/base/__init__.py index e680bfda8..fa66deae9 100644 --- a/apps/base/__init__.py +++ b/apps/base/__init__.py @@ -53,6 +53,10 @@ def main(): def main_post(): honeypot_field = request.form.get("name") email = request.form.get("email", "").strip() + list = request.form.get("list") + + if request.form.get("list") not in app.config["LISTMONK_LISTS"]: + return raise_404() if email == "": return redirect(url_for(".main")) @@ -68,7 +72,7 @@ def main_post(): response = requests.post( app.config["LISTMONK_URL"] + "/api/public/subscription", - json={"email": email, "list_uuids": [app.config["LISTMONK_LIST_ID"]]}, + json={"email": email, "list_uuids": [app.config["LISTMONK_LISTS"][list]]}, ) if response.status_code != 200: diff --git a/apps/common/__init__.py b/apps/common/__init__.py index 5000ecf6f..18ff661a0 100644 --- a/apps/common/__init__.py +++ b/apps/common/__init__.py @@ -7,7 +7,7 @@ import pendulum from main import db, external_url -from flask import session, abort, current_app as app +from flask import session, abort, current_app as app, render_template from markupsafe import Markup from flask.json import jsonify from flask_login import login_user, current_user @@ -145,6 +145,18 @@ def pretty_text(text): text = "\n".join(f"

{para}

" for para in re.split(r"[\r\n]+", text)) return Markup(text) + @app_obj.context_processor + def contact_form_processor(): + def contact_form(list): + """Renders a contact form for the requested list.""" + if list not in app_obj.config["LISTMONK_LISTS"]: + msg = f"The list '{list}' is not configured. Add it to your config file under LISTMONK_LISTS." + raise ValueError(msg) + + return Markup(render_template("home/_mailing_list_form.html", list=list)) + + return {"contact_form": contact_form} + def create_current_user(email: str, name: str): user = User(email, name) diff --git a/config/development-example.cfg b/config/development-example.cfg index a45a69895..bcdb3901d 100644 --- a/config/development-example.cfg +++ b/config/development-example.cfg @@ -30,7 +30,9 @@ TRANSFERWISE_ENVIRONMENT = "sandbox" TRANSFERWISE_API_TOKEN = "" LISTMONK_URL = "https://broadcast.emfcamp.org" -LISTMONK_LIST_ID = "e4f02d85-5f8f-458f-9f83-051edf25bfb0" +LISTMONK_LISTS = { + "main": "e4f02d85-5f8f-458f-9f83-051edf25bfb0" +} MAIL_SERVER = "localhost" MAIL_BACKEND = "console" diff --git a/templates/about/contact.html b/templates/about/contact.html index 1f801d570..853f1deff 100644 --- a/templates/about/contact.html +++ b/templates/about/contact.html @@ -21,7 +21,7 @@

Get Updates

If you're interested in updates about EMF, follow us on the Fediverse or join our mailing list:

- {% include "home/_mailing_list_form.html" %} + {{ contact_form("main")}}

Community

diff --git a/templates/home/_mailing_list_form.html b/templates/home/_mailing_list_form.html index d45c1615d..1ca57aa14 100644 --- a/templates/home/_mailing_list_form.html +++ b/templates/home/_mailing_list_form.html @@ -1,4 +1,5 @@
+
{# This is a honeypot field to prevent bots signing up, it's hidden by CSS #} @@ -8,4 +9,6 @@
-

(We'll only use your details to contact you about future events.)

+{% if list == "main" %} +

(We'll only use your details to contact you about future events.)

+{% endif %} diff --git a/templates/home/before-sales.html b/templates/home/before-sales.html index 82e3c9403..9ccd01a78 100644 --- a/templates/home/before-sales.html +++ b/templates/home/before-sales.html @@ -17,7 +17,7 @@ us on the Fediverse or join our mailing list:

- {% include "home/_mailing_list_form.html" %} + {{contact_form("main")}} diff --git a/templates/home/cancelled-time-machine.html b/templates/home/cancelled-time-machine.html index f5ab6b845..345fba7ea 100644 --- a/templates/home/cancelled-time-machine.html +++ b/templates/home/cancelled-time-machine.html @@ -64,7 +64,7 @@ Twitter or join our mailing list:

- {% include "home/_mailing_list_form.html" %} + {{contact_form("main")}} diff --git a/templates/home/cancelled.html b/templates/home/cancelled.html index b03118f69..5f9ab5c77 100644 --- a/templates/home/cancelled.html +++ b/templates/home/cancelled.html @@ -39,7 +39,7 @@ Twitter or join our mailing list:

- {% include "home/_mailing_list_form.html" %} + {{contact_form("main")}} diff --git a/templates/home/sales_block.html b/templates/home/sales_block.html index 98a32bdec..49a0bd420 100644 --- a/templates/home/sales_block.html +++ b/templates/home/sales_block.html @@ -11,7 +11,7 @@ the Fediverse or join our mailing list for more updates:

- {% include "home/_mailing_list_form.html" %} + {{contact_form("main")}} {% elif SALES_STATE == 'sold-out' %}

We’re sorry to say EMF is sold out! diff --git a/templates/purchase/speakers.html b/templates/purchase/speakers.html index f494059a9..33ef15fe9 100644 --- a/templates/purchase/speakers.html +++ b/templates/purchase/speakers.html @@ -5,7 +5,7 @@

Please follow us the Fediverse or join our mailing list to be notified when more tickets are on sale:

- {% include "home/_mailing_list_form.html" %} + {{contact_form("main")}}

We can't reserve any tickets, but if we accept your {% if config['CFP'] %} talk, workshop, or installation proposal, diff --git a/templates/purchase/tickets.html b/templates/purchase/tickets.html index 49b45f361..84692c35d 100644 --- a/templates/purchase/tickets.html +++ b/templates/purchase/tickets.html @@ -6,7 +6,7 @@

Please follow us the Fediverse or join our mailing list to be notified when more tickets are on sale:

- {% include "home/_mailing_list_form.html" %} + {{contact_form("main")}}

We can't reserve any tickets, but if we accept your {% if config['CFP'] %} diff --git a/templates/subscribe.html b/templates/subscribe.html index c7431483a..84aee5009 100644 --- a/templates/subscribe.html +++ b/templates/subscribe.html @@ -7,7 +7,7 @@

Subscribe to EMF event emails

If you'd like to be infrequently notified about EMF events, please sign up to our newsletter.

- {% include "home/_mailing_list_form.html" %} + {{contact_form("main")}}
{% endblock %} diff --git a/templates/tickets/cutoff.html b/templates/tickets/cutoff.html index 2adb2dbb7..276d8e6ad 100644 --- a/templates/tickets/cutoff.html +++ b/templates/tickets/cutoff.html @@ -12,7 +12,7 @@

If you're interested in updates on our next event, please follow us the Fediverse or join our mailing list:

- {% include "home/_mailing_list_form.html" %} + {{contact_form("main")}} {% endif %} {% if SALES_STATE != 'sales-ended' %} From 8aa9eaaa24cd8db80df13f274586c7b6ada28b5d Mon Sep 17 00:00:00 2001 From: Jon Wood Date: Sun, 7 Jan 2024 15:27:27 +0000 Subject: [PATCH 2/3] Allow Jinja in Markdown about pages --- apps/base/about.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/base/about.py b/apps/base/about.py index e7cd900ac..81e140a41 100644 --- a/apps/base/about.py +++ b/apps/base/about.py @@ -5,7 +5,14 @@ although some legacy content remains here. """ -from flask import abort, current_app as app, redirect, render_template, url_for +from flask import ( + abort, + current_app as app, + redirect, + render_template, + render_template_string, + url_for, +) from markdown import markdown from os import path from pathlib import Path @@ -33,7 +40,12 @@ def render_markdown(source, **view_variables): source = f.read() (metadata, content) = source.split("---", 2) metadata = parse_yaml(metadata) - content = Markup(markdown(content, extensions=["markdown.extensions.nl2br"])) + content = Markup( + markdown( + render_template_string(content), + extensions=["markdown.extensions.nl2br"], + ) + ) view_variables.update(content=content, title=metadata["title"]) return render_template(page_template(metadata), **view_variables) From 05eb58fd37eb6ac872344d4192d3b42cbea62330 Mon Sep 17 00:00:00 2001 From: Jon Wood Date: Sun, 7 Jan 2024 15:27:44 +0000 Subject: [PATCH 3/3] Add a signup form for the volunteering list --- config/development-example.cfg | 3 ++- templates/about/volunteering.md | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/config/development-example.cfg b/config/development-example.cfg index bcdb3901d..2d1b6e0d6 100644 --- a/config/development-example.cfg +++ b/config/development-example.cfg @@ -31,7 +31,8 @@ TRANSFERWISE_API_TOKEN = "" LISTMONK_URL = "https://broadcast.emfcamp.org" LISTMONK_LISTS = { - "main": "e4f02d85-5f8f-458f-9f83-051edf25bfb0" + "main": "e4f02d85-5f8f-458f-9f83-051edf25bfb0", + "volunteer": "ee88b1a2-a9da-4235-9223-7e537a3a44cc" } MAIL_SERVER = "localhost" diff --git a/templates/about/volunteering.md b/templates/about/volunteering.md index 806b88b50..5589ce66f 100644 --- a/templates/about/volunteering.md +++ b/templates/about/volunteering.md @@ -23,6 +23,11 @@ Running an event like EMF requires a huge amount of planning to make sure the ev **We're looking for people to help organise the event**. If this is something that interests you [take a look at the list of roles we're looking to fill](/about/volunteer-roles). +We also have a mailing list where we periodically post about volunteer roles, to +subscribe fill out the form below: + +{{ contact_form("volunteer") }} + ## Helping out during the event During the event, there are plenty of roles which need to be filled, from construction to cooking for volunteers.