• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python melons.get_by_id函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中melons.get_by_id函数的典型用法代码示例。如果您正苦于以下问题:Python get_by_id函数的具体用法?Python get_by_id怎么用?Python get_by_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_by_id函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: shopping_cart

def shopping_cart():
    """Display content of shopping cart."""

    # TODO: Display the contents of the shopping cart.
    # The logic here will be something like:
    # - get the list-of-ids-of-melons from the session cart
    
    melon_order = session['cart']

    # - loop over this list:
    order = {} 
    for id in melon_order:
        if id not in order:
            order[id] = (melons.get_by_id(id).common_name, melons.get_by_id(id).price, melon_order.count(id))
        # id = tuple(common_name, price, qty)

    # make a dictiionary within dictionary

    #   - keep track of information about melon types in the cart
    #   - keep track of the total amt ordered for a melon-type
    #   - keep track of the total amt of the entire order
    # - hand to the template the total order cost and the list of melon types



    return render_template("cart.html", order=order)
        )
开发者ID:kellyhiggins,项目名称:shopping-site,代码行数:27,代码来源:shoppingsite.py


示例2: shopping_cart

def shopping_cart():
    """Display content of shopping cart."""

    # TODO: Display the contents of the shopping cart.

    # The logic here will be something like:
    #
    # - get the list-of-ids-of-melons from the session cart
    # - loop over this list:
    #   - keep track of information about melon types in the cart
    #   - keep track of the total amt ordered for a melon-type
    #   - keep track of the total amt of the entire order
    # - hand to the template the total order cost and the list of melon types

    total_order_cost = 0

    # list of tuples of name, qty, price, total
    individual_melon_order = []

    for melon_id in session["cart"]:
        melon_quantity = session["cart"].count(melon_id)
        melon_name = melons.get_by_id(melon_id).common_name
        melon_price = melons.get_by_id(melon_id).price
        melon_total = melon_quantity * melon_price
        melon_tuple = (melon_name, melon_quantity, melon_price, melon_total)
        total_order_cost += melon_total
        if melon_tuple not in individual_melon_order:
            individual_melon_order.append(melon_tuple)

    return render_template("cart.html", melon_order=individual_melon_order, order_total=total_order_cost)
开发者ID:tjhakseth,项目名称:Shopping_site,代码行数:30,代码来源:shoppingsite.py


示例3: shopping_cart

def shopping_cart():
    """Display content of shopping cart."""

    # TODO: Display the contents of the shopping cart.

    # The logic here will be something like:
    #
    # - get the list-of-ids-of-melons from the session cart
    melon_order = session['cart']

    total_melons = {}

    for item in melon_order:
        total_melons[item] = {}
        total_melons[item]["count"] = total_melons[item].get("count", 0) + 1
        total_melons[item]["price"] = melons.get_by_id(item).price
        total_melons[item]["common_name"] = melons.get_by_id(item).common_name
        total_melons[item]["total"] = total_melons[item]["price"] * total_melons[item]["count"]


    # - loop over this list:
    #   - keep track of information about melon types in the cart
    #   - keep track of the total amt ordered for a melon-type
    #   - keep track of the total amt of the entire order
    # - hand to the template the total order cost and the list of melon types

    return render_template("cart.html", dictionary=total_melons)
开发者ID:cabbageyful,项目名称:HB-shopping-site,代码行数:27,代码来源:shoppingsite.py


示例4: shopping_cart

def shopping_cart():
    """Display content of shopping cart."""

    order_total = 0

    melon_cart_ids = session.get("cart",[])

    cart={}
    
    for melon_id in melon_cart_ids:
        if melon_id in cart:
            melon_info =cart[melon_id]
        else:
            melon_type=melons.get_by_id(melon_id)
            melon_info=cart[melon_id] = {
                "melon_name":melon_type.common_name,
                "melon_price":melon_type.price,
                "qty":0,
                "total_cost":0
            }

        melon_info["qty"] += 1
        melon_info["total_cost"] += melon_info["melon_price"]

        order_total += melon_info["melon_price"]

    cart = cart.values()



    return render_template("cart.html",
                            cart=cart,
                            order_total=order_total
                            )
开发者ID:mlpeters12,项目名称:Sessions-shoppingsite,代码行数:34,代码来源:shoppingsite.py


示例5: shopping_cart

