Skip to content

Commit

Permalink
Merge branch 'main' into issue-878/eur-bank-transfer-iso-11649-refere…
Browse files Browse the repository at this point in the history
…nces

Conflicts:
	apps/common/epc.py [logical, non-merge conflict]
	apps/payments/invoice.py
	tests/test_epc.py
  • Loading branch information
jayaddison committed Dec 22, 2023
2 parents 2085434 + 4aabbcd commit 8c8e269
Show file tree
Hide file tree
Showing 49 changed files with 726 additions and 945 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ on:
schedule:
- cron: '30 5 */14 * *'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
DOCKER_BUILDKIT: 1

Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ on:
env:
COMPOSE_INTERACTIVE_NO_CLI: 1

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on: [pull_request]
env:
COMPOSE_INTERACTIVE_NO_CLI: 1

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
Expand Down
15 changes: 14 additions & 1 deletion apps/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,20 @@ def main():

@base.route("/", methods=["POST"])
def main_post():
email = request.form.get("email")
honeypot_field = request.form.get("name")
email = request.form.get("email", "").strip()

if email == "":
return redirect(url_for(".main"))

if honeypot_field != "":
app.logger.warn(
"Mailing list honeypot field failed for %s (IP %s)",
email,
request.remote_addr,
)
flash("We aren't able to subscribe you at this time.")
return redirect(url_for(".main"))

