Start fleshing out donations panel

master
Drew DeVault 9 years ago
parent 86ca065ab3
commit 76aae6d57e
  1. 14
      fosspay/blueprints/html.py
  2. 2
      fosspay/objects.py
  3. 174
      templates/admin.html
  4. 2
      templates/index.html
  5. 32
      templates/panel.html

@ -57,9 +57,9 @@ def admin():
first=first,
projects=projects,
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.recurring]),
recurring=lambda p: sum([d.amount for d in p.donations if d.type == DonationType.monthly]),
unspecified_one_times=sum([d.amount for d in unspecified if d.type == DonationType.one_time]),
unspecified_recurring=sum([d.amount for d in unspecified if d.type == DonationType.recurring])
unspecified_recurring=sum([d.amount for d in unspecified if d.type == DonationType.monthly])
)
@html.route("/create-project", methods=["POST"])
@ -73,6 +73,10 @@ def create_project():
@html.route("/login", methods=["GET", "POST"])
def login():
if current_user:
if current_user.admin:
return redirect("/admin")
return redirect("/panel")
if request.method == "GET":
return render_template("login.html")
email = request.form.get("email")
@ -85,6 +89,8 @@ def login():
if not bcrypt.hashpw(password.encode('UTF-8'), user.password.encode('UTF-8')) == user.password.encode('UTF-8'):
return render_template("login.html", errors=True)
login_user(user)
if user.admin:
return redirect("/admin")
return redirect("/")
@html.route("/logout")
@ -187,4 +193,6 @@ def reset_password(token):
@html.route("/panel")
@loginrequired
def panel():
return render_template("panel.html")
return render_template("panel.html",
one_times=lambda u: [d for d in u.donations if d.type == DonationType.one_time],
recurring=lambda u: next(d for d in u.donations if d.type == DonationType.recurring))

@ -73,7 +73,7 @@ class Donation(Base):
return "<Donation {} from {}: ${} ({})>".format(
self.id,
self.user.email,
self.amount,
"{:.2f}".format(self.amount / 100),
self.type
)

