From 7a3924cd8183122ee0e13211a7cc00840993c7a5 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Thu, 30 Dec 2021 15:02:39 -0800 Subject: [PATCH] Adding more chain integrations --- .../versions/f15cd9fa0f06_meme_approval.py | 27 +++++++ suchwowx/models.py | 1 + suchwowx/routes/meme.py | 17 ++-- suchwowx/static/js/metamask.js | 1 - suchwowx/templates/includes/meme_card.html | 2 +- suchwowx/templates/includes/web3.html | 22 ++++- suchwowx/templates/meme.html | 80 +++++++++++++------ 7 files changed, 116 insertions(+), 34 deletions(-) create mode 100644 alembic/versions/f15cd9fa0f06_meme_approval.py diff --git a/alembic/versions/f15cd9fa0f06_meme_approval.py b/alembic/versions/f15cd9fa0f06_meme_approval.py new file mode 100644 index 0000000..a36a0e7 --- /dev/null +++ b/alembic/versions/f15cd9fa0f06_meme_approval.py @@ -0,0 +1,27 @@ +"""meme approval + +Revision ID: f15cd9fa0f06 +Revises: c548cc54ee17 +Create Date: 2021-12-30 13:11:10.706513 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'f15cd9fa0f06' +down_revision = 'c548cc54ee17' +branch_labels = None +depends_on = None + + +def upgrade(): + with op.batch_alter_table('memes', schema=None) as batch_op: + batch_op.add_column(sa.Column('approved', sa.Boolean(), nullable=True)) + + + +def downgrade(): + with op.batch_alter_table('memes', schema=None) as batch_op: + batch_op.drop_column('approved') diff --git a/suchwowx/models.py b/suchwowx/models.py index 5eec059..e59e746 100644 --- a/suchwowx/models.py +++ b/suchwowx/models.py @@ -102,6 +102,7 @@ class Meme(db.Model): title = db.Column(db.String(50)) description = db.Column(db.String(400), nullable=True) minted = db.Column(db.Boolean, default=False) + approved = db.Column(db.Boolean, default=False) user_id = db.Column(db.Integer, db.ForeignKey('users.id')) user = db.relationship('User', back_populates='memes') diff --git a/suchwowx/routes/meme.py b/suchwowx/routes/meme.py index 7acb273..2f8cd9a 100644 --- a/suchwowx/routes/meme.py +++ b/suchwowx/routes/meme.py @@ -19,7 +19,7 @@ bp = Blueprint('meme', 'meme') @bp.route('/') def index(): memes = Meme.query.filter( - Meme.meta_ipfs_hash != None + Meme.approved == True ).order_by(Meme.create_date.desc()) w3 = Web3(Web3.HTTPProvider('http://127.0.0.1:9650')) contract_address = w3.toChecksumAddress(config.CONTRACT_ADDRESS) @@ -38,7 +38,7 @@ def mod(): flash('You are not a moderator', 'warning') return redirect(url_for('meme.index')) memes = Meme.query.filter( - Meme.meta_ipfs_hash == None + Meme.approved != True ).order_by(Meme.create_date.asc()) return render_template('index.html', memes=memes) @@ -105,10 +105,10 @@ def show(meme_id): meme = Meme.query.filter(Meme.id == meme_id).first() if not meme: return redirect('/') - if not meme.meta_ipfs_hash and not current_user.is_authenticated: - flash('You need to be a moderator to view that meme.', 'warning') + if not meme.approved and not current_user.is_authenticated: + flash('You need to be logged in to view that meme.', 'warning') return redirect(url_for('meme.index')) - elif not meme.meta_ipfs_hash and not current_user.is_moderator(): + elif not meme.approved and not current_user.is_moderator(): flash('You need to be a moderator to view that meme.', 'warning') return redirect(url_for('meme.index')) return render_template('meme.html', meme=meme) @@ -126,8 +126,8 @@ def approve(meme_id, action): if not meme: flash('That meme does not exist.', 'warning') return redirect(url_for('meme.index')) - if meme.meta_ipfs_hash != None: - flash('That meme already has been published to IPFS.', 'warning') + if meme.approved is True: + flash('That meme already has been approved.', 'warning') return redirect(url_for('meme.show', meme_id=meme.id)) if action == 'approve': res = upload_to_ipfs(meme.id) @@ -145,8 +145,9 @@ def approve(meme_id, action): return redirect(url_for('meme.show', meme_id=meme.id)) meme.meta_ipfs_hash = res[0] meme.meme_ipfs_hash = res[1] + meme.approved = True db.session.commit() - flash('Published new meme to IPFS.', 'success') + flash('Approved meme and published new meme to local IPFS server.', 'success') elif action == 'deny': # delete image # delete from database diff --git a/suchwowx/static/js/metamask.js b/suchwowx/static/js/metamask.js index 90b159d..6f0beb8 100644 --- a/suchwowx/static/js/metamask.js +++ b/suchwowx/static/js/metamask.js @@ -19,7 +19,6 @@ async function onboardMetaMask(){ const connectButton = async () => { if (!MetaMaskOnboarding.isMetaMaskInstalled()) { - onboardButton.innerText = 'Click here to install MetaMask!'; onboardButton.onclick = () => { onboardButton.classList.add('is-loading'); onboardButton.disabled = true; diff --git a/suchwowx/templates/includes/meme_card.html b/suchwowx/templates/includes/meme_card.html index d3996fc..f51346a 100644 --- a/suchwowx/templates/includes/meme_card.html +++ b/suchwowx/templates/includes/meme_card.html @@ -2,7 +2,7 @@
- + {% if meme.file_name.endswith('mp4') %}

Meme IPFS: {{ meme.meme_ipfs_hash }}

{% endif %}

Meme ID: {{ meme }}

- {% if not meme.meta_ipfs_hash %} + + {% if not meme.approved %}
@@ -50,23 +62,22 @@
{% else %}
-
- {% if meme.minted %} + + +
{% endif %}
@@ -75,31 +86,53 @@
{% include 'includes/footer.html' %} + {% if meme.approved %} {% include 'includes/web3.html' %} + {% endif %}