当前位置: 首页>>代码示例>>Python>>正文


Python Gift.get_by_id方法代码示例

本文整理汇总了Python中apps.gift.models.Gift.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Gift.get_by_id方法的具体用法?Python Gift.get_by_id怎么用?Python Gift.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在apps.gift.models.Gift的用法示例。


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

示例1: show

# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import get_by_id [as 别名]
def show(request):
    gifts = []
    order_items = request.session.get('order', {})
    if not order_items:
        return render_to_response('cart/show.html', {'gifts':gifts})
    total_price = 0
    for k, val in order_items.iteritems():
        gift = Gift.get_by_id(k)
        if gift:
            gift.count = val
            gifts.append(gift)
            total_price += gift.price * val
    form = OrderForm()
    if request.method == 'POST' and form.validate(request.form):
        order = form.save(commit=False)
        order.email = request.form.get('email', None)
        order.address = request.form.get('address', None)
        order.put()
        for k, v in request.session.get('order', {}).items():
            gift = Gift.get_by_id(k)
            if gift:
                oi = OrderItem(gift_id=gift, count=v)
                oi.in_order = order
                oi.put()
        clear_cart(request)
        return render_to_response('cart/confirm_complete.html')
    return render_to_response('cart/show.html', {'gifts':gifts,
                                                 'total_price':total_price,
                                                 'form':form.as_widget()})
开发者ID:gmist,项目名称:f-toy,代码行数:31,代码来源:views.py

示例2: sync_add_image

# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import get_by_id [as 别名]
def sync_add_image(request, uid):
    logging.info("Add image for gift with key: %s" % uid)
    mem_key = 'sync/add_image/%s' % uid
    img_url = memcache.get(mem_key)
    if img_url:
        memcache.delete(mem_key)
        img = urlfetch.fetch(img_url)
        if img.status_code == 200:
            thumb = img.content
            gift = Gift.get_by_id(uid)
            if gift:
                title = gift.name.replace('"', '"')
                thumb_img = ThumbImage()
                content_type = 'image/jpeg'
                thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(700, 700,),
                                        title=title, content_type=content_type)
                thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(400, 400, ),
                                        title=title, content_type=content_type)
                thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(200, 200, ),
                                        title=title, content_type=content_type)
                thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(100, 100, ),
                                        title=title, content_type=content_type)
                if not gift.thumbs.count():
                    thumb_img.main_gift = gift
                thumb_img.gift = gift
                thumb_img.put()
    return render_json_response({'api_msg': 'Ok', 'api_success': True})
开发者ID:gmist,项目名称:f-toy,代码行数:29,代码来源:views.py

示例3: add_image_task

# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import get_by_id [as 别名]
def add_image_task(request, task_id):
    data = memcache.get(task_id)
    memcache.delete(task_id)
    if not data or not data.get('gift_id') or not data.get('img_url'):
        return render_to_response('empty.html')
    img = urlfetch.fetch(data['img_url'])
    if img.status_code == 200:
        thumb = img.content
        gift = Gift.get_by_id(data['gift_id'])
        if gift:
            title = gift.name.replace('"', '"')
            content_type = 'image/jpeg'
            thumb_img = ThumbImage()
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(700, 700, ),
                                    title=title, content_type=content_type)
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(400, 400, ),
                                    title=title, content_type=content_type)
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(200, 200, ),
                                    title=title, content_type=content_type)
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(100, 100, ),
                                    title=title, content_type=content_type)
            thumb_img.put()
            gift.thumbs.append(str(thumb_img.key()))
            if not gift.main_thumb:
                gift.main_thumb = str(thumb_img.key())
            gift.put()
    return render_to_response('empty.html')
开发者ID:gmist,项目名称:five-studio,代码行数:29,代码来源:views.py

示例4: get_gift

# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import get_by_id [as 别名]
def get_gift(request, idx):
    gift = Gift.get_by_id(idx)
    if not gift:
        return redirect('/')
    additional_gifts = Gift.all().filter('subcategory =', gift.subcategory).filter(
                'name !=', gift.name).fetch(4)
    return render_to_response('gift/get.html',
            {'gift': gift,
            'additional_gifts': additional_gifts,
            'price_modif': GlobalPriceModif.get_price_modif()})
开发者ID:gmist,项目名称:f-toy,代码行数:12,代码来源:views.py

示例5: index

# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import get_by_id [as 别名]
def index(request):
    order =request.session.get('order', {})
    count = 0
    if order:
        order_items = request.session.get('order', {})

        for k, val in order_items.iteritems():
            gift = Gift.get_by_id(k)
            if gift:
                count += gift.price * val
    return render_to_response('cart/index.html', {'count':count})
开发者ID:gmist,项目名称:f-toy,代码行数:13,代码来源:views.py

示例6: confirm

# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import get_by_id [as 别名]
def confirm(request):
    if not request.session.get('order', {}):
        return redirect('/cart/show/')
    form = OrderForm()
    if request.method == 'POST' and form.validate(request.form):
        order = form.save()
        for k, v in request.session.get('order', {}).items():
            gift = Gift.get_by_id(k)
            if gift:
                oi = OrderItem(gift_id=gift, count=v)
                oi.in_order = order
                oi.put()
        clear_cart(request)
        return render_to_response('cart/confirm_complete.html')
    return render_to_response('cart/confirm.html', {'form':form.as_widget()})
开发者ID:gmist,项目名称:f-toy,代码行数:17,代码来源:views.py

示例7: add_item

# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import get_by_id [as 别名]
def add_item(request, id, count):
    gift = Gift.get_by_id(id)
    try:
        int_count = int(count)
    except ValueError:
        int_count = 0
    if gift and int_count:
        request.session['items_count'] = \
        request.session.get('items_count',0) + int_count
    items = request.session.get('order', {})
    if not items:
        request.session['order'] = {}
    current_item = items.get(id, 0) + int_count
    request.session['order'][id] = current_item
    return redirect('/cart/')
开发者ID:gmist,项目名称:f-toy,代码行数:17,代码来源:views.py

示例8: simple_buy

# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import get_by_id [as 别名]
def simple_buy(request, id, count):
    gift = Gift.get_by_id(id)
    if not gift:
        return render_to_response('empty.html')
    form = OrderForm()
    if request.method == 'POST' and form.validate(request.form) and count:
        order = form.save()
        oi = OrderItem(gift_id=gift, count=count)
        oi.in_order = order
        oi.put()
        def txn():
                taskqueue.add(url=url_for('cart/send_order_to_manager',
                                    order_key=str(order.key())),
                                    transactional=True)
        db.run_in_transaction(txn)
        return render_to_response('cart/confirm_complete_text.html')
    return render_to_response('cart/cart_block.html', {'gift':gift, 'form':form.as_widget()})
开发者ID:gmist,项目名称:f-toy,代码行数:19,代码来源:views.py

示例9: cart_block

# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import get_by_id [as 别名]
def cart_block(request, id):
    gift = Gift.get_by_id(id)
    if not gift:
        return render_to_response('empty.html')
    form = OrderForm()
    return render_to_response('cart/cart_block.html', {'gift':gift, 'form':form.as_widget()})
开发者ID:gmist,项目名称:f-toy,代码行数:8,代码来源:views.py


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