From ee022f032df5d57c9ee560d0727af9236674da06 Mon Sep 17 00:00:00 2001
From: Lynne <>
Date: Wed, 19 Sep 2018 20:03:19 +0200
Subject: [PATCH 1/5] Add a dynamic currency system.
---
fosspay/blueprints/html.py | 9 ++++++---
fosspay/currency.py | 21 +++++++++++++++++++++
scripts/index.js | 1 +
templates/admin.html | 20 ++++++++++----------
templates/goal.html | 18 +++++++++---------
templates/index.html | 5 +++--
templates/panel.html | 4 ++--
7 files changed, 52 insertions(+), 26 deletions(-)
create mode 100644 fosspay/currency.py
diff --git a/fosspay/blueprints/html.py b/fosspay/blueprints/html.py
index ac6e01d..8ba98a6 100644
--- a/fosspay/blueprints/html.py
+++ b/fosspay/blueprints/html.py
@@ -6,6 +6,7 @@ from fosspay.database import db
from fosspay.common import *
from fosspay.config import _cfg, load_config
from fosspay.email import send_thank_you, send_password_reset
+from fosspay.currency import currency
import os
import locale
@@ -75,7 +76,7 @@ def index():
patreon_count=patreon_count,
patreon_sum=patreon_sum,
lp_count=lp_count,
- lp_sum=lp_sum)
+ lp_sum=lp_sum, currency=currency)
@html.route("/setup", methods=["POST"])
def setup():
@@ -103,6 +104,7 @@ def admin():
first=first,
projects=projects,
donations=donations,
+ currency=currency,
one_times=lambda p: sum([d.amount for d in p.donations if d.type == DonationType.one_time]),
recurring=lambda p: sum([d.amount for d in p.donations if d.type == DonationType.monthly and d.active]),
recurring_ever=lambda p: sum([d.amount * d.payments for d in p.donations if d.type == DonationType.monthly]),
@@ -202,7 +204,7 @@ def donate():
try:
charge = stripe.Charge.create(
amount=amount,
- currency="usd",
+ currency=_cfg("currency"),
customer=user.stripe_customer,
description="Donation to " + _cfg("your-name")
)
@@ -276,7 +278,8 @@ def reset_password(token):
def panel():
return render_template("panel.html",
one_times=lambda u: [d for d in u.donations if d.type == DonationType.one_time],
- recurring=lambda u: [d for d in u.donations if d.type == DonationType.monthly and d.active])
+ recurring=lambda u: [d for d in u.donations if d.type == DonationType.monthly and d.active],
+ currency=currency)
@html.route("/cancel/
- ${{ "{:.2f}".format(recurring_sum / 100) }}/mo
+ {{ currency.amount("{:.2f}".format(recurring_sum / 100)) }}/mo
via {{ domain }}
({{ recurring_count }} supporter{{ "s" if recurring_count != 1 else "" }})
- ${{ "{:.2f}".format(patreon_sum / 100) }}/mo
+ {{ currency.amount("{:.2f}".format(patreon_sum / 100)) }}/mo
via
- ${{ "{:.2f}".format(lp_sum / 100) }}/mo
+ {{ currency.amount("{:.2f}".format(lp_sum / 100)) }}/mo
via
- ${{ "{:.2f}".format(total_sum / 100)}}/mo
+ {{ currency.amount("{:.2f}".format(total_sum / 100))}}/mo
of
- ${{ "{:.2f}".format(goal / 100) }}/mo
+ {{ currency.amount("{:.2f}".format(goal / 100)) }}/mo
goal
- Supported with ${{ "{:.2f}".format(total_sum / 100) }}
+ Supported with ${{ currency.amount("{:.2f}".format(total_sum / 100)) }}
from {{ total_count }} supporters!
- {{ "{:.2f}".format(recurring_sum / 100) }}€ par mois
+ {{ currency.amount("{:.2f}".format(recurring_sum / 100)) }} par mois
via {{ domain }}
({{ recurring_count }} donateurice{{ "s" if recurring_count != 1 else "" }})
- {{ "{:.2f}".format(patreon_sum / 100) }}€ par mois
+ {{ currency.amount("{:.2f}".format(patreon_sum / 100)) }} par mois
via
- {{ "{:.2f}".format(lp_sum / 100) }}€ par mois
+ {{ currency.amount("{:.2f}".format(lp_sum / 100)) }} par mois
via
- {{ "{:.2f}".format(total_sum / 100)}}€ par mois
+ {{ currency.amount("{:.2f}".format(total_sum / 100))}} par mois
sur l'objectif de
- {{ "{:.2f}".format(goal / 100) }}€.
+ {{ currency.amount("{:.2f}".format(goal / 100)) }}.
- Supported with ${{ "{:.2f}".format(total_sum / 100) }}
- from {{ total_count }} supporters!
+ Soutenu par {{ total_count }} personne{{ "s" if total_count != 1 else "" }}
+ pour un montant total de {{ currency.amount("{:.2f}".format(total_sum / 100)) }}
{% endfor %}
{{ project.name }}
- ${{ "{:.2f}".format(one_times(project) / 100) }}
- ${{ "{:.2f}".format(recurring(project) / 100) }}
- ${{ "{:.2f}".format(recurring_ever(project) / 100) }}
+ {{ currency.amount("{:.2f}".format(one_times(project) / 100)) }}
+ {{ currency.amount("{:.2f}".format(recurring(project) / 100)) }}
+ {{ currency.amount("{:.2f}".format(recurring_ever(project) / 100)) }}
(not specified)
- ${{ "{:.2f}".format(unspecified_one_times / 100) }}
- ${{ "{:.2f}".format(unspecified_recurring / 100) }}
- ${{ "{:.2f}".format(unspecified_recurring_ever / 100) }}
+ {{ currency.amount("{:.2f}".format(unspecified_one_times / 100)) }}
+ {{ currency.amount("{:.2f}".format(unspecified_recurring / 100)) }}
+ {{ currency.amount("{:.2f}".format(unspecified_recurring_ever / 100)) }}
@@ -118,7 +118,7 @@
Total
- ${{ "{:.2f}".format(total_one_time / 100) }}
- ${{ "{:.2f}".format(total_recurring / 100) }}
- ${{ "{:.2f}".format(total_recurring_ever / 100) }}
+ {{ currency.amount("{:.2f}".format(total_one_time / 100)) }}
+ {{ currency.amount("{:.2f}".format(total_recurring / 100)) }}
+ {{ currency.amount("{:.2f}".format(total_recurring_ever / 100)) }}
{{ donation.user.email }}
{{ donation.project.name if donation.project else "" }}
{{ donation.comment if donation.comment else "" }}
- ${{ "{:.2f}".format(donation.amount / 100) }}
+ {{ currency.amount("{:.2f}".format(donation.amount / 100)) }}
{{ "Once" if str(donation.type) == "DonationType.one_time" else "Monthly" }}
{{ "(cancelled)" if not donation.active else "" }}
diff --git a/templates/goal.html b/templates/goal.html
index 8be983f..b98c514 100644
--- a/templates/goal.html
+++ b/templates/goal.html
@@ -23,21 +23,21 @@
class="progress-bar progress-bar-primary"
style="width: {{ recurring_progress * 100 }}%; line-height: 2.5"
>
- ${{ "{:.0f}".format(recurring_sum / 100) }}
+ {{ currency.amount("{:.0f}".format(recurring_sum / 100)) }}
{% endif %}
@@ -47,13 +47,13 @@
{{ donation.created.strftime("%Y-%m-%d") }}
- ${{ "{:.2f}".format(donation.amount / 100) }}
+ {{ currency.amount("{:.2f}".format(donation.amount / 100)) }}
{{ donation.project.name if donation.project else "Not specified" }}
{% endfor %}
@@ -51,7 +51,7 @@
{% for donation in one_times(user) %}
{% endfor %}
From 7be17efc8bc542f625ad2fe0a5918baa3edb6fd7 Mon Sep 17 00:00:00 2001
From: Lynne <>
Date: Wed, 19 Sep 2018 20:14:39 +0200
Subject: [PATCH 2/5] Change currency in emails.
---
emails/declined | 2 +-
emails/thank-you | 4 ++--
fosspay/email.py | 5 +++--
3 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/emails/declined b/emails/declined
index 7cf6fdc..777baec 100644
--- a/emails/declined
+++ b/emails/declined
@@ -1,5 +1,5 @@
An attempt was just made to charge your card for your monthly donation to
-{{your_name}} for ${{amount}}. Unfortunately, your card was declined.
+{{your_name}} for {{amount}}. Unfortunately, your card was declined.
The donation has been disabled. If you would like to, you may create a new
recurring donation here:
diff --git a/emails/thank-you b/emails/thank-you
index 6d45485..7e1e8a9 100644
--- a/emails/thank-you
+++ b/emails/thank-you
@@ -3,10 +3,10 @@ Thank you for donating!
Receipt:
{{#monthly}}
-Monthly donation ${{amount}}
+Monthly donation {{amount}}
{{/monthly}}
{{^monthly}}
-One-time donation ${{amount}}
+One-time donation {{amount}}
{{/monthly}}
You can view and manage your donations online here:
diff --git a/fosspay/email.py b/fosspay/email.py
index 78601b0..96b21b2 100644
--- a/fosspay/email.py
+++ b/fosspay/email.py
@@ -10,6 +10,7 @@ from flask import url_for
from fosspay.database import db
from fosspay.objects import User
from fosspay.config import _cfg, _cfgi
+from fosspay.currency import currency
def send_thank_you(user, amount, monthly):
if _cfg("smtp-host") == "":
@@ -24,7 +25,7 @@ def send_thank_you(user, amount, monthly):
"user": user,
"root": _cfg("protocol") + "://" + _cfg("domain"),
"your_name": _cfg("your-name"),
- "amount": "{:.2f}".format(amount / 100),
+ "amount": currency.amount("{:.2f}".format(amount / 100)),
"monthly": monthly,
"your_email": _cfg("your-email")
})))
@@ -70,7 +71,7 @@ def send_declined(user, amount):
"user": user,
"root": _cfg("protocol") + "://" + _cfg("domain"),
"your_name": _cfg("your-name"),
- "amount": "{:.2f}".format(amount / 100)
+ "amount": currency.amount("{:.2f}".format(amount / 100))
})))
message['Subject'] = "Your monthly donation was declined."
message['From'] = _cfg("smtp-from")
From 0a1b3603471dbeb0b8350fdd06ce216bcaf741fe Mon Sep 17 00:00:00 2001
From: Lynne <>
Date: Wed, 19 Sep 2018 20:29:23 +0200
Subject: [PATCH 3/5] Change default config file for dynamic currency system
---
config.ini.example | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/config.ini.example b/config.ini.example
index e945675..574425a 100644
--- a/config.ini.example
+++ b/config.ini.example
@@ -31,6 +31,11 @@ connection-string=postgresql://postgres@localhost/fosspay
stripe-secret=
stripe-publish=
+# Currency to use
+# "usd" for dollar, "eur" for euro
+# refer to stripe documentation for details : https://stripe.com/docs/currencies
+currency=usd
+
# Separate with spaces
default-amounts=3 5 10 20
# Which one to pick when they arrive?
From 456d97225eb018c09aab030cc2760d3949f82280 Mon Sep 17 00:00:00 2001
From: emy {{ donation.created.strftime("%Y-%m-%d") }}
- ${{ "{:.2f}".format(donation.amount / 100) }}
+ {{ currency.amount("{:.2f}".format(donation.amount / 100)) }}
{{ donation.project.name if donation.project else "Not specified" }}
{% endfor %}
{{ project.name }}
- {{ "{:.2f}".format(one_times(project) / 100) }}€
- {{ "{:.2f}".format(recurring(project) / 100) }}€
- {{ "{:.2f}".format(recurring_ever(project) / 100) }}€
+ {{ currency.amount("{:.2f}".format(one_times(project) / 100)) }}
+ {{ currency.amount("{:.2f}".format(recurring(project) / 100)) }}
+ {{ currency.amount("{:.2f}".format(recurring_ever(project) / 100)) }}
(non précisé)
- {{ "{:.2f}".format(unspecified_one_times / 100) }}€
- {{ "{:.2f}".format(unspecified_recurring / 100) }}€
- {{ "{:.2f}".format(unspecified_recurring_ever / 100) }}€
+ {{ currency.amount("{:.2f}".format(unspecified_one_times / 100)) }}
+ {{ currency.amount("{:.2f}".format(unspecified_recurring / 100)) }}
+ {{ currency.amount("{:.2f}".format(unspecified_recurring_ever / 100)) }}
@@ -117,7 +117,7 @@
Total
- {{ "{:.2f}".format(total_one_time / 100) }}€
- {{ "{:.2f}".format(total_recurring / 100) }}€
- {{ "{:.2f}".format(total_recurring_ever / 100) }}€
+ {{ currency.amount("{:.2f}".format(total_one_time / 100)) }}
+ {{ currency.amount("{:.2f}".format(total_recurring / 100)) }}
+ {{ currency.amount("{:.2f}".format(total_recurring_ever / 100)) }}
{{ donation.user.email }}
{{ donation.project.name if donation.project else "" }}
{{ donation.comment if donation.comment else "" }}
- {{ "{:.2f}".format(donation.amount / 100) }}€
+ {{ currency.amount("{:.2f}".format(donation.amount / 100)) }}
{{ "Unique" if str(donation.type) == "DonationType.one_time" else "Mensuel" }}
{{ "(cancelled)" if not donation.active else "" }}
diff --git a/contrib/fr/overrides/goal.html b/contrib/fr/overrides/goal.html
index bd464fb..deed792 100644
--- a/contrib/fr/overrides/goal.html
+++ b/contrib/fr/overrides/goal.html
@@ -23,21 +23,21 @@
class="progress-bar progress-bar-primary"
style="width: {{ recurring_progress * 100 }}%; line-height: 2.5"
>
- {{ "{:.0f}".format(recurring_sum / 100) }}€
+ {{ currency.amount("{:.0f}".format(recurring_sum / 100)) }}
{% endif %}
@@ -47,13 +47,13 @@
{{ donation.created.strftime("%d-%m-%Y") }}
- {{ "{:.2f}".format(donation.amount / 100) }}€
+ {{ currency.amount("{:.2f}".format(donation.amount / 100)) }}
{{ donation.project.name if donation.project else "Non précisé" }}
{% endfor %}
@@ -51,7 +51,7 @@
{% for donation in one_times(user) %}
{% endfor %}
diff --git a/templates/goal.html b/templates/goal.html
index b98c514..e433617 100644
--- a/templates/goal.html
+++ b/templates/goal.html
@@ -83,7 +83,7 @@
{{ donation.created.strftime("%d-%m-%Y") }}
- {{ "{:.2f}".format(donation.amount / 100) }}€
+ {{ currency.amount("{:.2f}".format(donation.amount / 100)) }}
{{ donation.project.name if donation.project else "Non précisé" }}
- Supported with ${{ currency.amount("{:.2f}".format(total_sum / 100)) }} + Supported with {{ currency.amount("{:.2f}".format(total_sum / 100)) }} from {{ total_count }} supporters!
{% endif %} diff --git a/templates/index.html b/templates/index.html index 20882fd..e843931 100644 --- a/templates/index.html +++ b/templates/index.html @@ -15,6 +15,8 @@ const i18n = { "Submitting...": "Submitting...", "Donate": "Donate" }; +// End of translation of index.js + const currency = "{{ _cfg("currency") }}"; {% if user %} From e7da56aaac052f175fc100586bf508a367b84b58 Mon Sep 17 00:00:00 2001 From: emy