Add goals and Patreon integration
This commit is contained in:
parent
6c9318c7b6
commit
0f628d23fc
|
@ -39,3 +39,16 @@ default-amount=10
|
||||||
|
|
||||||
# Pick between "monthly" and "once"
|
# Pick between "monthly" and "once"
|
||||||
default-type=monthly
|
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=
|
||||||
|
|
|
@ -75,5 +75,6 @@ def inject():
|
||||||
'_cfg': _cfg,
|
'_cfg': _cfg,
|
||||||
'_cfgi': _cfgi,
|
'_cfgi': _cfgi,
|
||||||
'debug': app.debug,
|
'debug': app.debug,
|
||||||
'str': str
|
'str': str,
|
||||||
|
'int': int
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,34 @@ def index():
|
||||||
selected_project = int(selected_project)
|
selected_project = int(selected_project)
|
||||||
except:
|
except:
|
||||||
selected_project = None
|
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,
|
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"])
|
@html.route("/setup", methods=["POST"])
|
||||||
def setup():
|
def setup():
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
{#
|
||||||
|
This is a little blurb you can write to explain why your goal is set to what
|
||||||
|
it is.
|
||||||
|
#}
|
|
@ -0,0 +1,71 @@
|
||||||
|
{% if _cfg("public-income") == "yes" %}
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-8 col-md-offset-2">
|
||||||
|
<hr />
|
||||||
|
{% set total_sum = recurring_sum + patreon_sum %}
|
||||||
|
{% set total_count = recurring_count + patreon_count %}
|
||||||
|
{% if _cfg("goal") %}
|
||||||
|
<h3 class="text-center">Goal</h3>
|
||||||
|
{% set goal = int(_cfg("goal")) %}
|
||||||
|
{% set recurring_progress = recurring_sum / goal %}
|
||||||
|
{% set patreon_progress = patreon_sum / goal %}
|
||||||
|
{% set progress = total_sum / goal %}
|
||||||
|
<div class="progress" style="height: 3rem">
|
||||||
|
<div
|
||||||
|
class="progress-bar progress-bar-primary"
|
||||||
|
style="width: {{ recurring_progress * 100 }}%; line-height: 2.5"
|
||||||
|
>
|
||||||
|
<span>${{ "{:.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>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4 col-md-offset-4">
|
||||||
|
{% if patreon_count %}
|
||||||
|
<p>
|
||||||
|
${{ "{:.2f}".format(recurring_sum / 100) }}/mo
|
||||||
|
via <strong class="text-primary">{{ domain }}</strong>
|
||||||
|
({{ recurring_count }} supporter{{ "s" if recurring_count != 1 else "" }})
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
${{ "{:.2f}".format(patreon_sum / 100) }}/mo
|
||||||
|
via
|
||||||
|
<strong><a
|
||||||
|
href="https://patreon.com/{{ _cfg("patreon-campaign") }}"
|
||||||
|
style="color: #51acc7">
|
||||||
|
Patreon <i class="glyphicon glyphicon-share"></i>
|
||||||
|
</a></strong> ({{ patreon_count }} supporter{{ "s" if patreon_count != 1 else "" }})
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
{% if goal %}
|
||||||
|
<p class="{{ "text-center" if not patreon_sum else "" }}">
|
||||||
|
${{ "{:.2f}".format(total_sum / 100)}}/mo
|
||||||
|
of
|
||||||
|
${{ "{:.2f}".format(goal / 100) }}/mo
|
||||||
|
goal
|
||||||
|
</p>
|
||||||
|
{% else %}
|
||||||
|
<p>
|
||||||
|
Supported with ${{ "{:.2f}".format(total_sum / 100) }}
|
||||||
|
from {{ total_count }} supporters!
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6 col-md-offset-3">
|
||||||
|
{% include "goal-summary.html" %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
|
@ -130,7 +130,7 @@ window.email = "{{user.email}}";
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row" style="margin-top: 50px">
|
<div class="row">
|
||||||
<div class="col-md-4 col-md-offset-4">
|
<div class="col-md-4 col-md-offset-4">
|
||||||
<div class="alert alert-danger hidden" id="errors">
|
<div class="alert alert-danger hidden" id="errors">
|
||||||
<p></p>
|
<p></p>
|
||||||
|
@ -139,6 +139,7 @@ window.email = "{{user.email}}";
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% include "goal.html" %}
|
||||||
<hr />
|
<hr />
|
||||||
<div class="container text-center">
|
<div class="container text-center">
|
||||||
{% if not user %}
|
{% if not user %}
|
||||||
|
|
|
@ -54,6 +54,20 @@
|
||||||
Your Stripe API keys look good.
|
Your Stripe API keys look good.
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
{% if not _cfg("patreon-access-token") or not _cfg("patreon-campaign") %}
|
||||||
|
<span class="glyphicon glyphicon-remove text-danger"></span>
|
||||||
|
Your Patreon access token and campaign are not configured (optional).
|
||||||
|
{% else %}
|
||||||
|
<span class="glyphicon glyphicon-ok text-success"></span>
|
||||||
|
Your Patreon integration looks good. We'll integrate with
|
||||||
|
<a
|
||||||
|
href="https://patreon.com/{{ _cfg("patreon-campaign") }}"
|
||||||
|
target="_blank" rel="noopener noreferrer"
|
||||||
|
>{{ _cfg("patreon-campaign") }}</a>'s campaign.
|
||||||
|
{% endif %}
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>You can make changes and refresh this page if you like.</p>
|
<p>You can make changes and refresh this page if you like.</p>
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,3 @@
|
||||||
the donation UI and will reduce the number of conversions you
|
the donation UI and will reduce the number of conversions you
|
||||||
actually get.
|
actually get.
|
||||||
#}
|
#}
|
||||||
|
|
||||||
<p>
|
|
||||||
As donations permit, I will take leave from my day job, a week at a time, to work on these projects.
|
|
||||||
</p>
|
|
||||||
|
|
Loading…
Reference in New Issue