diff --git a/suchwow/app.py b/suchwow/app.py index 1644722..2a0d27d 100644 --- a/suchwow/app.py +++ b/suchwow/app.py @@ -16,6 +16,7 @@ Session(app) app.register_blueprint(post.bp) app.register_blueprint(auth.bp) +app.register_blueprint(profile.bp) @app.route("/") def index(): diff --git a/suchwow/models.py b/suchwow/models.py index 721e03c..640ac0e 100644 --- a/suchwow/models.py +++ b/suchwow/models.py @@ -3,7 +3,7 @@ from datetime import datetime from suchwow import config -db = SqliteDatabase(f'{config.DATA_FOLDER}/db/sqlite.db') +db = SqliteDatabase(f"{config.DATA_FOLDER}/db/sqlite.db") class Post(Model): id = AutoField() @@ -25,7 +25,7 @@ class Profile(Model): id = AutoField() username = CharField() address = CharField() - notifications = IntegerField() + notifications = IntegerField(default=0) class Meta: database = db @@ -33,8 +33,8 @@ class Profile(Model): class Comment(Model): id = AutoField() comment = TextField() - commenter = ForeignKeyField(Profile, field=Profile.username) - post = ForeignKeyField(Post, field=id) + commenter = ForeignKeyField(Profile) + post = ForeignKeyField(Post) timestamp = DateTimeField(default=datetime.now) class Meta: @@ -43,7 +43,7 @@ class Comment(Model): class Notification(Model): type = CharField() message = TextField() - username = ForeignKeyField(Profile, field=Profile.username) + username = ForeignKeyField(Profile) timestamp = DateTimeField(default=datetime.now) class Meta: diff --git a/suchwow/routes/post.py b/suchwow/routes/post.py index 150e1cb..0029ac0 100644 --- a/suchwow/routes/post.py +++ b/suchwow/routes/post.py @@ -4,7 +4,7 @@ from flask import send_from_directory, redirect, url_for, current_app from werkzeug.utils import secure_filename from suchwow import wownero from suchwow.models import Post -from suchwow.utils.decorators import login_required +from suchwow.utils.decorators import login_required, profile_required from suchwow.utils.helpers import allowed_file @@ -25,6 +25,7 @@ def read(id): @bp.route("/post/create", methods=["GET", "POST"]) @login_required +@profile_required def create(): if request.method == "POST": post_title = request.form.get("title") @@ -46,7 +47,6 @@ def create(): save_path_base = path.join(current_app.config["DATA_FOLDER"], "uploads") save_path = path.join(save_path_base, filename) file.save(save_path) - # gen wallet try: wallet = wownero.Wallet() account_index = wallet.new_account() diff --git a/suchwow/routes/profile.py b/suchwow/routes/profile.py index e69de29..c181494 100644 --- a/suchwow/routes/profile.py +++ b/suchwow/routes/profile.py @@ -0,0 +1,24 @@ +from flask import render_template, Blueprint, flash +from flask import request, redirect, url_for, session +from suchwow.models import Profile +from suchwow.utils.decorators import login_required + + +bp = Blueprint("profile", "profile") + +@bp.route("/profile/edit", methods=["GET", "POST"]) +@login_required +def edit(): + if request.method == "POST": + address = request.form.get("address") + if len(address) in [97, 108]: + profile = Profile( + username=session["auth"]["preferred_username"], + address=address + ) + profile.save() + return redirect(request.args.get("redirect", "/")) + else: + flash("WTF bro, that's not a valid Wownero address") + return redirect(request.url) + return render_template("profile/edit.html") diff --git a/suchwow/templates/index.html b/suchwow/templates/index.html index 086fcf4..603ba70 100644 --- a/suchwow/templates/index.html +++ b/suchwow/templates/index.html @@ -8,11 +8,15 @@
No posts yet!
+ {% endif %} @@ -20,7 +24,7 @@ Back {% endif %} - {% if not page == total_pages %} + {% if page <= total_pages and total_pages > 0 %} Next {% endif %} diff --git a/suchwow/templates/navbar.html b/suchwow/templates/navbar.html index b80aa66..00d9761 100755 --- a/suchwow/templates/navbar.html +++ b/suchwow/templates/navbar.html @@ -18,6 +18,9 @@ Login {% else %} +Vote for this post by sending WOW to the following address:
{{ address }}
Vote for this post by sending WOW to the following address:
{{ address }}
You need to setup your profile before you can submit memes. As of now this only consists of a payout address so we know where to send Wownero if someone sends funds for your post.
+ +