Эх сурвалжийг харах

art now shows in profile page

control 3 жил өмнө
parent
commit
ecf6d706aa

+ 7 - 4
app/dashboards.py

@@ -1,12 +1,12 @@
 from flask import Blueprint, render_template, request, flash, redirect, url_for
 from flask_login import login_required, current_user
 from werkzeug.security import generate_password_hash, check_password_hash
-from .models import User
+from .models import User, Art
 from . import db
 
-from . import clean_file as cf
-from . import tools
 from . import dispatch
+from app.lib import clean_file as cf
+from app.lib import tools
 
 dashboards = Blueprint('dashboards', __name__)
 
@@ -34,7 +34,10 @@ def profile():
             else:
                 flash('Password update failed!', category='error')
 
-    return render_template('profile.html', user=current_user)
+    my_art = Art.query.filter_by(owner=current_user.id).all()
+    my_creation = Art.query.filter_by(creator=current_user.id).all()
+
+    return render_template('profile.html', user = current_user, my_art = my_art, my_creation = my_creation)
 
 @dashboards.route('/create_art', methods=['GET', 'POST'])
 @login_required

BIN
app/database-clean.db


BIN
app/database-mints.db


BIN
app/database.db


+ 14 - 4
app/dispatch.py

@@ -1,14 +1,16 @@
 # Dispatches data to hasher and adds to database tables
 
 import sqlalchemy
+import os
+
 from datetime import datetime
 from flask_login import current_user
 
 from .models import Hashchain, Art, List, TX 
 from . import db
 
-from . import clean_file as cf
-from . import hasher as hsh
+from app.lib import clean_file as cf
+from app.lib import hasher as hsh
 
 def mint(designated_fn, art_name, art_desc, min_price, buyout_price, close_date):
     # gen filehash
@@ -29,7 +31,8 @@ def mint(designated_fn, art_name, art_desc, min_price, buyout_price, close_date)
     new_bhash = hsh.append_tx(txhash, prev_bhash)
     new_block = Hashchain(blockhash = new_bhash)
     db.session.add(new_block)
-    # move the file into external secure storage + another local dir (NOT DONE)
+    # move the file into external secure storage (NOT DONE)
+    os.rename(f'{cf.UPLOAD_FOLDER}/{designated_fn}', f'{cf.REPO_FOLDER}/{designated_fn}')
     # add to TX table (mint)
     new_tx = TX(
             filehash = filehash,
@@ -41,7 +44,14 @@ def mint(designated_fn, art_name, art_desc, min_price, buyout_price, close_date)
             )
     db.session.add(new_tx)
     # add to Art table
-    new_art = Art(name = art_name, description = art_desc, filehash = filehash)
+    new_art = Art(
+            name = art_name,
+            description = art_desc,
+            filehash = filehash,
+            owner = current_user.id,
+            creator = current_user.id,
+            dname = designated_fn
+            )
     db.session.add(new_art)
     # add to List table
     new_listing = List(

+ 0 - 0
app/lib/__init__.py


+ 0 - 0
app/alphagen.py → app/lib/alphagen.py


+ 1 - 0
app/clean_file.py → app/lib/clean_file.py

@@ -5,6 +5,7 @@ from werkzeug.utils import secure_filename
 from . import alphagen as ag
 
 UPLOAD_FOLDER = 'app/static/incoming'
+REPO_FOLDER = 'app/static/repository'
 ALLOWED_EXT = {'png', 'jpg', 'jpeg'}
 
 # Checks file for allowed extension

+ 0 - 0
app/hasher.py → app/lib/hasher.py


+ 0 - 0
app/tools.py → app/lib/tools.py


+ 3 - 0
app/models.py

@@ -28,6 +28,9 @@ class Art(db.Model):
     name = db.Column(db.String(200))
     description = db.Column(db.String(200))
     filehash = db.Column(db.String(64)) # sha256 hash
+    owner = db.Column(db.Integer)
+    creator = db.Column(db.Integer)
+    dname = db.Column(db.String(20))
 
 class List(db.Model):
     id = db.Column(db.Integer, primary_key=True)

BIN
app/static/repository/pTXxc8nsR2HTQPQO.jpeg


+ 8 - 2
app/templates/profile.html

@@ -55,12 +55,18 @@ table, th, td {
 <p>{{user.username}}</p>
 <hr>
 <p>Art I Own</p>
-<p>1. Art Name</p>
+{%for art in my_art%}
+<p>{{art.name}}</p>
+<img src="static/repository/{{art.dname}}">
 <p>2. Art Image(Click the photo will go to pop up detail art page)</p>
+{%endfor%}
 <hr>
+{%for art in my_creation%}
 <p>Art by Me</p>
-<p>1. Art Name</p>
+<p>{{art.name}}</p>
+<img src="static/repository/{{art.dname}}">
 <p>2. Art Image(Click the photo will go to pop up detail art page)</p>
+{%endfor%}
 <a href="{{url_for('dashboards.modal_profile')}}">Popup</a>
 
 {% block modal %}{% endblock %}