Browse Source

bug fix: user wont be able to select already listed art & auction end backend draft

control 3 years ago
parent
commit
1e1928ba69

+ 0 - 1
app/__init__.py

@@ -50,7 +50,6 @@ def create_app():
 
 
     return app
     return app
 
 
-
 def create_database(app):
 def create_database(app):
     if not path.exists('app/' + DB_NAME):
     if not path.exists('app/' + DB_NAME):
         db.create_all(app=app)
         db.create_all(app=app)

BIN
app/database (pre-minted).db


BIN
app/database.db


+ 25 - 10
app/dispatch.py

@@ -7,8 +7,6 @@ from datetime import datetime
 from flask import flash
 from flask import flash
 from flask_login import current_user
 from flask_login import current_user
 
 
-from apscheduler.schedulers.background import BackgroundScheduler as BS
-
 from .models import Hashchain, Art, List, TX , User, Bids, List
 from .models import Hashchain, Art, List, TX , User, Bids, List
 from . import db
 from . import db
 
 
@@ -112,11 +110,15 @@ def list_item(designated_fn, art_name, art_desc, min_price, buyout_price, close_
 
 
     db.session.commit() 
     db.session.commit() 
 
 
-def tx_exchange(filehash, source_id, price):
+def tx_exchange(filehash, source_id, price, dest_id=None):
+    if not dest_id:
+        if current_user.is_authenticated:
+            dest_id = current_user.id
+            
     # create tx hash
     # create tx hash
     dt = sqlalchemy.func.now()
     dt = sqlalchemy.func.now()
     ddt = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
     ddt = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
-    txstring = f'[{filehash}, {ddt}, {source_id}, {current_user.id}, {price}]' # exchange
+    txstring = f'[{filehash}, {ddt}, {source_id}, {dest_id}, {price}]' # exchange
     txhash = hsh.gen_txhash(txstring)
     txhash = hsh.gen_txhash(txstring)
     # fetch prev block hash OR GEN HASH
     # fetch prev block hash OR GEN HASH
     try:
     try:
@@ -134,7 +136,7 @@ def tx_exchange(filehash, source_id, price):
         filehash = filehash,
         filehash = filehash,
         datetime = dt,
         datetime = dt,
         source_id = source_id,
         source_id = source_id,
-        destination_id = current_user.id,
+        destination_id = dest_id,
         price = price,
         price = price,
         txhash = txhash
         txhash = txhash
         )
         )
@@ -173,12 +175,25 @@ def save_pp(pp_path):
     new_pppath.profile_image = pp_path
     new_pppath.profile_image = pp_path
     db.session.commit()
     db.session.commit()
 
 
-def check_time():
+def check_auction_end():
     # background scheduler runs this daily
     # background scheduler runs this daily
     # to check for Auction end
     # to check for Auction end
+    all_listings = List.query.all()
 
 
     # go through List table and check for timeout
     # go through List table and check for timeout
-    
-    # if close_date and min bid reached
-
-    # if close_date and min bid not reached
+    for listing in all_listings:
+        # if close_date and min bid reached
+        ddt = datetime.utcnow().strftime("%Y-%m-%d")
+        if listing.timeout == ddt and listing.cur_bid > listing.min_price:
+            print(f'DEBUG: scheduler >>> EXCHANGING!!') ##
+            # transaction for the last bid made
+            # get buyer id from Bids table using filehash
+            buyer_bid = Bids.query.filter_by(filehash = listing.filehash).order_by(desc(Bids.id)).first()
+            # initiate exchange transaction and clean bid table
+            tx_exchange(listing.filehash, listing.seller, buyer_bid.bid_price, buyer_bid.buyer)
+            clean_bid_table(listing.filehash)
+        # if close_date and min bid not reached (no one made a qualifying bid)
+        elif listing.timeout == ddt and not listing.cur_bid > listing.min_price:
+            print(f'DEBUG: scheduler >>> DE-LISTING!!') ##
+            # remove from List table
+            List.query.filter_by(filehash = filehash).delete()

+ 5 - 4
app/lib/collector.py

@@ -11,6 +11,7 @@ def join_art_list_table():
     return_list = list()
     return_list = list()
 
 
     # Creates a new list for art details
     # Creates a new list for art details
+    # This is retarded. I know.
     for l in listings:
     for l in listings:
         for a in art:
         for a in art:
             if l.filehash == a.filehash:
             if l.filehash == a.filehash:
@@ -41,12 +42,12 @@ def check_listing():
     available_art = list()
     available_art = list()
 
 
     # to remove art that is already listed
     # 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)
+    for art in owned_art:
         if not listed_art:
         if not listed_art:
             available_art.append(oa)
             available_art.append(oa)
+        # if none of the list of objects' filehash matches this filehash
+        if not any(la.filehash == art.filehash for la in listed_art):
+            available_art.append(oa)
 
 
 
 
     return available_art
     return available_art

+ 1 - 0
app/models.py

@@ -1,6 +1,7 @@
 # Database Models
 # Database Models
 from . import db # that SQLAlchemy Object in __init__.py
 from . import db # that SQLAlchemy Object in __init__.py
 from flask_login import UserMixin
 from flask_login import UserMixin
+from flask import app
 from sqlalchemy.sql import func
 from sqlalchemy.sql import func
 
 
 class User(db.Model, UserMixin): # User Database
 class User(db.Model, UserMixin): # User Database

BIN
app/static/repository/3YdXeM6xZpUbmj3W.jpg


BIN
app/static/repository/7PE7S1elVmnyrrDX.jpeg


BIN
app/static/repository/E40pw7hr8Xv4yBBS.jpg


BIN
app/static/repository/HXk4s8hcG6T0SvsO.jpg


BIN
app/static/repository/SmAmbRZwkxOL3jWD.jpg


BIN
app/static/repository/hgWeov20otnWlBAp.jpg


BIN
app/static/repository/vaUxGM7yQfkqwRan.jpg


BIN
app/static/uploads/LzMUWPV3r1ZUb4SI.jpeg


+ 22 - 1
main.py

@@ -1,6 +1,27 @@
 from app import create_app
 from app import create_app
 
 
+#from apscheduler.schedulers.background import BackgroundScheduler as BS
+#from apscheduler.triggers.cron import CronTrigger
+#from app.dispatch import check_auction_end
+
 app = create_app()
 app = create_app()
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':
-    app.run(debug=True) ## debug=True auto re-runs websever upon change turn off for production
+
+    '''
+    with app.app_context():
+        # Background Scheduler for Background tasks
+        #app.app_context().push() # need to wrap this in app context
+        sched = BS(daemon=True)
+        if not sched.running:
+            print(f'DEBUG: STARTING SCHEDULER')
+            # pass the function of check_auction_end, don't call
+            #sched.add_job(check_auction_end, CronTrigger.from_crontab('0 0 * * *'))
+            #sched.add_job(check_auction_end, CronTrigger.from_crontab('*/2 * * * *'))
+            sched.add_job(check_auction_end, trigger="interval", seconds=60)
+            sched.start()
+    '''
+
+    app.run(debug=True) ## debug=True auto re-runs websever upon change turn off for production
+
+