@ -2,91 +2,101 @@
{% block title %}
<title>Donation Admin</title>
{% endblock %}
{% block container %}
<a href="/logout" class="pull-right">Log out</a>
<h1>Fosspay Admin</h1>
{% if first %}
{% block body %}
<div class="well">
<p>
You're set up and ready to go! This is your admin panel.
Yeah, it's not pretty. Next steps:
</p>
<ol>
<li>
Set up a cron job to handle monthly donations. <a href="https://github.com/SirCmpwn/fosspay/wiki/Recurring-donations-cronjob">Relevant documentation</a>.
</li>
<li>
Add some projects. Donors can tell you which project they want to support
when they donate.
</li>
<li>
Customize the look &amp; feel. Look at the contents of the <code>templates</code>
directory - you can copy and paste any of these templates into the
<code>overrides</code> directory and change it to suit your needs.
</li>
<li>
<a href="https://drewdevault.com/donate?project=fosspay">Donate to fosspay upstream</a>?
</li>
<li>
<a href="https://github.com/SirCmpwn/fosspay">Contribute code to fosspay upstream</a>?
</li>
</ol>
<div class="container">
<p class="pull-right">
<a class="btn btn-default" href="logout">Log Out</a>
</p>
<h1>Donation Admin</h1>
</div>
</div>
{% endif %}
<h2>Projects</h2>
<div class="row">
<div class="col-md-6">
<table class="table">
<thead>
<tr>
<th style="width: 10%"></th>
<th>Project Name</th>
<th>One-time</th>
<th>Recurring</th>
<th>README Button</th>
</tr>
</thead>
<tbody>
{% for project in projects %}
<tr>
<td><button type="button" class="close">&times;</button></td>
<td>{{ project.name }}</td>
<td>${{ one_times(project) }}</td>
<td>${{ recurring(project) }}</td>
<td><a href="#" class="btn btn-primary btn-sm">Get Markdown</a></td>
</tr>
{% endfor %}
<tr>
<td></td>
<td>(not specified)</td>
<td>${{ unspecified_one_times }}</td>
<td>${{ unspecified_recurring }}</td>
<td></td>
</tr>
</tbody>
</table>
<div class="container">
{% if first %}
<div class="well">
<p>
You're set up and ready to go! This is your admin panel. Next steps:
</p>
<ol>
<li>
<strong>Set up a cron job to handle monthly donations.</strong>
<a href="https://github.com/SirCmpwn/fosspay/wiki/Recurring-donations-cronjob">
Relevant documentation
</a>.
</li>
<li>
Add some projects. Donors can tell you which project they want to support
when they donate.
</li>
<li>
Customize the look &amp; feel. Look at the contents of the <code>templates</code>
directory - you can copy and paste any of these templates into the
<code>overrides</code> directory and change it to suit your needs.
</li>
<li>
<a href="https://drewdevault.com/donate?project=fosspay">Donate to fosspay upstream</a>?
</li>
<li>
<a href="https://github.com/SirCmpwn/fosspay">Contribute code to fosspay upstream</a>?
</li>
</ol>
</div>
<div class="col-md-6 well">
<h4>Add Project</h4>
<p>Donors will not be given a choice of project unless you have at least 2.</p>
<form method="POST" action="/create-project">
<div class="form-group">
<input class="form-control" type="text" placeholder="Project name" name="name" />
</div>
<input type="submit" value="Add" class="btn btn-default pull-right" />
</form>
{% endif %}
<h2>Projects</h2>
<div class="row">
<div class="col-md-6">
<table class="table">
<thead>
<tr>
<th style="width: 10%"></th>
<th>Project Name</th>
<th>One-time</th>
<th>Recurring</th>
<th>README Button</th>
</tr>
</thead>
<tbody>
{% for project in projects %}
<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><a href="#" class="btn btn-primary btn-sm">Get Markdown</a></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></td>
</tr>
</tbody>
</table>
</div>
<div class="col-md-6 well">
<h4>Add Project</h4>
<p>Donors will not be given a choice of project unless you have at least 2.</p>
<form method="POST" action="/create-project">
<div class="form-group">
<input class="form-control" type="text" placeholder="Project name" name="name" />
</div>
<input type="submit" value="Add" class="btn btn-default pull-right" />
</form>
</div>
</div>
<h2>Donation History</h2>
<table class="table">
<thead>
<tr>
<th>Email</th>
<th>Project</th>
<th>Comment</th>
<th>Amount</th>
<th style="width: 10%">Recurring</th>
</tr>
</thead>
</table>
</div>
<h2>Donation History</h2>
<table class="table">
<thead>
<tr>
<th>Email</th>
<th>Project</th>
<th>Comment</th>
<th>Amount</th>
<th style="width: 10%">Recurring</th>
</tr>
</thead>
</table>
{% endblock %}

@ -140,7 +140,7 @@ window.default_type = "{{ _cfg("default-type") }}";
<div class="container text-center">
<p>
<small class="text-muted">
Been here before? <a href="/login">Log in</a> to view your donation
Been here before? <a href="login">Log in</a> to view your donation
history, edit recurring donations, and so on.
</small>
</p>

@ -0,0 +1,32 @@
{% extends "layout.html" %}
{% block body %}
<div class="well">
<div class="container">
<p class="pull-right">
<a class="btn btn-primary" href="..">Donate Again</a>
<a class="btn btn-default" href="logout">Log Out</a>
</p>
<h1>Your Donations</h1>
</div>
</div>
<div class="container">
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Amount</th>
<th>Project</th>
</tr>
</thead>
<tbody>
{% for donation in one_times(user) %}
<tr>
<td>{{ donation.created.strftime("%Y-%m-%d") }}</td>
<td>${{ "{:.2f}".format(donation.amount / 100) }}</td>
<td>{{ donation.project.name if donation.project else "Not specified" }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}
Loading…
Cancel
Save