def mypagetop(): # ログイン中のユーザーがユーザーページのユーザーをフォローしているかの判定 followed = UserConnect.followed_exists(current_user.User_id) follows = UserConnect.select_follows_by_user_id(current_user.User_id) good_ratings_count, bad_ratings_count = Rating.select_rate_by_user_id( current_user.User_id) # 売上金 sales = Sell.select_sales(current_user.User_id) sales = sales.sumprice # ユーザーが出品した商品 items = Sell.select_sell_by_user_id_sort(current_user.User_id) # 最近見た本 b_items = BrowsingHistory.b_history_join_sell(Sell, current_user.User_id) # ログイン中のユーザーが過去にどの商品をいいねしたかを格納しておく liked_list = [] for item in items: liked = Likes.liked_exists(item.Sell_id) if liked: liked_list.append(item.Sell_id) for item in b_items: liked = Likes.liked_exists(item.Sell_id) if liked: liked_list.append(item.Sell_id) return render_template('mypage/mypage.html', followed=followed, follows_count=len(follows), good_ratings_count=good_ratings_count, bad_ratings_count=bad_ratings_count, items=items, liked_list=liked_list, post_c=len(items), b_items=b_items, sales=sales)
def userdata(user_code): user = User.select_user_by_user_code(user_code) if user is None: return redirect(url_for('route.home')) follows = UserConnect.select_follows_by_user_id(user.User_id) good_ratings_count,bad_ratings_count = Rating.select_rate_by_user_id(user.User_id) # ユーザーが出品した商品 items = Sell.select_sell_by_user_id_sort(user.User_id) # レコメンドリスト if current_user.is_authenticated: r_user_list = u_recommend(user.User_id,current_user.User_id) else: r_user_list = u_recommend(user.User_id) # ログイン中のユーザーがユーザーをフォローしているかの判定 f_users = [] f_users.append(user) f_users.extend(r_user_list) followed_list = [] if current_user.is_authenticated: for f_user in f_users: followed = UserConnect.followed_exists(f_user.User_id) if followed: followed_list.append(f_user.User_id) # ログイン中のユーザーが過去にどの商品をいいねしたかを格納しておく liked_list = [] if current_user.is_authenticated: for item in items: liked = Likes.liked_exists(item.Sell_id) if liked: liked_list.append(item.Sell_id) return render_template( 'user/userdata.html', user=user, followed_list=followed_list, follows_count=len(follows), good_ratings_count=good_ratings_count, bad_ratings_count=bad_ratings_count, items=items, liked_list=liked_list, post_c=len(items), r_user_list=r_user_list )
def buy_in_progress(): """購入取引中履歴""" user_id = current_user.get_id() next_url = prev_url = items = None page = request.args.get('page', 1, type=int) posts = Buy.buy_join_sell_deal_status_page(user_id, 2, page) next_url = url_for('history.buy_in_progress', page=posts.next_num) if posts.has_next else None prev_url = url_for('history.buy_in_progress', page=posts.prev_num) if posts.has_prev else None items = posts.items liked_list = [] if None in items: items = [] next_url = None prev_url = None if current_user.is_authenticated: for item in items: liked = Likes.liked_exists(item.Sell_id) if liked: liked_list.append(item.Sell_id) return render_template('history/buy_history.html', items=items, next_url=next_url, prev_url=prev_url, liked_list=liked_list)
def home(): """ホーム(新着順)""" # セッションの破棄 session.pop('pay_way', None) session.pop('Credit_id', None) session.pop('ShippingAddress_id', None) # 出品状態、有効フラグが有効の商品を新着順に取り出す items = Sell.select_new_sell() # レコメンドリスト r_item_list = [] r_user_list = [] if current_user.is_authenticated: r_item_list, r_user_list = recommend(current_user.User_id) # ログイン中のユーザーが過去にどの商品をいいねしたかを格納しておく liked_list = [] if current_user.is_authenticated: for item in items: liked = Likes.liked_exists(item.Sell_id) if liked: liked_list.append(item.Sell_id) return render_template('home.html', items=items, liked_list=liked_list, r_item_list=r_item_list, r_user_list=r_user_list)
def itemdata(item_id): # セッションの破棄 session.pop('pay_way', None) session.pop('Credit_id', None) session.pop('ShippingAddress_id', None) item = Sell.query.get(item_id) buy_user = "" buy = Buy.select_buy_by_sell_id(item_id) if buy: buy_user = buy.User_id if item is None: return redirect(url_for('route.home')) form = SellUpdateFlgAndDeleteForm(request.form) # ログイン中のユーザーが過去にどの商品をいいねしたかを格納しておく liked_list = [] if current_user.is_authenticated: liked = Likes.liked_exists(item_id) if liked: liked_list.append(item_id) if current_user.is_authenticated: # 閲覧履歴登録処理 browsinghistory = BrowsingHistory( Sell_id = item_id, User_id = current_user.User_id ) with db.session.begin(subtransactions=True): BrowsingHistory.create_new_browsinghistory(browsinghistory) db.session.commit() return render_template('item/itemdata.html', item=item, form=form, liked_list=liked_list, buy_user=buy_user)
def sell_completed(): """出品取引済み履歴""" user_id = current_user.get_id() next_url = prev_url = items = None page = request.args.get('page', 1, type=int) posts = Sell.select_sell_by_deal_status_page(user_id, 3, page) next_url = url_for('history.sell_completed', page=posts.next_num) if posts.has_next else None prev_url = url_for('history.sell_completed', page=posts.prev_num) if posts.has_prev else None items = posts.items liked_list = [] if current_user.is_authenticated: for item in items: liked = Likes.liked_exists(item.Sell_id) if liked: liked_list.append(item.Sell_id) return render_template('history/sell_history.html', items=items, next_url=next_url, prev_url=prev_url, liked_list=liked_list)
def timeline(): """ホーム(タイムライン)""" # セッションの破棄 session.pop('pay_way', None) session.pop('Credit_id', None) session.pop('ShippingAddress_id', None) items = UserConnect.select_timeline_sell(Sell) # レコメンドリスト r_item_list = [] r_user_list = [] r_item_list, r_user_list = recommend(current_user.User_id) # ログイン中のユーザーが過去にどの商品をいいねしたかを格納しておく liked_list = [] for item in items: liked = Likes.liked_exists(item.Sell_id) if liked: liked_list.append(item.Sell_id) return render_template('home.html', items=items, liked_list=liked_list, r_item_list=r_item_list, r_user_list=r_user_list)
def like_ajax(): """いいね機能ajax処理""" sell_id = request.form.get('sell_id', -1, type=int) if sell_id != -1: liked = False like = Likes.liked_exists(sell_id) # すでにいいねしていたら if like: #いいねテーブルから削除する with db.session.begin(subtransactions=True): Likes.delete_like(sell_id) db.session.commit() # いいねしていなければ else: # いいねテーブルに追加する。 likes = Likes(Sell_id=sell_id, User_id=current_user.User_id) with db.session.begin(subtransactions=True): likes.create_new_likes() db.session.commit() liked = True # Sell_idが一致するいいねレコードを抽出 len()で要素数を代入 all_likes = Likes.select_likes_by_sell_id(sell_id) return jsonify(item_id=sell_id, liked=liked, count=len(all_likes))
def hit(): """ホーム(ヒット)""" # セッションの破棄 session.pop('pay_way', None) session.pop('Credit_id', None) session.pop('ShippingAddress_id', None) items = BrowsingHistory.select_hit_sell(Sell) # レコメンドリスト r_item_list = [] r_user_list = [] if current_user.is_authenticated: r_item_list, r_user_list = recommend(current_user.User_id) # ログイン中のユーザーが過去にどの商品をいいねしたかを格納しておく liked_list = [] if current_user.is_authenticated: for item in items: liked = Likes.liked_exists(item.Sell_id) if liked: liked_list.append(item.Sell_id) return render_template('home.html', items=items, liked_list=liked_list, r_item_list=r_item_list, r_user_list=r_user_list)