From 76aae6d57e16c4564a8427bf9dd7957029c93d57 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sun, 6 Sep 2015 13:39:50 -0400 Subject: [PATCH] Start fleshing out donations panel --- fosspay/blueprints/html.py | 14 ++- fosspay/objects.py | 2 +- templates/admin.html | 174 ++++++++++++++++++++----------------- templates/index.html | 2 +- templates/panel.html | 32 +++++++ 5 files changed, 137 insertions(+), 87 deletions(-) create mode 100644 templates/panel.html diff --git a/fosspay/blueprints/html.py b/fosspay/blueprints/html.py index 7b128bf..48bd5b4 100644 --- a/fosspay/blueprints/html.py +++ b/fosspay/blueprints/html.py @@ -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)) diff --git a/fosspay/objects.py b/fosspay/objects.py index 5677895..45506c2 100644 --- a/fosspay/objects.py +++ b/fosspay/objects.py @@ -73,7 +73,7 @@ class Donation(Base): return "".format( self.id, self.user.email, - self.amount, + "{:.2f}".format(self.amount / 100), self.type ) diff --git a/templates/admin.html b/templates/admin.html index b7d25ce..7a75359 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -2,91 +2,101 @@ {% block title %} Donation Admin {% endblock %} -{% block container %} -Log out -

Fosspay Admin

-{% if first %} +{% block body %}
-

- You're set up and ready to go! This is your admin panel. - Yeah, it's not pretty. Next steps: -

-
    -
  1. - Set up a cron job to handle monthly donations. Relevant documentation. -
  2. -
  3. - Add some projects. Donors can tell you which project they want to support - when they donate. -
  4. -
  5. - Customize the look & feel. Look at the contents of the templates - directory - you can copy and paste any of these templates into the - overrides directory and change it to suit your needs. -
  6. -
  7. - Donate to fosspay upstream? -
  8. -
  9. - Contribute code to fosspay upstream? -
  10. -
+
+

+ Log Out +

+

Donation Admin

+
-{% endif %} -

Projects

-
-
- - - - - - - - - - - - {% for project in projects %} - - - - - - - - {% endfor %} - - - - - - - - -
Project NameOne-timeRecurringREADME Button
{{ project.name }}${{ one_times(project) }}${{ recurring(project) }}Get Markdown
(not specified)${{ unspecified_one_times }}${{ unspecified_recurring }}
+
+ {% if first %} +
+

+ You're set up and ready to go! This is your admin panel. Next steps: +

+
    +
  1. + Set up a cron job to handle monthly donations. + + Relevant documentation + . +
  2. +
  3. + Add some projects. Donors can tell you which project they want to support + when they donate. +
  4. +
  5. + Customize the look & feel. Look at the contents of the templates + directory - you can copy and paste any of these templates into the + overrides directory and change it to suit your needs. +
  6. +
  7. + Donate to fosspay upstream? +
  8. +
  9. + Contribute code to fosspay upstream? +
  10. +
-
-

Add Project

-

Donors will not be given a choice of project unless you have at least 2.

-
-
- -
- -
+ {% endif %} +

Projects

+
+
+ + + + + + + + + + + + {% for project in projects %} + + + + + + + + {% endfor %} + + + + + + + + +
Project NameOne-timeRecurringREADME Button
{{ project.name }}${{ "{:.2f}".format(one_times(project) / 100) }}${{ "{:.2f}".format(recurring(project) / 100) }}Get Markdown
(not specified)${{ "{:.2f}".format(unspecified_one_times / 100) }}${{ "{:.2f}".format(unspecified_recurring / 100) }}
+
+
+

Add Project

+

Donors will not be given a choice of project unless you have at least 2.

+
+
+ +
+ +
+
+

Donation History

+ + + + + + + + + + +
EmailProjectCommentAmountRecurring
-

Donation History

- - - - - - - - - - -
EmailProjectCommentAmountRecurring
{% endblock %} diff --git a/templates/index.html b/templates/index.html index 99826a3..9e3b09e 100644 --- a/templates/index.html +++ b/templates/index.html @@ -140,7 +140,7 @@ window.default_type = "{{ _cfg("default-type") }}";

- Been here before? Log in to view your donation + Been here before? Log in to view your donation history, edit recurring donations, and so on.

diff --git a/templates/panel.html b/templates/panel.html new file mode 100644 index 0000000..8e9d035 --- /dev/null +++ b/templates/panel.html @@ -0,0 +1,32 @@ +{% extends "layout.html" %} +{% block body %} +
+
+

+ Donate Again + Log Out +

+

Your Donations

+
+
+
+ + + + + + + + + + {% for donation in one_times(user) %} + + + + + + {% endfor %} + +
DateAmountProject
{{ donation.created.strftime("%Y-%m-%d") }}${{ "{:.2f}".format(donation.amount / 100) }}{{ donation.project.name if donation.project else "Not specified" }}
+
+{% endblock %}