Răsfoiți Sursa

backend for market and profile art selection done

control 3 ani în urmă
părinte
comite
71c0da1400

+ 34 - 24
app/dashboards.py

@@ -5,8 +5,8 @@ from .models import User, Art, List
 from . import db
 
 from . import dispatch
-from app.lib import clean_file as cf
-from app.lib import tools
+from app.lib import clean_file as cf, tools
+from app.lib import collector
 
 from .forms import UPForm, PicForm, CAForm
 
@@ -15,14 +15,14 @@ dashboards = Blueprint('dashboards', __name__)
 # Main Pages
 @dashboards.route('/', methods=['GET', 'POST'])
 def market():
-    listings = List.query.all()
-    art = Art.query.all()
-    return_list = list()
-    for l in listings:
-        for a in art:
-            if l.filehash == a.filehash:
-                return_list.append([a.name, a.description, a.owner, a.creator, a.dname, l.seller, l.min_price, l.out_price, l.timeout, l.list_date])
-                
+    return_list = collector.market_listing()
+
+    if request.method == "POST":
+        focus_item = request.form.get('focus_but')
+        u_dbcall = User.query.filter_by(id=current_user.id).first()
+        u_dbcall.focus = focus_item
+        db.session.commit()
+        return redirect(url_for('dashboards.detail'))
 
     return render_template('market.html', user=current_user, listings = return_list)
 	
@@ -32,6 +32,13 @@ def profile():
     form = UPForm()
     form2 = PicForm()
 
+    if request.method == "POST":
+        focus_item = request.form.get('focus_but')
+        u_dbcall = User.query.filter_by(id=current_user.id).first()
+        u_dbcall.focus = focus_item
+        db.session.commit()
+        return redirect(url_for('dashboards.detail'))
+
     if form2.validate_on_submit():
         print('passsing')
         f =  form2.upload.data
@@ -40,8 +47,6 @@ def profile():
             f.save(f'{cf.PROFILEPIC_FOLDER}/{designated_fn}')
             dispatch.save_pp(designated_fn)
             flash('Updated Profile Picture!', category='success')
-        else:
-            print('you dick')    
         
 
     if form.validate_on_submit():
@@ -76,15 +81,7 @@ def profile():
 def create():
     form = CAForm()
 
-    owned_art = Art.query.filter_by(owner=current_user.id).all() 
-    listed_art = List.query.filter_by(seller=current_user.id).all()
-    available_art = list()
-
-    # to remove art that is already listed
-    for oa in owned_art:
-        for la in listed_art:
-            if oa.filehash != la.filehash:
-                available_art.append(oa)
+    available_art = collector.check_listing()
 
    # check POST req
     if form.validate_on_submit():
@@ -101,16 +98,29 @@ def create():
                 designated_fn = cf.sanitize(new_art.filename)
                 new_art.save(f'{cf.UPLOAD_FOLDER}/{designated_fn}')
                 dispatch.mint(designated_fn, art_name, art_desc, min_price, buyout_price, close_date)
-            # elif here
+                flash('Minted & Listed!', category='success')
 
     return render_template('create_art.html', user = current_user, form = form, av_art = available_art)
 	
 @dashboards.route('/search')
 @login_required
 def search():
-    return render_template('search.html', user=current_user)
+    return render_template('search.html', user = current_user)
 
 @dashboards.route('/detail')
 @login_required
 def detail():
-    return render_template('detail_art.html', user=current_user)
+
+    focus = None
+
+    # Collects details of the listing based on the 
+    # focus pointer of the user
+    return_list = collector.market_listing()
+    for item in return_list:
+        if item[11] == current_user.focus: # comparing hash
+            focus = item
+            break
+
+    owner_obj = collector.find_user_obj(focus[2])
+
+    return render_template('detail_art.html', user = current_user, detail = focus, own_uname = owner_obj.username)

BIN
app/database.db


+ 0 - 6
app/lib/alphagen.py

@@ -1,6 +0,0 @@
-import string, secrets
-
-def gen_alphanum():
-    alphanumeric = string.ascii_letters + string.digits
-    ralphanum = ''.join(secrets.choice(alphanumeric) for i in range(16))
-    return ralphanum

+ 2 - 2
app/lib/clean_file.py

@@ -2,7 +2,7 @@ import os
 
 from werkzeug.utils import secure_filename
 
-from . import alphagen as ag
+from .tools import gen_alphanum
 
 UPLOAD_FOLDER = 'app/static/incoming'
 REPO_FOLDER = 'app/static/repository'
@@ -18,7 +18,7 @@ def allowed_file(filename):
 def sanitize(filename):
     sfn = secure_filename(filename) # strips any slashes
     ssfn, fx = os.path.splitext(sfn) # ensures that internal filenames are not