def shopping_cart():
    """Display content of shopping cart."""
    if 'cart' not in session:
        session['cart'] = []

    melons_in_cart = []
    total = 0
    for num in session['cart']:
        current_melon = melons.get_by_id(num)
        total += current_melon.price
        if current_melon in melons_in_cart:
            current_melon.quantity += 1
        else:
            current_melon.quantity = 1
            melons_in_cart.append(current_melon)


    # TODO: Display the contents of the shopping cart.

    # The logic here will be something like:

    # - get the list-of-ids-of-melons from the session cart
    # see if session has a cart; if not add one.
    # - loop over this list:
    #   - keep track of information about melon types in the cart
    #   - keep track of the total amt ordered for a melon-type
    #   - keep track of the total amt of the entire order
    # - hand to the template the total order cost and the list of melon types

    return render_template("cart.html", melons=melons_in_cart, grand_total=total)
开发者ID:karayount,项目名称:shopping-site,代码行数:30,代码来源:shoppingsite.py


示例6: shopping_cart

def shopping_cart():
    """Display content of shopping cart."""
   
    # TODO: Display the contents of the shopping cart.

    # The logic here will be something like:
    #
    # - get the list-of-ids-of-melons from the session cart
    # - loop over this list:
    #   - keep track of information about melon types in the cart
    #   - keep track of the total amt ordered for a melon-type
    #   - keep track of the total amt of the entire order
    # - hand to the template the total order cost and the list of melon types
    total_cost = 0
    melon_items = {}
    for melon_id in session["cart"]:#iterate through the cart list
        quantity = session["cart"].count(melon_id)
        #current melon is melon object
        current_melon = melons.get_by_id(melon_id)
        melon_total = quantity * current_melon.price 
        total_cost += melon_total

        melon_items[melon_id] = {"melon": current_melon.common_name, "qty":quantity, "price":current_melon.price, "mel_total": melon_total}


    return render_template("cart.html", total_cost = total_cost, melon_items=melon_items)
开发者ID:Ihyatt,项目名称:shopping-site,代码行数:26,代码来源:shoppingsite.py


示例7: add_to_cart

def add_to_cart(id):
    """Add a melon to cart and redirect to shopping cart page.

    When a melon is added to the cart, redirect browser to the shopping cart
    page and display a confirmation message: 'Successfully added to cart'.
    """

    # TODO: Finish shopping cart functionality

    # The logic here should be something like:
    #
    # - add the id of the melon they bought to the cart in the session

    # on adding an item, check to see if the session contains a cart
    # if no, add a new cart to the session
    # append the melon id under consideration to our cart
    if session['cart']:
        session["cart"].append(id)
    else:
        session['cart'] = [id]

    # flash the message indicating the melon was added to the cart
    flash('You have added ' + melons.get_by_id(id).common_name + ' to your cart!!!')


# redirect user to shopping cart route
    return redirect("/cart")
开发者ID:kellyhiggins,项目名称:shopping-site,代码行数:27,代码来源:shoppingsite.py


示例8: shopping_cart

def shopping_cart():
    """Display content of shopping cart."""

    melon_list = []

    total_cost = 0

    if "cart" in session:
        melon_id_list = session['cart']
        melon_cost = 0

        for m_id in melon_id_list:
            melon = melons.get_by_id(m_id)
            melon_cost += melon.price
            print melon
            melon_list.append(melon)

        total_cost = melon_cost

    melon_order = {}

    for melon in melon_list:
        melon_order[melon] = {
                                "price": melon.price,
                                "quantity": melon_order[melon].get("quantity", 0) + 1,
                                "sub_total": melon_order[melon]["price"] * melon_order[melon]["quantity"],
        }


    print melon_order

        # total_cost = melon_cost 

    return render_template("cart.html", melon_list=melon_list, 
                                        total_cost=total_cost)
开发者ID:mcbishop,项目名称:shopping-site,代码行数:35,代码来源:shoppingsite.py


示例9: add_to_cart

