Fix a few stuff in dashboard

This commit is contained in:
Jeremy Zhang 2017-03-25 21:14:42 -07:00
parent 53c06ed050
commit 3e884fa2fa
5 changed files with 18 additions and 5 deletions

View File

@ -4,6 +4,7 @@ from flask import Flask, render_template, request, session, url_for, redirect, j
from titanembeds.utils import cache from titanembeds.utils import cache
import blueprints.api import blueprints.api
import blueprints.user import blueprints.user
import blueprints.embed
import os import os
@ -18,6 +19,7 @@ cache.init_app(app, config={'CACHE_TYPE': 'simple'})
app.register_blueprint(blueprints.api.api, url_prefix="/api", template_folder="/templates") app.register_blueprint(blueprints.api.api, url_prefix="/api", template_folder="/templates")
app.register_blueprint(blueprints.user.user, url_prefix="/user", template_folder="/templates") app.register_blueprint(blueprints.user.user, url_prefix="/user", template_folder="/templates")
app.register_blueprint(blueprints.embed.embed, url_prefix="/embed", template_folder="/templates")
@app.route("/set_username/<guildid>/<channelid>", methods=["GET"]) @app.route("/set_username/<guildid>/<channelid>", methods=["GET"])
def get_set_username(guildid, channelid): def get_set_username(guildid, channelid):
@ -32,7 +34,7 @@ def post_set_username(guildid, channelid):
def index(): def index():
return render_template("index.html.j2") return render_template("index.html.j2")
@app.route("/embed/<guildid>/<channelid>") @app.route("/oldembed/<guildid>/<channelid>")
def embed_get(guildid, channelid): def embed_get(guildid, channelid):
if 'username' not in session: if 'username' not in session:
return redirect(url_for("get_set_username", guildid=guildid, channelid=channelid)) return redirect(url_for("get_set_username", guildid=guildid, channelid=channelid))

View File

@ -0,0 +1 @@
from embed import embed

View File

@ -0,0 +1,7 @@
from flask import Blueprint
embed = Blueprint("embed", __name__)
@embed.route("/<guild_id>")
def guild_embed(guild_id):
return guild_id

View File

@ -162,7 +162,7 @@ def administrate_guild(guild_id):
guild = discord_api.get_guild(guild_id) guild = discord_api.get_guild(guild_id)
if guild['code'] != 200: if guild['code'] != 200:
return redirect(generate_bot_invite_url(guild_id)) return redirect(generate_bot_invite_url(guild_id))
db_guild = Guilds.query.filter_by(guild_id=guild_id).first() db_guild = db.session.query(Guilds).filter(Guilds.guild_id == guild_id).first()
if not db_guild: if not db_guild:
db_guild = Guilds(guild_id) db_guild = Guilds(guild_id)
db.session.add(db_guild) db.session.add(db_guild)
@ -177,7 +177,9 @@ def administrate_guild(guild_id):
all_members = db.session.query(UnauthenticatedUsers).filter(UnauthenticatedUsers.guild_id == guild_id).all() all_members = db.session.query(UnauthenticatedUsers).filter(UnauthenticatedUsers.guild_id == guild_id).all()
all_bans = db.session.query(UnauthenticatedBans).filter(UnauthenticatedBans.guild_id == guild_id).all() all_bans = db.session.query(UnauthenticatedBans).filter(UnauthenticatedBans.guild_id == guild_id).all()
users = prepare_guild_members_list(all_members, all_bans) users = prepare_guild_members_list(all_members, all_bans)
return render_template("administrate_guild.html.j2", guild=guild['content'], members=users, permissions=permissions) users.reverse()
dbguild_dict = {"unauth_users": db_guild.unauth_users}
return render_template("administrate_guild.html.j2", guild=guild['content'], dbguild=dbguild_dict, members=users, permissions=permissions)
@user.route('/me') @user.route('/me')
@discord_users_only() @discord_users_only()

View File

@ -20,8 +20,9 @@
<div class="card-stacked"> <div class="card-stacked">
<div class="card-content"> <div class="card-content">
<p class="flow-text">Direct Link</p> <p class="flow-text">Direct Link</p>
<input disabled value="http://localhost:3000/embed/{{ guild['id'] }}" id="disabled" type="text"> <!-- Switch to url_for later --> <input disabled value="{{ url_for("embed.guild_embed", guild_id=guild['id'], _external=True) }}" id="disabled" type="text"> <!-- Switch to url_for later -->
<p class="flow-text">iFrame Embed</p> <p class="flow-text">iFrame Embed</p>
<input disabled value=" &lt;iframe src=&quot;{{ url_for("embed.guild_embed", guild_id=guild['id'], _external=True) }}&quot; height=&quot;200&quot; width=&quot;300&quot; /&gt; " id="disabled" type="text"> <!-- Switch to url_for later -->
</div> </div>
</div> </div>
</div> </div>
@ -38,7 +39,7 @@
<div class="switch"> <div class="switch">
<label> <label>
Disable Disable
<input type="checkbox" id="unauth_users" name="unauth_users"> <input type="checkbox" id="unauth_users" name="unauth_users" {% if dbguild['unauth_users'] %}checked{% endif %} >
<span class="lever"></span> <span class="lever"></span>
Enable Enable
</label> </label>