예제 #1
0
파일: views.py 프로젝트: gmist/f-toy
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()})
예제 #2
0
파일: views.py 프로젝트: gmist/f-toy
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})
예제 #3
0
파일: views.py 프로젝트: gmist/five-studio
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')
예제 #4
0
파일: views.py 프로젝트: gmist/f-toy
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()})
예제 #5
0
파일: views.py 프로젝트: gmist/f-toy
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})
예제 #6
0
파일: views.py 프로젝트: gmist/f-toy
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()})
예제 #7
0
파일: views.py 프로젝트: gmist/f-toy
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/')
예제 #8
0
파일: views.py 프로젝트: gmist/f-toy
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()})
예제 #9
0
파일: views.py 프로젝트: gmist/f-toy
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()})