示例#1
0
文件: user.py 项目: HEW2meiG/HEW2
def userdata_likes(user_code):
    user = User.select_user_by_user_code(user_code)
    if user is None:
        return redirect(url_for('route.home'))
    # ログイン中のユーザーがユーザーページのユーザーをフォローしているかの判定
    followed = UserConnect.followed_exists(user.User_id)
    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)
    # ユーザーが出品した商品
    sell_items = Sell.select_sell_by_user_id(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)
    # ユーザーがいいねした商品
    items = Likes.likes_join_sell(Sell, 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=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(sell_items), r_user_list=r_user_list
    )
示例#2
0
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)
示例#3
0
def sell_delete():
    form = SellUpdateFlgAndDeleteForm(request.form)
    if request.method == 'POST':
        with db.session.begin(subtransactions=True):
            Sell.delete_sell(form.Sell_id.data)
            BrowsingHistory.delete_b_history(form.Sell_id.data)
            Likes.delete_all_like(form.Sell_id.data)
        db.session.commit()
        flash('削除しました')
        return redirect(url_for('history.sell_on_display'))
    return redirect(url_for('route.home'))
示例#4
0
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)
示例#5
0
文件: route.py 项目: HEW2meiG/HEW2
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)
示例#6
0
文件: item.py 项目: HEW2meiG/HEW2
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)
示例#7
0
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))
示例#8
0
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)
示例#9
0
文件: route.py 项目: HEW2meiG/HEW2
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)
示例#10
0
文件: route.py 项目: HEW2meiG/HEW2
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)
示例#11
0
 def likes_count(sell_id):
     """いいねの数をカウントして返す"""
     all_likes = Likes.select_likes_by_sell_id(sell_id)
     return len(all_likes)