def add_to_cart(melon_id):
    """Add a melon to cart and redirect to shopping cart page.

    When a melon is added to the cart, redirect browser to the shopping cart
    page and display a confirmation message: 'Successfully added to cart'.
    """

    # TODO: Finish shopping cart functionality

    # The logic here should be something like:
    #
    # - add the id of the melon they bought to the cart in the session
    melon = melons.get_by_id(melon_id)

    # Check if the melon ID exists in the session. If it doesn't, add
    # the ID as a key with a quantity of 0 as its value, and add 1. 
    # Otherwise, add 1 to the quantity.

    session.setdefault("cart", []).append(melon_id)

    print "#########"
    print melon
    print "#########"
    print session
    print "#########"

    flash("You have added {} to your cart.".format(melon.common_name))
    return redirect('/melons')
开发者ID:lindsaynchan,项目名称:hb_melon_shopping_list,代码行数:28,代码来源:shoppingsite.py


示例10: shopping_cart

def shopping_cart():
    """Display content of shopping cart."""

    # TODO: Display the contents of the shopping cart.

    # The logic here will be something like:
    #
    # - get the list-of-ids-of-melons from the session cart
    # - loop over this list:
    #   - keep track of information about melon types in the cart
    current_cart = session['cart']

    for melon_id in current_cart:
        melon_info = melons.get_by_id(melon_id)
        # melon_price = melon_info.price
        # melon_name = melon_info.common_name

        print melon_info

    # - hand to the template the total order cost and the list of melon types
    
    print "*" * 20
    #   - keep track of the total amt ordered for a melon-type
    print request.args.get("quantity")
    # print type(melon_quantity)
    #   - keep track of the total amt of the entire order
    return render_template("cart.html")
开发者ID:ibhan88,项目名称:Shopping-Site,代码行数:27,代码来源:shoppingsite.py


示例11: shopping_cart

def shopping_cart():
    """Display content of shopping cart."""

    list_ids = session['cart']
    dict_melon = {}

    for each_id in list_ids:

        count_ids = list_ids.count(each_id)
        dict_melon[each_id] = [count_ids]
        dict_melon[each_id].append()    

    melon = melons.get_by_id(each_id)    
    # TODO: Display the contents of the shopping cart.

    # The logic here will be something like:
    #
    # - get the list-of-ids-of-melons from the session cart
    # - loop over this list:
    #   - keep track of information about melon types in the cart
    #   - keep track of the total amt ordered for a melon-type
    #   - keep track of the total amt of the entire order
    # - hand to the template the total order cost and the list of melon types

    return render_template("cart.html")
开发者ID:jeanhl,项目名称:HB-shopping-cart,代码行数:25,代码来源:shoppingsite.py


示例12: shopping_cart

def shopping_cart():
    """Display content of shopping cart."""
    
    cart = {}

    for item in session["cart"]:
        if item in cart:
            cart[item] += 1
        else:
            cart[item] = 1
    print cart

    # TODO make this really work
    for melon_id in cart.keys():
        melon = melons.get_by_id(melon_id)
        melon_name = melon.common_name
        melon_price = melon.price
        melon_quantity = cart[melon_id]


    # TODO: Display the contents of the shopping cart.

    # The logic here will be something like:
    #
    # - get the list-of-ids-of-melons from the session cart
    # - loop over this list:
    #   - keep track of information about melon types in the cart
    #   - keep track of the total amt ordered for a melon-type
    #   - keep track of the total amt of the entire order
    # - hand to the template the total order cost and the list of melon types

    return render_template("cart.html")
开发者ID:ohrely,项目名称:melon-shopping,代码行数:32,代码来源:shoppingsite.py


示例13: shopping_cart

def shopping_cart():
    """Display content of shopping cart."""

    # TODO: Display the contents of the shopping cart.

    # The logic here will be something like:
    #
    # - get the list-of-ids-of-melons from the session cart
    # - loop over this list:
    #   - keep track of information about melon types in the cart
    #   - keep track of the total amt ordered for a melon-type
    #   - keep track of the total amt of the entire order
    # - hand to the template the total order cost and the list of melon types

    ordered_melons = {}
    total = 0

    if 'cart' in session:
        for melon_id in set(session['cart']):

            ordered_melons[melon_id] = {}
            ordered_melons[melon_id]['quantity'] = session["cart"].count(melon_id)
            melon = melons.get_by_id(melon_id)
            ordered_melons[melon_id]['name'] = melon.common_name
            ordered_melons[melon_id]['price'] = melon.price
            total = total + (ordered_melons[melon_id]['quantity'] * ordered_melons[melon_id]['price'])        

    # flash(ordered_melons) # Test code to see dictionary

    return render_template("cart.html", ordered_melons=ordered_melons, total=total)
