Browse Source

Add a dynamic currency system.

master
Lynne 3 years ago
parent
commit
ee022f032d
  1. 9
      fosspay/blueprints/html.py
  2. 21
      fosspay/currency.py
  3. 1
      scripts/index.js
  4. 20
      templates/admin.html
  5. 18
      templates/goal.html
  6. 5
      templates/index.html
  7. 4
      templates/panel.html

9
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/<id>")
@loginrequired

21
fosspay/currency.py

@ -0,0 +1,21 @@
from fosspay.config import _cfg
class Currency:
def __init__(self, symbol, position):
self.symbol = symbol
self.position = position
def amount(self, amount):
if self.position == "right":
return amount + self.symbol
else:
return self.symbol + amount
currencies = {
'usd' : Currency("$", "left"),
'eur' : Currency("", "right")
# ... More currencies can be added here
}
currency = currencies[_cfg("currency")]

1
scripts/index.js

@ -78,6 +78,7 @@
description: donation.type == "monthly" ? i18n["Monthly Donation"] : i18n["One-time Donation"],
panelLabel: i18n["Donate "] + "{{amount}}",
amount: donation.amount,
currency: currency,
token: function(token) {
e.target.setAttribute("disabled", "");
e.target.textContent = i18n["Submitting..."];

20
templates/admin.html

@ -65,24 +65,24 @@
<tr>
<td><button type="button" class="close">&times;</button></td>
<td>{{ project.name }}</td>
<td>${{ "{:.2f}".format(one_times(project) / 100) }}</td>
<td>${{ "{:.2f}".format(recurring(project) / 100) }}</td>
<td>${{ "{:.2f}".format(recurring_ever(project) / 100) }}</td>
<td>{{ currency.amount("{:.2f}".format(one_times(project) / 100)) }}</td>
<td>{{ currency.amount("{:.2f}".format(recurring(project) / 100)) }}</td>
<td>{{ currency.amount("{:.2f}".format(recurring_ever(project) / 100)) }}</td>
</tr>
{% endfor %}
<tr>
<td></td>
<td>(not specified)</td>
<td>${{ "{:.2f}".format(unspecified_one_times / 100) }}</td>
<td>${{ "{:.2f}".format(unspecified_recurring / 100) }}</td>
<td>${{ "{:.2f}".format(unspecified_recurring_ever / 100) }}</td>
<td>{{ currency.amount("{:.2f}".format(unspecified_one_times / 100)) }}</td>
<td>{{ currency.amount("{:.2f}".format(unspecified_recurring / 100)) }}</td>
<td>{{ currency.amount("{:.2f}".format(unspecified_recurring_ever / 100)) }}</td>
</tr>
<tr>
<td></td>
<td><strong>Total</strong></td>
<td>${{ "{:.2f}".format(total_one_time / 100) }}</td>
<td>${{ "{:.2f}".format(total_recurring / 100) }}</td>
<td>${{ "{:.2f}".format(total_recurring_ever / 100) }}</td>
<td>{{ currency.amount("{:.2f}".format(total_one_time / 100)) }}</td>
<td>{{ currency.amount("{:.2f}".format(total_recurring / 100)) }}</td>
<td>{{ currency.amount("{:.2f}".format(total_recurring_ever / 100)) }}</td>
</tr>
</tbody>
</table>
@ -118,7 +118,7 @@
<td><a href="mailto:{{ donation.user.email }}">{{ donation.user.email }}</a></td>
<td>{{ donation.project.name if donation.project else "" }}</td>
<td title="{{ donation.comment }}">{{ donation.comment if donation.comment else "" }}</td>
<td>${{ "{:.2f}".format(donation.amount / 100) }}</td>
<td>{{ currency.amount("{:.2f}".format(donation.amount / 100)) }}</td>
<td>
{{ "Once" if str(donation.type) == "DonationType.one_time" else "Monthly" }}
{{ "(cancelled)" if not donation.active else "" }}

18
templates/goal.html

@ -23,21 +23,21 @@
class="progress-bar progress-bar-primary"
style="width: {{ recurring_progress * 100 }}%; line-height: 2.5"
>
<span>${{ "{:.0f}".format(recurring_sum / 100) }}</span>
<span>{{ currency.amount("{:.0f}".format(recurring_sum / 100)) }}</span>
</div>
<div
class="progress-bar progress-bar-info"
style="width: {{ patreon_progress * 100 }}%; line-height: 2.5"
>
<span>${{ "{:.0f}".format(patreon_sum / 100) }}</span>
<span>{{ currency.amount("{:.0f}".format(patreon_sum / 100)) }}</span>
</div>
<div
class="progress-bar progress-bar-warning"
style="width: {{ lp_progress * 100 }}%; line-height: 2.5"
>
<span>${{ "{:.0f}".format(lp_sum / 100) }}</span>
<span>{{ currency.amount("{:.0f}".format(lp_sum / 100)) }}</span>
</div>
</div>
{% endif %}
@ -47,13 +47,13 @@
<div class="col-md-6 col-md-offset-3">
{% if patreon_count or lp_count %}
<p>
${{ "{:.2f}".format(recurring_sum / 100) }}/mo
{{ currency.amount("{:.2f}".format(recurring_sum / 100)) }}/mo
via <strong class="text-primary">{{ domain }}</strong>
({{ recurring_count }} supporter{{ "s" if recurring_count != 1 else "" }})
</p>
{% if patreon_count %}
<p>
${{ "{:.2f}".format(patreon_sum / 100) }}/mo
{{ currency.amount("{:.2f}".format(patreon_sum / 100)) }}/mo
via
<strong><a
href="https://patreon.com/{{ _cfg("patreon-campaign") }}"
@ -64,7 +64,7 @@
{% endif %}
{% if lp_count %}
<p>
${{ "{:.2f}".format(lp_sum / 100) }}/mo
{{ currency.amount("{:.2f}".format(lp_sum / 100)) }}/mo
via
<strong><a
class="text-warning"
@ -76,14 +76,14 @@
{% endif %}
{% if goal %}
<p class="{{ "text-center" if not patreon_sum else "" }}">
${{ "{:.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
</p>
{% else %}
<p>
Supported with ${{ "{:.2f}".format(total_sum / 100) }}
Supported with ${{ currency.amount("{:.2f}".format(total_sum / 100)) }}
from {{ total_count }} supporters!
</p>
{% endif %}

5
templates/index.html

@ -15,6 +15,7 @@ const i18n = {
"Submitting...": "Submitting...",
"Donate": "Donate"
};
const currency = "{{ _cfg("currency") }}";
{% if user %}
window.email = "{{user.email}}";
@ -65,7 +66,7 @@ window.email = "{{user.email}}";
<div class="btn-group" role="group">
<button data-amount="{{ amt }}" type="button"
class="btn btn-default {{"active" if _cfg("default-amount") == amt else ""}}"
>${{ amt }}</button>
>{{ currency.amount(amt) }}</button>
</div>
{% endfor %}
<div class="btn-group" role="group">
@ -78,7 +79,7 @@ window.email = "{{user.email}}";
<div class="col-md-4 col-md-offset-4">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon">$</span>
<span class="input-group-addon">{{ currency.symbol }}</span>
<input id="custom-amount-text" type="text" value="13.37"
class="form-control" placeholder="Amount" />
</div>

4
templates/panel.html

@ -30,7 +30,7 @@
</form>
</td>
<td>{{ donation.created.strftime("%Y-%m-%d") }}</td>
<td>${{ "{:.2f}".format(donation.amount / 100) }}</td>
<td>{{ currency.amount("{:.2f}".format(donation.amount / 100)) }}</td>
<td>{{ donation.project.name if donation.project else "Not specified" }}</td>
</tr>
{% endfor %}
@ -51,7 +51,7 @@
{% for donation in one_times(user) %}
<tr>
<td>{{ donation.created.strftime("%Y-%m-%d") }}</td>
<td>${{ "{:.2f}".format(donation.amount / 100) }}</td>
<td>{{ currency.amount("{:.2f}".format(donation.amount / 100)) }}</td>
<td>{{ donation.project.name if donation.project else "Not specified" }}</td>
</tr>
{% endfor %}

Loading…
Cancel
Save