Exemple #1
0
def todolist_count():
    """やることリストの数をカウントして返す"""
    count = 0
    user_id = current_user.get_id()
    items = Sell.select_sall_status(user_id)
    for item in items:
        # 出品者
        if item.User_id==user_id:
            buy_data = Buy.select_buy_by_sell_id(item.Sell_id)
            rating = Rating.select_count_sell_id_to_user_id(item.Sell_id, user_id)
            # 未発送
            if item.has_sent == item.has_got == False:
                count += 1
            # 発送済みで受け取り・評価待ち
            elif item.has_sent == True and item.has_got == False:
                count += 0
            # 受け取り済みで相手が相互評価して自分がしてない
            elif item.has_sent == item.has_got == True and rating == 1:
                count += 1
        #購入者 
        else:
            rating = Rating.select_count_sell_id_to_user_id(item.Sell_id, item.User_id)
            # 発送済みで商品を受取ってない
            if item.has_sent == True and item.has_got == False:
                count += 1
            # 発送待ち
            elif item.has_sent == item.has_got == False:
                count += 0
            # 評価待ち
            elif item.has_sent == item.has_got == True:
                count += 0
    return dict(todolist_count=count)
Exemple #2
0
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)
Exemple #3
0
def buy_complete(item_id):
    sell = Sell.select_sell_by_sell_id(item_id)
    buy = Buy.select_buy_by_sell_id(item_id)
    # レコメンドキャッシュのクリア
    # 読み込み速度の問題によりデモではキャッシュクリアを行わない
    # getRecommendations.cache_clear()
    # topMatches.cache_clear()
    return render_template('buy/buy_complete.html', item=sell, buy=buy)
Exemple #4
0
def transaction(item_id):
    """取引画面処理"""
    item = Sell.select_sell_by_sell_id(item_id)
    buy = Buy.select_buy_by_sell_id(item_id)
    shippingaddress = ShippingAddress.search_shippingaddress(buy.ShippingAddress_id)
    messageform = DealMessageForm(request.form)
    messages = DealMessage.get_messages_by_sell_id(item_id)
    noticeform = NoticeRatingForm(request.form)
    # ログイン中のユーザーが出品者だった場合
    if current_user.User_id == item.User_id:
        dest_user = User.select_user_by_id(buy.User_id)
    # ログイン中のユーザーが購入者だった場合
    elif current_user.User_id == buy.User_id:
        dest_user = User.select_user_by_id(item.User_id)
    read_message_ids = [message.DealMessage_id for message in messages if (not message.is_read) and (message.from_user_id == int(dest_user.User_id))]
    if read_message_ids:
        with db.session.begin(subtransactions=True):
            # is_readをTrueに更新
            DealMessage.update_is_read_by_ids(read_message_ids)
        db.session.commit()
    not_checked_message_ids = [message.DealMessage_id for message in messages if message.is_read and (not message.is_checked) and (message.from_user_id == int(current_user.User_id))]
    if not_checked_message_ids:
        with db.session.begin(subtransactions=True):
            DealMessage.update_is_checked_by_ids(not_checked_message_ids)
        db.session.commit()
    if request.method == 'POST' and messageform.validate(read_message_ids):
        dealmessage = DealMessage(
            Sell_id = item_id,
            to_user_id = dest_user.User_id,
            from_user_id = current_user.User_id,
            message = messageform.message.data
        )
        # データベース登録処理
        with db.session.begin(subtransactions=True):
            dealmessage.create_new_dealmessage()
        db.session.commit()
        return redirect(url_for('transaction.transaction', item_id=item_id))
    return render_template(
        'transaction/transaction.html',
        item=item,
        buy=buy,
        shippingaddress=shippingaddress,
        messageform=messageform,
        messages=messages,
        dest_user=dest_user,
        noticeform=noticeform
    )
Exemple #5
0
 def decorated_function(*args, **kwargs):
     sell_id = kwargs['item_id']
     sell = Sell.select_sell_by_sell_id(sell_id)
     buy = Buy.select_buy_by_sell_id(sell_id)
     user_id = current_user.get_id()
     if sell is None or buy is None:
         return redirect(url_for('route.home'))
     else:
         if sell.User_id != user_id and buy.User_id != user_id:
             return redirect(url_for('route.home'))
         elif not sell.sell_flg:
             return redirect(url_for('route.home'))
         elif not sell.is_active:
             return redirect(url_for('route.home'))
         elif sell.deal_status == Deal_status['出品中']:
             return redirect(url_for('route.home'))
     return func(*args, **kwargs)