response = requests.post(
app.config["LISTMONK_URL"] + "/api/public/subscription",
Expand Down
126 changes: 39 additions & 87 deletions apps/base/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,110 +5,62 @@
although some legacy content remains here.
"""

from flask import redirect, render_template, url_for
from . import base


@base.route("/about")
def about():
return render_template("about/index.html")


@base.route("/about/travel")
def travel():
return render_template("about/getting-there.html")


@base.route("/about/arrival-times")
def arrival():
return render_template("about/arrival-times.html")


@base.route("/about/covid")
def covid():
return redirect(url_for(".health"))


@base.route("/about/health")
def health():
return render_template("about/health.html")


@base.route("/about/privacy")
def privacy():
return render_template("about/privacy.html")


@base.route("/about/power")
def power():
return render_template("about/power.html")
from flask import abort, current_app as app, redirect, render_template, url_for
from markdown import markdown
from os import path
from pathlib import Path

from markupsafe import Markup
from yaml import safe_load as parse_yaml
from . import base

# @base.route("/about/internet")
# def internet():
# return render_template("about/internet.html")

def page_template(metadata):
if "show_nav" not in metadata or metadata["show_nav"] is True:
return "about/template.html"
else:
return "static_page.html"

@base.route("/about/accessibility")
def accessibility():
return render_template("about/accessibility.html")

def render_markdown(source, **view_variables):
template_root = Path(path.join(app.root_path, app.template_folder)).resolve()
source_file = template_root.joinpath(f"{source}.md").resolve()

@base.route("/about/villages")
def villages():
return render_template("about/villages.html")
if not source_file.is_relative_to(template_root) or not source_file.exists():
return abort(404)

with open(source_file, "r") as f:
source = f.read()
(metadata, content) = source.split("---", 2)
metadata = parse_yaml(metadata)
content = Markup(markdown(content, extensions=["markdown.extensions.nl2br"]))

@base.route("/about/childcare")
def childcare():
return render_template("about/childcare.html")
view_variables.update(content=content, title=metadata["title"])
return render_template(page_template(metadata), **view_variables)


@base.route("/about/branding")
def branding():
return render_template("branding.html")
@base.route("/about/<page_name>")
def page(page_name: str):
return render_markdown(f"about/{page_name}", page_name=page_name)


@base.route("/about/design-elements")
def design_elements():
return render_template("design.html")
# About and Contact have actual logic in them, so remain as HTML rather than
# markdown
@base.route("/about")
def about():
return render_template("about/index.html")


@base.route("/about/company")
@base.route("/company")
def company():
return render_template("about/company.html")


@base.route("/about/volunteering")
def volunteering():
return render_template("about/volunteering.html")


@base.route("/about/volunteer-roles")
def volunteer_roles():
return render_template("about/volunteer-roles.html")


@base.route("/about/what_to_bring")
def what_to_bring_redirect():
return redirect(url_for(".what_to_bring"))


@base.route("/about/what-to-bring")
def what_to_bring():
return render_template("about/what-to-bring.html")


@base.route("/about/bring-and-donate")
def bring_and_donate():
return render_template("about/bring-and-donate.html")


@base.route("/about/food")
def food():
return render_template("about/food.html")
return render_markdown("about/company")


@base.route("/about/contact")
def contact():
return render_template("about/contact.html")


@base.route("/about/covid")
def covid():
return redirect(url_for(".health"))
4 changes: 2 additions & 2 deletions apps/base/tasks_banking.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def create_bank_accounts():
active=True,
institution="London Bank",
address="13 Bartlett Place, London, WC1B 4NM",
iban="GB47LOND11213141516171",
swift="GB47LOND",
iban="GB33BUKB20201555555555",
swift="GB33BUKB",
)
for acct in [gbp, eur]:
try:
Expand Down
39 changes: 39 additions & 0 deletions apps/common/epc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from io import BytesIO

from markupsafe import Markup
from segno import QRCode, helpers

from models.payment import BankPayment


def make_epc_qrfile(payment: BankPayment, **kwargs) -> BytesIO:
qrfile = BytesIO()
# TODO: this isn't currently used. Need to fetch IBAN from payment.recommended_destination
# and name from somewhere - maybe config rather than hard-coding.
qr: QRCode = helpers.make_epc_qr(
name="EMF Festivals Ltd",
iban=payment.recommended_destination.iban,
amount=payment.amount,
reference=payment.customer_reference,
encoding=1,
)
qr.save(qrfile, **kwargs)
qrfile.seek(0)
return qrfile


def qrfile_to_svg(qrfile: BytesIO) -> str:
return Markup(qrfile.getvalue().decode("utf-8"))


def format_inline_epc_qr(payment: BankPayment) -> str:
qrfile = make_epc_qrfile(
payment,
kind="svg",
svgclass=None,
omitsize=True,
xmldecl=False,
svgns=False,
nl=False,
)
return qrfile_to_svg(qrfile)
37 changes: 1 addition & 36 deletions apps/payments/invoice.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from decimal import Decimal
from io import BytesIO
import logging
import shutil
import os.path
Expand All @@ -15,55 +14,21 @@
send_file,
)
from flask_login import login_required, current_user
from markupsafe import Markup
from segno import helpers
from sqlalchemy.sql.functions import func
from wtforms import TextAreaField, SubmitField

from main import external_url, db
from ..common.receipt import render_pdf
from models.product import Product, PriceTier
from models.purchase import Purchase
from ..common.epc import format_inline_epc_qr
from ..common.forms import Form
from . import get_user_payment_or_abort
from . import payments

logger = logging.getLogger(__name__)


def make_epc_qrfile(payment, **kwargs):
qrfile = BytesIO()
# TODO: this isn't currently used. Need to fetch IBAN from payment.recommended_destination
# and name from somewhere - maybe config rather than hard-coding.
qr = helpers.make_epc_qr(
name="EMF Festivals Ltd",
iban=payment.recommended_destination.iban,
amount=payment.amount,
reference=payment.customer_reference,
encoding=1,
)
qr.save(qrfile, **kwargs)
qrfile.seek(0)
return qrfile


def qrfile_to_svg(qrfile):
return Markup(qrfile.getvalue().decode("utf-8"))


def format_inline_epc_qr(payment):
qrfile = make_epc_qrfile(
payment,
kind="svg",
svgclass=None,
omitsize=True,
xmldecl=False,
svgns=False,
nl=False,
)
return qrfile_to_svg(qrfile)


class InvoiceForm(Form):
company = TextAreaField("Company name")
update = SubmitField("Update")
Expand Down
7 changes: 5 additions & 2 deletions apps/volunteer/bar_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
from models.volunteer.volunteer import Volunteer


APPLICATION_ROOT = os.path.abspath(os.path.join(__file__, "..", "..", ".."))


def build_questions(training_json):
"""
Assigns specific IDs to questions and answers so that we can determine which
Expand Down Expand Up @@ -53,7 +56,7 @@ def build_questions(training_json):


def load_training_json(path):
file_path = os.path.abspath(os.path.join(__file__, "..", "..", "..", path))
file_path = os.path.join(APPLICATION_ROOT, path)
if not os.path.exists(file_path):
return None

Expand All @@ -65,7 +68,7 @@ def load_training_markdown(path):
Takes a file path for a Markdown file (relative to project root)
and returns the HTML (from Markdown) for that file.
"""
file_path = os.path.abspath(os.path.join(__file__, "..", "..", "..", path))
file_path = os.path.join(APPLICATION_ROOT, path)
if not os.path.exists(file_path):
return None

Expand Down
3 changes: 3 additions & 0 deletions css/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -415,3 +415,6 @@ input[type=range]::range-thumb {
}


#mailing-list-form #name-field {
display: none;
}
Loading

0 comments on commit 8c8e269

Please sign in to comment.