开发者ID:ashleyhsia0,项目名称:hb-shopping-cart,代码行数:30,代码来源:shoppingsite.py


示例14: add_to_cart

def add_to_cart(id):
    """Add a melon to cart and redirect to shopping cart page.

    When a melon is added to the cart, redirect browser to the shopping cart
    page and display a confirmation message: 'Successfully added to cart'.
    """
    melon = melons.get_by_id(id)
    melon_name = melon.common_name
    print melon_name
    # TODO: Finish shopping cart functionality

    # - add the id of the melon they bought to the cart in the session
    
    # if session does not contain a cart, create a new cart
    if session.get('cart', None) is None:
        session['cart'] = []

    #append the melon id to cart list
    session['cart'].append(id)
    # print session['cart']

    # flash mesage
    msg = "Added %s to cart." % melon_name
    flash(msg) #flask.flash(message, category='message')

    return redirect("/cart")
开发者ID:pdecks,项目名称:shopping-list,代码行数:26,代码来源:shoppingsite.py


示例15: shopping_cart

def shopping_cart():
    """Display content of shopping cart."""

    # TODO: Display the contents of the shopping cart.

    # The logic here will be something like:
    #
    # - get the list-of-ids-of-melons from the session cart
    # - loop over this list:
    #   - keep track of information about melon types in the cart
    #   - keep track of the total amt ordered for a melon-type
    #   - keep track of the total amt of the entire order
    # - hand to the template the total order cost and the list of melon types

    # creates an empty dictionary to store information about each 
    # melon in the specific user's cart
    cart = {}

    # creates a list of id's of melon's in the user's cart
    # if the cart is empty, the list will default to []
    melon_ids_in_cart = session.get("cart", [])

    # iterates through the melon id's in cart to update quantities
    # keeps track of total price for each melon
    for melon_id in melon_ids_in_cart:

        # if the melon is not already in the cart, create a key of melon id
        # the value is a dictionary containing melon info
        if melon_id not in cart:
            melon_obj = melons.get_by_id(melon_id)
            cart[melon_id] = {
                "melon_name": melon_obj.common_name,
                "qty_ordered": 1,
                "unit_price": melon_obj.price,
                "total_price": melon_obj.price,
            }
            
        # if melon is already in cart, increment quantity and total cost
        else:
            cart[melon_id]["qty_ordered"] += 1
            cart[melon_id]["total_price"] = (
                cart[melon_id]["qty_ordered"] * cart[melon_id]["unit_price"])

        # formats numerical values as monetary strings in a new key: value
        # pair in the melon dictionary we created above
        cart[melon_id]["unit_price_str"] = "${:,.2f}".format(
            cart[melon_id]["unit_price"])
        cart[melon_id]["total_price_str"] = "${:,.2f}".format(
            cart[melon_id]["total_price"])

    # initialize variable to count total cost        
    total = 0

    # for every melon in cart, add the total price to the total
    for melon in cart:
        total += cart[melon]["total_price"]

    total = "${:,.2f}".format(total)

    return render_template("cart.html", cart=cart, total=total)
开发者ID:lyoness1,项目名称:shopping-site,代码行数:60,代码来源:shoppingsite.py


示例16: shopping_cart

def shopping_cart():
    """Display content of shopping cart."""

    # TODO: Display the contents of the shopping cart.

    # The logic here will be something like:
    #
    # - get the list-of-ids-of-melons from the session cart
    # - loop over this list:
    #   - keep track of information about melon types in the cart
    #   - keep track of the total amt ordered for a melon-type
    #   - keep track of the total amt of the entire order
    # - hand to the template the total order cost and the list of melon types

    melon_data = {}

    for melon_id in session['cart']:
        melon_data.setdefault(melon_id, {})
        melon_data[melon_id].setdefault('count', 0)
        melon_data[melon_id]['count'] += 1
        melon_data[melon_id]['melon'] = melons.get_by_id(melon_id)

    print melon_data

    return render_template("cart.html",
                           melon_data=melon_data)
开发者ID:ainjii,项目名称:20160720_shopping_cart,代码行数:26,代码来源:shoppingsite.py


示例17: shopping_cart

