Explorar o código

bug fix: deleting bidding records when art is bought out

control %!s(int64=3) %!d(string=hai) anos
pai
achega
7483c15101
Modificáronse 3 ficheiros con 11 adicións e 3 borrados
  1. 3 3
      app/dashboards.py
  2. BIN=BIN
      app/database.db
  3. 8 0
      app/dispatch.py

+ 3 - 3
app/dashboards.py

@@ -142,6 +142,7 @@ def search():
 @login_required
 def detail():
     focus = None
+    form = BidForm()
 
     # Collects details of the listing based on the 
     # focus pointer of the user
@@ -156,15 +157,14 @@ def detail():
     item_bid_hist = collector.item_bid_hist(current_user.focus)
 
     # New Bid
-    form = BidForm()
-
     if form.validate_on_submit():
         user_bid = form.price.data
         # checking if bid is at buyout price or more
         if user_bid and user_bid >= focus[8]:
             dispatch.enter_bid(user_bid, focus)
             dispatch.tx_exchange(current_user.focus, focus[6], user_bid)
-            flash('You Bought this piece out! WOAH!', category='success')
+            dispatch.clean_bid_table(current_user.focus)
+            flash('You Bought this piece out! Congratulations!', category='success')
             return redirect(url_for('dashboards.profile'))
         # checking if bid is higher than minimum bidding price
         elif user_bid and user_bid > focus[7]:

BIN=BIN
app/database.db


+ 8 - 0
app/dispatch.py

@@ -111,6 +111,7 @@ def list_item(designated_fn, art_name, art_desc, min_price, buyout_price, close_
     db.session.commit() 
 
 def tx_exchange(filehash, source_id, price):
+    # create tx hash
     dt = sqlalchemy.func.now()
     ddt = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
     txstring = f'[{filehash}, {ddt}, {source_id}, {current_user.id}, {price}]' # exchange
@@ -144,6 +145,13 @@ def tx_exchange(filehash, source_id, price):
 
     db.session.commit()
 
+def clean_bid_table(filehash):
+    # cleans Bid table when Artwork is bought
+    old_bids = Bids.query.filter_by(filehash = filehash).all()
+    for bid in old_bids:
+        db.session.delete(bid)
+    db.session.commit()
+
 def enter_bid(user_bid, focus):
     # add to Bids table
     new_bid = Bids(