-    rsfn = ag.gen_alphanum() # known to users.
+    rsfn = gen_alphanum() # known to users.
     ffn = f'{rsfn}{fx}'
     return ffn
 

+ 52 - 0
app/lib/collector.py

@@ -0,0 +1,52 @@
+# Collects data the retarded way
+
+from flask_login import current_user
+from app.models import User, Art, List
+
+def market_listing():
+    listings = List.query.all()
+    art = Art.query.all()
+    user_list = User.query.all()
+    return_list = list()
+
+    # Creates a new list for art details
+    for l in listings:
+        for a in art:
+            if l.filehash == a.filehash:
+                for u in user_list:
+                    if a.creator == u.id:
+                        return_list.append([
+                            a.name, # [0] name of art
+                            a.description, # [1] description of art
+                            a.owner, # [2] current owner id
+                            u.username, # [3] creator's username
+                            u.profile_image, # [4] creator's profilepic
+                            a.dname, # [5] designated db name, also path filename
+                            l.seller, # [6] current seller id
+                            l.min_price, # [7] minimum bid price
+                            l.out_price, # [8] minimum buyout price
+                            l.timeout, # [9] closing bidding date
+                            l.list_date, # [10] listing date
+                            l.filehash # [11] listings/art filehash
+                        ])
+    return return_list
+
+def check_listing():
+    # returns list of art available to sell
+    owned_art = Art.query.filter_by(owner=current_user.id).all() 
+    listed_art = List.query.filter_by(seller=current_user.id).all()
+    available_art = list()
+
+    # to remove art that is already listed
+    for oa in owned_art:
+        for la in listed_art:
+            if oa.filehash != la.filehash:
+                available_art.append(oa)
+
+    return available_art
+
+
+def find_user_obj(user_id):
+    user = User.query.filter_by(id=user_id).first()
+    return user
+    

+ 5 - 0
app/lib/tools.py

@@ -1,4 +1,5 @@
 # Tools
+import string, secrets
 
 # takes list of variables and checks if empty
 def check_fields(var_list):
@@ -11,3 +12,7 @@ def check_fields(var_list):
     if counter == len(var_list):
         return True
 
+def gen_alphanum():
+    alphanumeric = string.ascii_letters + string.digits
+    ralphanum = ''.join(secrets.choice(alphanumeric) for i in range(16))
+    return ralphanum

+ 8 - 6
app/models.py

@@ -4,11 +4,12 @@ from flask_login import UserMixin
 from sqlalchemy.sql import func
 
 class User(db.Model, UserMixin): # User Database
-   id = db.Column(db.Integer, primary_key=True)
-   email = db.Column(db.String(150), unique=True)
-   password = db.Column(db.String(150))
-   username = db.Column(db.String(150))
-   profile_image = db.Column(db.String(150))
+    id = db.Column(db.Integer, primary_key=True)
+    email = db.Column(db.String(150), unique=True)
+    password = db.Column(db.String(150))
+    username = db.Column(db.String(150))
+    profile_image = db.Column(db.String(150))
+    focus = db.Column(db.Integer)
 
 class TX(db.Model):
     id = db.Column(db.Integer, primary_key=True)
@@ -30,7 +31,7 @@ class Art(db.Model):
     filehash = db.Column(db.String(64), unique=True) # sha256 hash # parent foreign key
     owner = db.Column(db.Integer)
     creator = db.Column(db.Integer)
-    dname = db.Column(db.String(20))
+    dname = db.Column(db.String(20)) # designated DB name
 
 class List(db.Model):
     id = db.Column(db.Integer, primary_key=True)
@@ -38,6 +39,7 @@ class List(db.Model):
     seller = db.Column(db.Integer)
     min_price = db.Column(db.Float)
     out_price = db.Column(db.Float)
+    cur_bid = db.Column(db.Float)
     timeout = db.Column(db.String(20))
     list_date = db.Column(db.DateTime(timezone=True), default=func.now()) 
 

BIN
app/static/repository/7yDTwiUakqiqTpZS.jpeg


BIN
app/static/repository/pTXxc8nsR2HTQPQ1.jpg


BIN
app/static/repository/pTXxc8nsR2HTQPQO.jpeg


BIN
app/static/uploads/lj7Czu6aeTXytG4z.jpeg


+ 8 - 14
app/templates/detail_art.html

@@ -7,23 +7,23 @@
     <div class="container px-4 px-lg-5 my-5">
       <div class="row gx-4 gx-lg-5 align-items-center">
         <!-- Art Image-->
-        <div class="col-md-6"><img class="card-img-top mb-5 mb-md-0" src="static/repository/website_photo/navbar_icon.png" alt="..." /></div>
+        <div class="col-md-6"><img class="card-img-top mb-5 mb-md-0" src="static/repository/{{detail[5]}}" alt="..." /></div>
           <div class="col-md-6">
             <!-- AuctionEnd Time-->
             <div class="small mb-1">