def shopping_cart():
    """Display content of shopping cart."""

    # TODO: Display the contents of the shopping cart.

    # The logic here will be something like:
    #
    # - get the list-of-ids-of-melons from the session cart
    # - loop over this list:
    #   - keep track of information about melon types in the cart
    #   - keep track of the total amt ordered for a melon-type
    #   - keep track of the total amt of the entire order
    # - hand to the template the total order cost and the list of melon types

    # import pdb; pdb.set_trace()

    melons_in_cart_id = session["cart"].keys()
    cart_melons = {}
    total = 0.00
    
    for melon_id in melons_in_cart_id:
        melon_id = int(melon_id)
        melon_type = melons.get_by_id(melon_id)
        cart_melons[melon_id] = {}
        cart_melons[melon_id]["common_name"] = melon_type.common_name
        cart_melons[melon_id]["price"] = melon_type.price
        cart_melons[melon_id]["qty"] = session["cart"][str(melon_id)]
        total += cart_melons[melon_id]["qty"] * cart_melons[melon_id]["price"]

    # print cart_melons


    return render_template("cart.html",
                            cart_melons = cart_melons, total=total)
开发者ID:kelseyoo14,项目名称:shopping-site,代码行数:34,代码来源:shoppingsite.py


示例18: shopping_cart

def shopping_cart():
    """Display content of shopping cart."""

    # TODO: Display the contents of the shopping cart.

    # The logic here will be something like:
    #
    # - get the list-of-ids-of-melons from the session cart
    # - loop over this list:
    #   - keep track of information about melon types in the cart
    #   - keep track of the total amt ordered for a melon-type
    #   - keep track of the total amt of the entire order
    # - hand to the template the total order cost and the list of melon types

    session["cart"] = session.get("cart",[])

    melon_cart_dict = {}
    #Iterating over the list of id's in our cart. 
    for melon_id in session["cart"]:
        #Calling function get_by_id to get melon object associated with id. 
        melon_object = melons.get_by_id(melon_id)
        #adding a key to the dictionary such that the key is the id, and
        #value is the returned melon object.
        melon_cart_dict[melon_id] = melon_cart_dict.get(melon_id, melon_object)
        print melon_object.quantity
        melon_object.quantity += 1
        print melon_object.quantity

    return render_template("cart.html", my_cart=melon_cart_dict)
开发者ID:khardsonhurley,项目名称:hb_shopping-sites,代码行数:29,代码来源:shoppingsite.py


示例19: shopping_cart

def shopping_cart():
    """Display content of shopping cart."""

    # TODO: Display the contents of the shopping cart.

    # The logic here will be something like:
    #
    # - get the list-of-ids-of-melons from the session cart
    # - loop over this list:
    #   - keep track of information about melon types in the cart
    #   - keep track of the total amt ordered for a melon-type
    #   - keep track of the total amt of the entire order
    # - hand to the template the total order cost and the list of melon types
    melons_in_cart = {}
    if session:
        melon_id_list = session["cart"]
        for mel_id in melon_id_list:
            melon_to_add = melons.get_by_id(mel_id)
            melons_in_cart[melon_to_add] = melons_in_cart.get(melon_to_add, 0) + 1

        print melons_in_cart

    else:
        flash("Your cart is empty.")

    return render_template("cart.html", melon_dict=melons_in_cart)
开发者ID:Nmargolis,项目名称:shopping-site2,代码行数:26,代码来源:shoppingsite.py


示例20: shopping_cart

def shopping_cart():
    """Display content of shopping cart."""

    # TODO: Display the contents of the shopping cart.

    # The logic here will be something like:
    #
    # - get the list-of-ids-of-melons from the session cart
    # - loop over this list:
    #   - keep track of information about melon types in the cart
    #   - keep track of the total amt ordered for a melon-type
    #   - keep track of the total amt of the entire order
    # - hand to the template the total order cost and the list of melon types
    # import pdb; pdb.set_trace()
    cart_dict = {}

    for id in session["cart"]:
        melon = melons.get_by_id(id)

        if id not in cart_dict:
            cart_dict[melon] = 1
        else:
            cart_dict[melon] += 1

    print cart_dict
    return render_template("cart.html", cart_dict=cart_dict)
开发者ID:sabellachan,项目名称:shopping-cart,代码行数:26,代码来源:shoppingsite.py



注:本文中的melons.get_by_id函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python orgformat.OrgFormat类代码示例发布时间:2022-05-27
下一篇:
Python melons.get_all函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap