|
|
|
@ -7,9 +7,9 @@ from flask import Flask, request, session, redirect
|
|
|
|
|
from flask import render_template, flash, url_for
|
|
|
|
|
from flask_session import Session
|
|
|
|
|
from suchwow import config
|
|
|
|
|
from suchwow.models import Post, Profile, Comment, Notification, db
|
|
|
|
|
from suchwow.models import Post, Profile, Comment, Notification, db, Moderator
|
|
|
|
|
from suchwow.routes import auth, comment, post, profile, leaderboard
|
|
|
|
|
from suchwow.utils.decorators import login_required
|
|
|
|
|
from suchwow.utils.decorators import login_required, moderator_required
|
|
|
|
|
from suchwow.reddit import make_post
|
|
|
|
|
from suchwow.discord import post_discord_webhook
|
|
|
|
|
from suchwow import wownero
|
|
|
|
@ -37,13 +37,19 @@ def index():
|
|
|
|
|
flash("Wow, wtf hackerman. Cool it.")
|
|
|
|
|
page = 1
|
|
|
|
|
|
|
|
|
|
posts = Post.select().order_by(Post.timestamp.desc())
|
|
|
|
|
posts = Post.select().where(Post.approved==True).order_by(Post.timestamp.desc())
|
|
|
|
|
if submitter:
|
|
|
|
|
posts = posts.where(Post.submitter == submitter)
|
|
|
|
|
posts = posts.paginate(page, itp)
|
|
|
|
|
total_pages = Post.select().count() / itp
|
|
|
|
|
return render_template("index.html", posts=posts, page=page, total_pages=total_pages)
|
|
|
|
|
|
|
|
|
|
@app.route("/mod")
|
|
|
|
|
@moderator_required
|
|
|
|
|
def mod_queue():
|
|
|
|
|
posts = Post.select().where(Post.approved==False).order_by(Post.timestamp.asc())
|
|
|
|
|
return render_template("index.html", posts=posts)
|
|
|
|
|
|
|
|
|
|
@app.route("/about")
|
|
|
|
|
def about():
|
|
|
|
|
return render_template("about.html")
|
|
|
|
@ -60,7 +66,7 @@ def init():
|
|
|
|
|
makedirs(f"{config.DATA_FOLDER}/{i}", exist_ok=True)
|
|
|
|
|
|
|
|
|
|
# init db
|
|
|
|
|
db.create_tables([Post, Profile, Comment, Notification])
|
|
|
|
|
db.create_tables([Post, Profile, Comment, Notification, Moderator])
|
|
|
|
|
|
|
|
|
|
@app.cli.command("create_accounts")
|
|
|
|
|
def create_accounts():
|
|
|
|
@ -106,7 +112,7 @@ def payout_users():
|
|
|
|
|
|
|
|
|
|
@app.cli.command("delete_post")
|
|
|
|
|
@click.argument("post_id")
|
|
|
|
|
def delete_post(post_id):
|
|
|
|
|
def _delete_post(post_id):
|
|
|
|
|
post = Post.get(id=post_id)
|
|
|
|
|
save_path_base = path.join(app.config["DATA_FOLDER"], "uploads")
|
|
|
|
|
save_path = path.join(save_path_base, post.image_name)
|
|
|
|
@ -114,5 +120,25 @@ def delete_post(post_id):
|
|
|
|
|
remove(save_path)
|
|
|
|
|
print(f"Deleted post {post_id} and image {save_path}")
|
|
|
|
|
|
|
|
|
|
@app.cli.command("add_admin")
|
|
|
|
|
@click.argument("username")
|
|
|
|
|
def add_admin(username):
|
|
|
|
|
if not Moderator.filter(username=username):
|
|
|
|
|
m = Moderator(username=username)
|
|
|
|
|
m.save()
|
|
|
|
|
print(f"Added {username}")
|
|
|
|
|
else:
|
|
|
|
|
print("That moderator already exists")
|
|
|
|
|
|
|
|
|
|
@app.cli.command("remove_admin")
|
|
|
|
|
@click.argument("username")
|
|
|
|
|
def add_admin(username):
|
|
|
|
|
m = Moderator.filter(username=username).first()
|
|
|
|
|
if m:
|
|
|
|
|
m.delete_instance()
|
|
|
|
|
print(f"Deleted {username}")
|
|
|
|
|
else:
|
|
|
|
|
print("That moderator doesn't exist")
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
app.run()
|
|
|
|
|