Exemple #6
0
def notice_rating(item_id):
    sell = Sell.select_sell_by_sell_id(item_id)
    buy = Buy.select_buy_by_sell_id(item_id)
    form = NoticeRatingForm(request.form)
    if request.method == 'POST' and form.validate():
        if form.notice_condition.data == 'has_sent':
            with db.session.begin(subtransactions=True):
                sell.has_sent = True
                sell.update_at = datetime.datetime.now()
            db.session.commit()
            flash('発送通知を送信しました。')
            return redirect(url_for('transaction.transaction', item_id=item_id))
        if form.notice_condition.data == 'has_got':
            rating = Rating(
                Sell_id = item_id,
                to_user_id = sell.User_id,
                from_user_id = current_user.User_id,
                rating = form.rating.data,
                rating_message = form.rating_message.data
            )
            with db.session.begin(subtransactions=True):
                rating.create_new_rating()
                sell.has_got = True
                sell.update_at = datetime.datetime.now()
            db.session.commit()
            flash('受け取り確認と評価を送信しました')
            return redirect(url_for('transaction.transaction', item_id=item_id))
        if form.notice_condition.data == 'seller_rating':
            rating = Rating(
                Sell_id = item_id,
                to_user_id = buy.User_id,
                from_user_id = current_user.User_id,
                rating = form.rating.data,
                rating_message = form.rating_message.data
            )
            with db.session.begin(subtransactions=True):
                rating.create_new_rating()
                sell.deal_status = Deal_status['取引済み']
                sell.update_at = datetime.datetime.now()
            db.session.commit()
            flash('評価を送信しました。取引が完了しました。')
            return redirect(url_for('transaction.transaction', item_id=item_id))
    return redirect(url_for('transaction.transaction', item_id=item_id))
Exemple #7
0
def todolist():
    """やることリスト"""
    user_id = current_user.get_id()
    now = datetime.datetime.now()
    items = Sell.select_sall_status(user_id)
    todolists =[]
    for item in items:
        elapsed = now - item.update_at
        todolist_data = {"item" : None, "status" : 0, "elapsed_time" : "", "partner_username" : "", "partner_user_code" : "", "partner_picture_path" : ""}
        # 出品者
        if item.User_id==user_id:
            buy_data = Buy.select_buy_by_sell_id(item.Sell_id)
            todolist_data["partner_username"] = User.select_user_by_id(buy_data.User_id).username
            todolist_data["partner_user_code"] = User.select_user_by_id(buy_data.User_id).user_code
            todolist_data["partner_picture_path"] = User.select_user_by_id(buy_data.User_id).picture_path
            rating = Rating.select_count_sell_id_to_user_id(item.Sell_id, user_id)
            # 未発送
            if item.has_sent == item.has_got == False:
                todolist_data["status"] = 1
            # 発送済みで受け取り・評価待ち
            elif item.has_sent == True and item.has_got == False:
                todolist_data["status"] = 4
            # 受け取り済みで相手が相互評価して自分がしてない
            elif item.has_sent == item.has_got == True and rating == 1:
                todolist_data["status"] = 2
                rating_datas=Rating.select_sell_id_to_user_id(item.Sell_id, user_id)
                for rating_data in rating_datas:
                    print(rating_data.update_at)
                    elapsed = now - rating_data.update_at
                    print(elapsed.days/7)
        #購入者 
        else:
            todolist_data["partner_username"] = User.select_user_by_id(item.User_id).username
            todolist_data["partner_user_code"] = User.select_user_by_id(item.User_id).user_code
            todolist_data["partner_picture_path"] = User.select_user_by_id(item.User_id).picture_path
            rating = Rating.select_count_sell_id_to_user_id(item.Sell_id, item.User_id)
            # 発送済みで商品を受取ってない
            if item.has_sent == True and item.has_got == False:
                todolist_data["status"] = 3
            # 発送待ち
            elif item.has_sent == item.has_got == False:
                todolist_data["status"] = 4
            # 評価待ち
            elif item.has_sent == item.has_got == True:
                todolist_data["status"] = 4
        print("*"*100)
        print(elapsed.days/7)
        # 経過時間
        if not elapsed.days//365 == 0:
            elapsed_time = str(elapsed.days//365) + "年"
        elif not elapsed.days//30 == 0:
            elapsed_time = str(elapsed.days//30) + "ヶ月"
        elif not elapsed.days//7 == 0:
            elapsed_time = str(elapsed.days//7) + "週間"
        elif not elapsed.days == 0:
            elapsed_time = str(elapsed.days) + "日"
        elif not elapsed.seconds//3600 == 0:
            elapsed_time = str(elapsed.seconds//3600) + "時間"
        elif not elapsed.seconds//60 == 0:
            elapsed_time = str(elapsed.seconds//60) + "分"
        else:
            elapsed_time = str(elapsed.seconds) + "秒"
        print(elapsed.seconds//60)
        print("*"*100)
        todolist_data["item"] = item
        todolist_data["elapsed_time"] = elapsed_time
        todolists.append(todolist_data)
        
    return render_template('todolist/todolist.html', todolists=todolists)