|
|
@@ -1,21 +1,21 @@
|
|
|
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, Art, List
|
|
|
+from .models import User, Art, List, Bids
|
|
|
from . import db
|
|
|
|
|
|
from . import dispatch
|
|
|
from app.lib import clean_file as cf, tools
|
|
|
from app.lib import collector
|
|
|
|
|
|
-from .forms import UPForm, PicForm, CAForm
|
|
|
+from .forms import UPForm, PicForm, CAForm, BidForm
|
|
|
|
|
|
dashboards = Blueprint('dashboards', __name__)
|
|
|
|
|
|
# Main Pages
|
|
|
@dashboards.route('/', methods=['GET', 'POST'])
|
|
|
def market():
|
|
|
- return_list = collector.market_listing()
|
|
|
+ return_list = collector.join_art_list_table()
|
|
|
|
|
|
if request.method == "POST":
|
|
|
focus_item = request.form.get('focus_but')
|
|
|
@@ -31,13 +31,18 @@ def market():
|
|
|
def profile():
|
|
|
form = UPForm()
|
|
|
form2 = PicForm()
|
|
|
+ user_bid_hist = collector.user_bid_hist(current_user.id)
|
|
|
|
|
|
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 focus_item and collector.check_art_listing(focus_item):
|
|
|
+ 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'))
|
|
|
+ elif focus_item and not collector.check_art_listing(focus_item):
|
|
|
+ pass
|
|
|
+
|
|
|
|
|
|
if form2.validate_on_submit():
|
|
|
print('passsing')
|
|
|
@@ -73,7 +78,8 @@ def profile():
|
|
|
my_art = my_art,
|
|
|
my_creation = my_creation,
|
|
|
form = form,
|
|
|
- form2 = form2
|
|
|
+ form2 = form2,
|
|
|
+ ubh = user_bid_hist
|
|
|
)
|
|
|
|
|
|
@dashboards.route('/create_art', methods=['GET', 'POST'])
|
|
|
@@ -85,6 +91,7 @@ def create():
|
|
|
|
|
|
# check POST req
|
|
|
if form.validate_on_submit():
|
|
|
+ print('this passes')
|
|
|
new_art = form.upload.data
|
|
|
art_name = form.art_name.data
|
|
|
art_desc = form.art_desc.data
|
|
|
@@ -92,7 +99,7 @@ def create():
|
|
|
buyout_price = form.buyout_price.data
|
|
|
close_date = form.close_date.data
|
|
|
|
|
|
- # this may be redundant now that we have WTForms ###
|
|
|
+ # For minting Art
|
|
|
if tools.check_fields([new_art, art_name, min_price, buyout_price, close_date]):
|
|
|
if new_art and new_art.filename != '' and cf.allowed_file(new_art.filename):
|
|
|
designated_fn = cf.sanitize(new_art.filename)
|
|
|
@@ -100,27 +107,74 @@ def create():
|
|
|
dispatch.mint(designated_fn, art_name, art_desc, min_price, buyout_price, close_date)
|
|
|
flash('Minted & Listed!', category='success')
|
|
|
|
|
|
+ # For re-Listing Art
|
|
|
+ if not new_art:
|
|
|
+ new_art = request.form.get('web_group') # fetch filehash
|
|
|
+ if new_art:
|
|
|
+ # get Art obj from filehash
|
|
|
+ art_obj = collector.get_art_obj(new_art)
|
|
|
+ # dispatch re-list function
|
|
|
+ dispatch.list_item(
|
|
|
+ art_obj.dname,
|
|
|
+ art_name,
|
|
|
+ art_desc,
|
|
|
+ min_price,
|
|
|
+ buyout_price,
|
|
|
+ close_date,
|
|
|
+ art_obj.filehash
|
|
|
+ )
|
|
|
+ flash('Listed!', category='success')
|
|
|
+
|
|
|
+
|
|
|
return render_template('create_art.html', user = current_user, form = form, av_art = available_art)
|
|
|
|
|
|
-@dashboards.route('/search')
|
|
|
+@dashboards.route('/search', methods=['GET', 'POST'])
|
|
|
@login_required
|
|
|
def search():
|
|
|
return render_template('search.html', user = current_user)
|
|
|
|
|
|
-@dashboards.route('/detail')
|
|
|
+@dashboards.route('/detail', methods=['GET', 'POST'])
|
|
|
@login_required
|
|
|
def detail():
|
|
|
-
|
|
|
focus = None
|
|
|
|
|
|
# Collects details of the listing based on the
|
|
|
# focus pointer of the user
|
|
|
- return_list = collector.market_listing()
|
|
|
+ # focus is the return of join_art_list_table in collector
|
|
|
+ return_list = collector.join_art_list_table()
|
|
|
for item in return_list:
|
|
|
if item[11] == current_user.focus: # comparing hash
|
|
|
focus = item
|
|
|
break
|
|
|
|
|
|
owner_obj = collector.find_user_obj(focus[2])
|
|
|
+ item_bid_hist = collector.item_bid_hist(current_user.focus)
|
|
|
+
|
|
|
+ # New Bid
|
|
|
+ form = BidForm()
|
|
|
|
|
|
- return render_template('detail_art.html', user = current_user, detail = focus, own_uname = owner_obj.username)
|
|
|
+ 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')
|
|
|
+ return redirect(url_for('dashboards.profile'))
|
|
|
+ # checking if bid is higher than minimum bidding price
|
|
|
+ elif user_bid and user_bid > focus[7]:
|
|
|
+ dispatch.enter_bid(user_bid, focus)
|
|
|
+ flash('Bid set! Good luck!', category='success')
|
|
|
+ else:
|
|
|
+ flash('Your Bid Price is too low!', category='error')
|
|
|
+ return redirect(url_for('dashboards.detail'))
|
|
|
+
|
|
|
+
|
|
|
+ return render_template(
|
|
|
+ 'detail_art.html',
|
|
|
+ user = current_user,
|
|
|
+ detail = focus,
|
|
|
+ own_uname = owner_obj.username,
|
|
|
+ form = form,
|
|
|
+ ibh = item_bid_hist
|
|
|
+ )
|