From 0f628d23fc7fa517babca12fa88713d606e2d9ad Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 9 Dec 2017 11:43:32 -0500 Subject: [PATCH] Add goals and Patreon integration --- config.ini.example | 13 +++++++ fosspay/app.py | 3 +- fosspay/blueprints/html.py | 28 ++++++++++++++- templates/goal-summary.html | 4 +++ templates/goal.html | 71 +++++++++++++++++++++++++++++++++++++ templates/index.html | 3 +- templates/setup.html | 14 ++++++++ templates/summary.html | 4 --- 8 files changed, 133 insertions(+), 7 deletions(-) create mode 100644 templates/goal-summary.html create mode 100644 templates/goal.html diff --git a/config.ini.example b/config.ini.example index 20893d4..f2a0106 100644 --- a/config.ini.example +++ b/config.ini.example @@ -39,3 +39,16 @@ default-amount=10 # Pick between "monthly" and "once" default-type=monthly + +# Display monthly donations publically +public-income=yes + +# How much are you hoping to earn monthly, in cents +goal=500 + +# Optional Patreon integration +# Register a client here: https://www.patreon.com/portal/registration/register-clients +# And put in the "Creator's Access Token" here: +patreon-access-token= +# And the Patreon campaign you want to connect with: +patreon-campaign= diff --git a/fosspay/app.py b/fosspay/app.py index d50fe5a..5753235 100644 --- a/fosspay/app.py +++ b/fosspay/app.py @@ -75,5 +75,6 @@ def inject(): '_cfg': _cfg, '_cfgi': _cfgi, 'debug': app.debug, - 'str': str + 'str': str, + 'int': int } diff --git a/fosspay/blueprints/html.py b/fosspay/blueprints/html.py index c8abe81..bbd97a8 100644 --- a/fosspay/blueprints/html.py +++ b/fosspay/blueprints/html.py @@ -30,8 +30,34 @@ def index(): selected_project = int(selected_project) except: selected_project = None + active_recurring = (Donation.query + .filter(Donation.type == DonationType.monthly) + .filter(Donation.active == True)) + recurring_count = active_recurring.count() + recurring_sum = sum([d.amount for d in active_recurring]) + + access_token = _cfg("patreon-access-token") + campaign = _cfg("patreon-campaign") + if access_token and campaign: + import patreon + client = patreon.API(access_token) + campaign = client.fetch_campaign() + attrs = campaign.json_data["data"][0]["attributes"] + patreon_count = attrs["patron_count"] + patreon_sum = attrs["pledge_sum"] + else: + patreon_count = 0 + patreon_sum = 0 + + recurring_count = 1 + recurring_sum = 5000 + return render_template("index.html", projects=projects, - avatar=avatar, selected_project=selected_project) + avatar=avatar, selected_project=selected_project, + recurring_count=recurring_count, + recurring_sum=recurring_sum, + patreon_count=patreon_count, + patreon_sum=patreon_sum) @html.route("/setup", methods=["POST"]) def setup(): diff --git a/templates/goal-summary.html b/templates/goal-summary.html new file mode 100644 index 0000000..f472771 --- /dev/null +++ b/templates/goal-summary.html @@ -0,0 +1,4 @@ +{# + This is a little blurb you can write to explain why your goal is set to what + it is. +#} diff --git a/templates/goal.html b/templates/goal.html new file mode 100644 index 0000000..02c830e --- /dev/null +++ b/templates/goal.html @@ -0,0 +1,71 @@ +{% if _cfg("public-income") == "yes" %} +
+
+
+
+ {% set total_sum = recurring_sum + patreon_sum %} + {% set total_count = recurring_count + patreon_count %} + {% if _cfg("goal") %} +

Goal

+ {% set goal = int(_cfg("goal")) %} + {% set recurring_progress = recurring_sum / goal %} + {% set patreon_progress = patreon_sum / goal %} + {% set progress = total_sum / goal %} +
+
+ ${{ "{:.0f}".format(recurring_sum / 100) }} +
+ +
+ ${{ "{:.0f}".format(patreon_sum / 100) }} +
+
+ {% endif %} +
+
+
+
+ {% if patreon_count %} +

+ ${{ "{:.2f}".format(recurring_sum / 100) }}/mo + via {{ domain }} + ({{ recurring_count }} supporter{{ "s" if recurring_count != 1 else "" }}) +

+

+ ${{ "{:.2f}".format(patreon_sum / 100) }}/mo + via + + Patreon + ({{ patreon_count }} supporter{{ "s" if patreon_count != 1 else "" }}) +

+ {% endif %} + {% if goal %} +

+ ${{ "{:.2f}".format(total_sum / 100)}}/mo + of + ${{ "{:.2f}".format(goal / 100) }}/mo + goal +

+ {% else %} +

+ Supported with ${{ "{:.2f}".format(total_sum / 100) }} + from {{ total_count }} supporters! +

+ {% endif %} +
+
+
+
+ {% include "goal-summary.html" %} +
+
+
+{% endif %} diff --git a/templates/index.html b/templates/index.html index 9b67e86..c9e0284 100644 --- a/templates/index.html +++ b/templates/index.html @@ -130,7 +130,7 @@ window.email = "{{user.email}}"; -
+
+{% include "goal.html" %}
{% if not user %} diff --git a/templates/setup.html b/templates/setup.html index fb969ff..ceef789 100644 --- a/templates/setup.html +++ b/templates/setup.html @@ -54,6 +54,20 @@ Your Stripe API keys look good. {% endif %} + +
  • + {% if not _cfg("patreon-access-token") or not _cfg("patreon-campaign") %} + + Your Patreon access token and campaign are not configured (optional). + {% else %} + + Your Patreon integration looks good. We'll integrate with + {{ _cfg("patreon-campaign") }}'s campaign. + {% endif %} +
  • You can make changes and refresh this page if you like.

    diff --git a/templates/summary.html b/templates/summary.html index ab9a7e2..0ff4baf 100644 --- a/templates/summary.html +++ b/templates/summary.html @@ -3,7 +3,3 @@ the donation UI and will reduce the number of conversions you actually get. #} - -

    -As donations permit, I will take leave from my day job, a week at a time, to work on these projects. -