-              (Auction ends in time)
+                {{ detail[9] }}
             </div>
             <!-- Art Name-->
-            <h1 class="display-5 fw-bolder">(Art Name)</h1>
+            <h1 class="display-5 fw-bolder">{{ detail[0] }}</h1>
             <!-- Art Description-->
-            <p class="lead">(Description)</p>
+            <p class="lead">{{ detail[1] }}</p>
             <div class="fs-5 mb-5">
               <!-- Price & Name-->
               <span class="text-decoration-line-through">Current Bid Price: (Current Bid Price) USD</span><br>
-              <span class="text-decoration-line-through">Buyout Price: (Buyout Price) USD</span><br>
-              <span class="text-decoration-line-through">Minimum Price: (Minimum Price) USD</span><br>
-              <span class="text-decoration-line-through">Who Created: (Creator Name)</span><br>
-              <span class="text-decoration-line-through">Art Owner: (Owner Name)</span><br>
+              <span class="text-decoration-line-through">Buyout Price: {{ detail[8] }} USD</span><br>
+              <span class="text-decoration-line-through">Minimum Price: {{ detail[7] }} USD</span><br>
+              <span class="text-decoration-line-through">Creator: {{ detail[3] }}</span><br>
+              <span class="text-decoration-line-through">Current Owner: {{ own_uname }}</span><br>
             </div>
             <!-- Bid button-->
             <div class="d-flex">
@@ -37,7 +37,6 @@
                 />
                 <label for="Bidding Price"></label>
                 <button class="btn btn-dark flex-shrink-0 input-submit" type="submit">Bid</button>
-                <p>(At the backend needs to record the bidder nickname and time. And the record will be showing at the bid history table)</p>
               </form>
             </div>
           </div>
@@ -73,12 +72,7 @@
         <td>100</td>
       </tr>
     </table>
-
     <hr>
-    <h3>(For the Bid button</h3>
-    <p>Only show the bid button if the user login. The bidding price needs higher than before.</p>
-    <p>If the user enters the buyout price, the auction will be ended.</p>
-    <p>Will not show the bid button for who created the auction.)</p>
   </div>
 </div>
 {% endblock %}

+ 5 - 2
app/templates/market.html

@@ -15,7 +15,10 @@
     <div class="row row-cols-4">
         {% for art in listings %}
         <div class="card col-md-3 grid-item shadow p-3 mb-5 bg-white rounded">
-            <a href="detail"><img class="market_each_bid_image_size" src="static/repository/{{art[4]}}"></a>
+            <!--<a href="detail"><img class="market_each_bid_image_size" src="static/repository/{{art[5]}}"></a>-->
+            <form method="POST">
+            <button name="focus_but" type="submit" value="{{art[11]}}"><img class="market_each_bid_image_size" src="static/repository/{{art[5]}}"></button>
+            </form>
             <div class="row" id="market_item_name_left">
                 <b>{{art[0]}}</b>
             </div>
@@ -25,7 +28,7 @@
             </div>
             <div class="row">
                 <p id="market_item_text_left">Creator</b>
-                <p id="market_item_text_right"><img src="static/Creator_Icon/" height=25 width=25>(Creator Icon)(Creator Name)</b>
+            <p id="market_item_text_right"><img src="static/uploads/{{art[4]}}" height=25 width=25>{{art[3]}}</b>
             </div>
         </div>
         {% endfor %}

+ 8 - 2
app/templates/profile.html

@@ -102,7 +102,10 @@
                                 <div class="row row-cols-3">
                                 {%for art in my_art%}
                                     <div class="card col-md-4 shadow p-3 mb-5 bg-white rounded"  type="button">
-                                        <a href="detail"><img class="image_bid_item_size" src="static/repository/{{art.dname}}"></a>
+                                        <form method="POST">
+                                            <!--<a href="detail"></a>-->
+                                            <button name="focus_but" type="submit" value="{{art.filehash}}"><img class="image_bid_item_size" src="static/repository/{{art.dname}}"></button>
+                                        </form>
                                             <div class="row" id="market_item_name_left">
                                             <b>{{art.name}}</b>
                                             </div>
@@ -114,7 +117,10 @@
                                 <div class="row row-cols-3">
                                     {%for art in my_creation%}
                                     <div class="card col-md-4 shadow p-3 mb-5 bg-white rounded"  type="button">
-                                        <a href="detail"><img class="image_bid_item_size" src="static/repository/{{art.dname}}"></a>
+                                        <form method="POST">
+                                            <!--<a href="detail"></a>-->
+                                            <button name="focus_but" type="submit" value="{{art.filehash}}"><img class="image_bid_item_size" src="static/repository/{{art.dname}}"></button>
+                                        </form>
                                             <div class="row" id="market_item_name_left">
                                                 <b>{{art.name}}</b>
                                             </div>