Donation goal banner

This commit is contained in:
Jeremy Zhang 2019-10-12 22:36:37 -07:00
parent b0c9e6c5ec
commit 0ec0b52501
10 changed files with 182 additions and 7 deletions

View File

@ -0,0 +1,34 @@
"""Added application settings table with donation goal related columns
Revision ID: ecf3e6bf950e
Revises: ce2b9c930a7a
Create Date: 2019-10-12 21:26:27.092295
"""
# revision identifiers, used by Alembic.
revision = 'ecf3e6bf950e'
down_revision = 'ce2b9c930a7a'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('application_settings',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('donation_goal_progress', sa.Integer(), server_default='0', nullable=False),
sa.Column('donation_goal_total', sa.Integer(), server_default='0', nullable=False),
sa.Column('donation_goal_end', sa.Date(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('application_settings')
# ### end Alembic commands ###

View File

@ -17,10 +17,11 @@ from flask_sslify import SSLify
from titanembeds.utils import rate_limiter, discord_api, socketio, babel, redis_store, language_code_list#, sentry
from .blueprints import api, user, admin, embed, gateway
import os
from titanembeds.database import get_administrators_list
from titanembeds.database import get_administrators_list, init_application_settings, get_application_settings
import titanembeds.constants as constants
from datetime import timedelta
import datetime
import random
os.chdir(config['app-location'])
app = Flask(__name__, static_folder="static")
@ -84,11 +85,14 @@ def global_banned_words():
@app.before_first_request
def before_first_request():
init_application_settings()
discord_api.init_discordrest()
@app.context_processor
def context_processor():
return {
"random": random,
"application_settings": get_application_settings(),
"devs": get_administrators_list(),
"sentry_js_dsn": config.get("sentry-js-dsn", None),
"constants": constants,

View File

@ -1,7 +1,7 @@
from flask import Blueprint, url_for, redirect, session, render_template, abort, request, jsonify
from flask_socketio import emit
from functools import wraps
from titanembeds.database import db, get_administrators_list, Cosmetics, Guilds, UnauthenticatedUsers, UnauthenticatedBans, TitanTokens, TokenTransactions, get_titan_token, set_titan_token, list_disabled_guilds, DisabledGuilds, UserCSS, AuthenticatedUsers, DiscordBotsOrgTransactions
from titanembeds.database import db, get_administrators_list, Cosmetics, Guilds, UnauthenticatedUsers, UnauthenticatedBans, TitanTokens, TokenTransactions, get_titan_token, set_titan_token, list_disabled_guilds, DisabledGuilds, UserCSS, AuthenticatedUsers, DiscordBotsOrgTransactions, ApplicationSettings
from titanembeds.oauth import generate_guild_icon_url
from titanembeds.utils import get_online_embed_user_keys, redisqueue
import datetime
@ -497,4 +497,39 @@ def voting_get():
if gmember:
u["discord"] = gmember["username"] + "#" + str(gmember["discriminator"])
referrals.append(u)
return render_template("admin_voting.html.j2", overall=overall, referrals=referrals, datestart=datestart, timestart=timestart, dateend=dateend, timeend=timeend)
return render_template("admin_voting.html.j2", overall=overall, referrals=referrals, datestart=datestart, timestart=timestart, dateend=dateend, timeend=timeend)
@admin.route("/app_settings", methods=["GET"])
@is_admin
def application_settings_get():
settings = db.session.query(ApplicationSettings).first()
return render_template("admin_application_settings.html.j2", settings=settings)
@admin.route("/app_settings", methods=["POST"])
@is_admin
def application_settings_post():
settings = db.session.query(ApplicationSettings).first()
if "donation_goal_progress" in request.form:
donation_goal_progress = request.form.get("donation_goal_progress")
settings.donation_goal_progress = int(donation_goal_progress)
if "donation_goal_total" in request.form:
donation_goal_total = request.form.get("donation_goal_total")
settings.donation_goal_total = int(donation_goal_total)
if "donation_goal_end" in request.form:
res = None
donation_goal_end = request.form.get("donation_goal_end")
if donation_goal_end:
donation_goal_end = donation_goal_end.split("/")
month = int(donation_goal_end[0])
day = int(donation_goal_end[1])
year = int(donation_goal_end[2])
res = datetime.date(year, month, day)
settings.donation_goal_end = res
db.session.commit()
return jsonify({
"donation_goal_progress": settings.donation_goal_progress,
"donation_goal_total": settings.donation_goal_total,
"donation_goal_end": settings.donation_goal_end,
})

View File

@ -14,6 +14,7 @@ from .token_transactions import TokenTransactions
from .patreon import Patreon
from .disabled_guilds import DisabledGuilds, list_disabled_guilds
from .discordbotsorg_transactions import DiscordBotsOrgTransactions
from .application_settings import ApplicationSettings
def set_titan_token(user_id, amt_change, action):
token_count = get_titan_token(user_id)
@ -29,4 +30,14 @@ def set_titan_token(user_id, amt_change, action):
db.session.add(transact)
token_usr.tokens = new_token_count
db.session.add(token_usr)
return True
return True
def init_application_settings():
settings = db.session.query(ApplicationSettings).first()
if not settings:
settings = ApplicationSettings()
db.session.add(settings)
db.session.commit()
def get_application_settings():
return db.session.query(ApplicationSettings).first()

View File

@ -0,0 +1,13 @@
from titanembeds.database import db
class ApplicationSettings(db.Model):
__tablename__ = "application_settings"
id = db.Column(db.Integer, primary_key=True, nullable=False) # Auto increment id
donation_goal_progress = db.Column(db.Integer, nullable=False, server_default="0") # Current progress towards donation goal
donation_goal_total = db.Column(db.Integer, nullable=False, server_default="0") # Total donation required to hit goal. 0 to now show banners
donation_goal_end = db.Column(db.Date(), nullable=True) # When to end donation goal
def __init__(self):
self.donation_goal_progress = 0
self.donation_goal_total = 0
self.donation_goal_end = None

View File

@ -81,7 +81,7 @@ img.center-align {
padding-bottom: 0px;
}
#dblbanner {
#dblbanner, #donbanner {
background-color: darkblue;
text-align: center;
font-size: 12pt;
@ -90,11 +90,11 @@ img.center-align {
display: none;
}
#dblbanner a {
#dblbanner a, #donbanner a {
transition: font-size 0.5s;
color: lightskyblue;
}
#dblbanner a:hover {
#dblbanner a:hover, #donbanner a:hover {
font-size: 14pt;
}

View File

@ -0,0 +1,26 @@
function postForm(donation_goal_progress, donation_goal_total, donation_goal_end) {
var funct = $.ajax({
dataType: "json",
method: "POST",
data: {
"donation_goal_progress": donation_goal_progress,
"donation_goal_total": donation_goal_total,
"donation_goal_end": donation_goal_end
}
});
return funct.promise();
}
$("#submit").click(function () {
Materialize.toast("Saving changes...", 2000);
let donation_goal_progress = $("#donation_goal_progress").val();
let donation_goal_total = $("#donation_goal_total").val();
let donation_goal_end = $("#donation_goal_end").val();
let req = postForm(donation_goal_progress, donation_goal_total, donation_goal_end);
req.done(function () {
Materialize.toast("All changes saved!", 2000);
});
req.fail(function () {
Materialize.toast("There is an error saving changes.", 2000);
});
});

View File

@ -0,0 +1,30 @@
{% extends 'site_layout.html.j2' %}
{% set title="Manage Guilds as Administrator" %}
{% block content %}
<h1>Application Settings</h1>
<p class="flow-text">Manage Titan Embeds</p>
<div class="col s12">
<div class="card-panel indigo lighten-5 z-depth-3 hoverable">
<p class="black-text flow-text">Donation Goal</p>
<div class="row">
<div class="input-field col s12">
<input id="donation_goal_progress" type="number" class="black-text" value="{{ settings.donation_goal_progress }}">
<label for="donation_goal_progress">Current Goal Progress</label>
</div>
<div class="input-field col s12">
<input id="donation_goal_total" type="number" class="black-text" value="{{ settings.donation_goal_total }}">
<label for="donation_goal_total">Current Goal Total (set 0 to disable)</label>
</div>
<div class="input-field col s12">
<input id="donation_goal_end" type="text" class="black-text" {% if settings.donation_goal_end %}value="{{ settings.donation_goal_end.strftime('%m/%d/%Y') }}"{% endif %}>
<label for="donation_goal_end">Goal End Date (mm/dd/yyyy)</label>
</div>
</div>
<a class="waves-effect waves-light btn" id="submit">Submit</a>
</div>
</div>
{% endblock %}
{% block script %}
<script type="text/javascript" src="{{ url_for('static', filename='js/admin_application_settings.js') }}"></script>
{% endblock %}

View File

@ -56,5 +56,12 @@
<a class="waves-effect waves-light btn" href="{{ url_for('admin.get_disabled_guilds') }}">Manage</a>
</div>
</div>
<div class="col s12">
<div class="card-panel indigo lighten-5 z-depth-3 hoverable black-text">
<h4>Application Settings</h4>
<p class="flow-text">Configure Titan Embeds.</p>
<a class="waves-effect waves-light btn" href="{{ url_for('admin.application_settings_get') }}">Manage</a>
</div>
</div>
</div>
{% endblock %}

View File

@ -31,6 +31,7 @@
{% include 'google_analytics.html.j2' %}
</head>
<body>
{% if random.randrange(100) < 50 %}
<div id="dblbanner">
<span>
<strong>Hey!</strong> Upvote us on <a href="{{ url_for("vote") }}">Discord Bots List</a> to show your
@ -38,6 +39,17 @@
<span class="yellow-text">golden name</span></em> and rewards in return for your vote)
</span>
</div>
{% else %}
<div id="donbanner">
<span>
<strong>Hey! We need your help!</strong> Support the Titan Embeds project on <a href="http://patreon.com/TitanEmbeds" target="_blank">Patreon</a> to help us cover the cost of server hosting!
{% if application_settings.donation_goal_total %}
<br>
<strong>Goal: <span class="yellow-text">${{ application_settings.donation_goal_progress }} raised out of ${{ application_settings.donation_goal_total }}</span>{% if application_settings.donation_goal_end %} by {{ application_settings.donation_goal_end }}{% endif %}</strong>
{% endif %}
</span>
</div>
{% endif %}
<main>
{% if session['unauthenticated'] is defined and not session['unauthenticated'] %}
<ul id="menu_dropdown" class="dropdown-content">
@ -106,6 +118,9 @@
});
</script>
{% endif %}
<script>
$('#donbanner').delay(1000).slideDown("slow");
</script>
{% if af_mode_enabled %}
<script type="text/javascript" src="{{ url_for('static', filename='js/site.af.sausage.js') }}"></script>