Ejemplo n.º 1
0
def get_goods(request):
    try:
        guid = request.GET.get('guid')
    except MultiValueDictKeyError:
        return HttpResponseAjaxError(code=302, message='no request GET guid')

    try:
        only_stock_ = request.GET.get('only_stock')
    except MultiValueDictKeyError:
        only_stock_ = None

    try:
        only_promo_ = request.GET.get('only_promo')
    except MultiValueDictKeyError:
        only_promo_ = None

    try:
        obj_section = Section.objects.get(guid=guid)
    except Section.DoesNotExist:
        return HttpResponseAjaxError(code=303, message='does not find section')

    obj_section.add_current_session(request)

    cart = Cart(request)
    goods_list = obj_section.get_goods_list_section(user=request.user,
                                                    only_stock=only_stock_,
                                                    only_promo=only_promo_)

    return HttpResponseAjax(current_section=obj_section.full_name,
                            products=render_to_string(
                                'goods.html', {
                                    'cart': cart,
                                    'goods_list': goods_list,
                                    'user': request.user
                                }))
Ejemplo n.º 2
0
def get_orders_list(request):
    try:
        begin_date = request.GET.get('begin_date')
    except MultiValueDictKeyError:
        return HttpResponseAjaxError(code=302,
                                     message='no request GET begin_date')
    try:
        end_date = request.GET.get('end_date')
    except MultiValueDictKeyError:
        return HttpResponseAjaxError(code=302,
                                     message='no request GET end_date')

    begin_date = datetime.date(int(begin_date.split('.')[2]),
                               int(begin_date.split('.')[1]),
                               int(begin_date.split('.')[0]))

    end_date = datetime.date(int(end_date.split('.')[2]),
                             int(end_date.split('.')[1]),
                             int(end_date.split('.')[0]))

    Order.add_current_session(request, begin_date, end_date)

    orders_list = Order.get_orders_list(request.user, begin_date, end_date)
    return HttpResponseAjax(list_orders=render_to_string(
        'orders/list_orders_table.html', {'orders_list': orders_list}))
Ejemplo n.º 3
0
def cart_get_form_quantity(request):
    if request.method == 'POST':
        pass
    else:
        try:
            guid = request.GET.get('guid')
        except MultiValueDictKeyError:
            return HttpResponseAjaxError(code=302,
                                         message='no request GET guid')

        try:
            product = Product.objects.get(guid=guid)
        except Product.DoesNotExist:
            return HttpResponseAjaxError(code=303,
                                         message='does not find product')

        cart = Cart(request)
        is_cart = (cart.get_quantity_product(product.guid) > 0)

        inventory = max(product.get_inventory(cart), 0)
        inventory = 999999 if inventory > 10 else inventory
        if not is_cart and inventory > 0:
            form = EnterQuantity(initial={'quantity': 1}, max_value=inventory)
        else:
            form = EnterQuantityError()

        return HttpResponseAjax(guid=guid,
                                inventory=inventory,
                                form_enter_quantity=render_to_string(
                                    'goods/enter_quantity.html', {
                                        'form': form,
                                        'guid': guid,
                                        'inventory': inventory,
                                        'is_cart': is_cart
                                    }))
Ejemplo n.º 4
0
def cart_add(request):
    try:
        guid = request.GET.get('guid')
    except MultiValueDictKeyError:
        return HttpResponseAjaxError(code=302, message='no request GET guid')

    try:
        quantity = request.GET.get('quantity')
    except MultiValueDictKeyError:
        return HttpResponseAjaxError(code=302,
                                     message='no request GET quantity')

    try:
        quantity = int(quantity)
    except TypeError:
        return HttpResponseAjaxError(code=302, message='no quantity int')

    cart = Cart(request)
    product = get_object_or_404(Product, guid=guid)

    inventory = max(product.get_inventory(cart), 0)
    inventory = 999999 if inventory > 10 else inventory
    quantity = min(quantity, inventory)

    if quantity > 0:
        cart.add(product=product, quantity=quantity)

    return HttpResponseAjax(cart=render_to_string('cart/cart.html',
                                                  {'cart': cart}),
                            user_cart=render_to_string(
                                'header/user_tools_cart.html', {
                                    'cart': cart,
                                    'user': request.user
                                }))
Ejemplo n.º 5
0
def get_help_tip(request):
    try:
        guid = request.GET.get('guid')
    except MultiValueDictKeyError:
        response = HttpResponseAjaxError(code=302, message='no request GET guid')
        log_response(
            '%s : no request GET guid', request.path,
            response=response,
            request=request,
        )
        return response

    product = get_object_or_404(Product, guid=guid)

    user = request.user
    if not user:
        response = HttpResponseAjaxError(code=303, message='you are not authenticated')
        log_response(
            '%s : you are not authenticated', request.path,
            response=response,
            request=request,
        )

    return HttpResponseAjax(
        help_tip=render_to_string('goods/help_tip.html',
                                  {'ob_goods': product, 'inventories': product.inventories_user(user)})
    )
Ejemplo n.º 6
0
def get_goods(request):
    try:
        guid = request.GET.get('guid')
    except MultiValueDictKeyError:
        response = HttpResponseAjaxError(code=302, message='no request GET guid')
        log_response(
            '%s : no request GET guid', request.path,
            response=response,
            request=request,
        )
        return response

    try:
        only_stock_ = str2bool(request.GET.get('only_stock'))
    except MultiValueDictKeyError:
        only_stock_ = False

    try:
        only_promo_ = str2bool(request.GET.get('only_promo'))
    except MultiValueDictKeyError:
        only_promo_ = False

    try:
        obj_section = Section.objects.get(id=guid)
    except Section.DoesNotExist:
        response = HttpResponseAjaxError(code=302, message='did not find section')
        log_response(
            '%s : did not find section : %s', request.path, str(guid),
            response=response,
            request=request,
        )
        return response

    obj_section.add_current_session(request)

    is_price_rrp = False

    cart = Cart(request)
    goods_list, kwargs = obj_section.get_goods_list_section_with_kwargs(
        user=request.user, only_stock=only_stock_, only_promo=only_promo_, is_price_rrp=is_price_rrp)

    is_price_rrp = kwargs.get('is_price_rrp', True)

    return HttpResponseAjax(
        current_section=obj_section.full_name,
        products=render_to_string('goods.html', {
            'cart': cart,
            'is_price_rrp': is_price_rrp,
            'goods_list': goods_list,
            'user': request.user
        })
    )
Ejemplo n.º 7
0
def cart_reduce_quantity(request):
    try:
        guid = request.GET.get('guid')
    except MultiValueDictKeyError:
        return HttpResponseAjaxError(code=302, message='no request GET guid')

    cart = Cart(request)
    product = get_object_or_404(Product, guid=guid)
    cart.add(product=product, quantity=-1)

    elem_cart = cart.get_tr_cart(guid)
    delete_row = elem_cart['quantity'] <= 0

    if delete_row:
        cart.remove(product)

    return HttpResponseAjax(
        delete=delete_row,
        td_cart_quantity=render_to_string('cart/td_cart_quantity.html',
                                          {'goods': elem_cart}),
        td_cart_total_price=render_to_string('cart/td_cart_total_price.html',
                                             {'goods': elem_cart}),
        td_cart_total_price_ruble=render_to_string(
            'cart/td_cart_total_price_ruble.html', {'goods': elem_cart}),
        header_cart=render_to_string('cart/header_cart.html', {
            'cart': cart,
            'user': request.user
        }),
        user_cart=render_to_string('header/user_tools_cart.html', {
            'cart': cart,
            'user': request.user
        }))
Ejemplo n.º 8
0
def cart_add_quantity(request):
    try:
        guid = request.GET.get('guid')
    except MultiValueDictKeyError:
        return HttpResponseAjaxError(code=302, message='no request GET guid')

    cart = Cart(request)
    product = get_object_or_404(Product, guid=guid)

    quantity = 1
    inventory = max(product.get_inventory(cart), 0)
    inventory = 999999 if inventory > 10 else inventory
    quantity = min(quantity, inventory)

    cart.add(product=product, quantity=quantity)

    elem_cart = cart.get_tr_cart(guid)

    return HttpResponseAjax(
        td_cart_quantity=render_to_string('cart/td_cart_quantity.html',
                                          {'goods': elem_cart}),
        td_cart_total_price=render_to_string('cart/td_cart_total_price.html',
                                             {'goods': elem_cart}),
        td_cart_total_price_ruble=render_to_string(
            'cart/td_cart_total_price_ruble.html', {'goods': elem_cart}),
        header_cart=render_to_string('cart/header_cart.html', {
            'cart': cart,
            'user': request.user
        }),
        user_cart=render_to_string('header/user_tools_cart.html', {
            'cart': cart,
            'user': request.user
        }))
Ejemplo n.º 9
0
def get_form_images(request):
    if request.method == 'POST':
        pass
    else:
        try:
            guid = request.GET.get('guid')
        except MultiValueDictKeyError:
            response = HttpResponseAjaxError(code=302, message='no request GET guid')
            log_response(
                '%s : no request GET guid', request.path,
                response=response,
                request=request,
            )
            return response

        try:
            product = Product.objects.get(guid=guid)
        except Product.DoesNotExist:
            response = HttpResponseAjaxError(code=303, message='did not find product')
            log_response(
                '%s : did not find product : %s', request.path, str(guid),
                response=response,
                request=request,
            )
            return response

        try:
            height = int(request.GET.get('height'))
        except TypeError:
            height = 699

        if height > 700:
            max_width = 1055
            max_height = 745
        else:
            max_width = 531
            max_height = 521

        return HttpResponseAjax(
            guid=guid,
            height=max_height,
            width=max_width,
            form_images=render_to_string('goods/show_images.html',
                                         {'guid': guid, 'image': ('media/' + str(product.image)),
                                          'max_width': max_width, 'max_height': max_height, 'name': str(product.name)})
        )
Ejemplo n.º 10
0
def get_orders_list(request):
    try:
        begin_date_str = request.GET.get('begin_date')
    except MultiValueDictKeyError:
        response = HttpResponseAjaxError(code=302, message='no request GET begin_date')
        log_response(
            '%s : no request GET begin_date', request.path,
            response=response,
            request=request,
        )
        return response
    try:
        end_date_str = request.GET.get('end_date')
    except MultiValueDictKeyError:
        response = HttpResponseAjaxError(code=302, message='no request GET end_date')
        log_response(
            '%s : no request GET end_date', request.path,
            response=response,
            request=request,
        )
        return response

    try:
        begin_date = datetime.datetime.strptime(begin_date_str, "%d.%m.%Y")
    except ValueError:
        begin_date = datetime.datetime.strptime(begin_date_str, "%m/%d/%Y")

    try:
        end_date = datetime.datetime.strptime(end_date_str, "%d.%m.%Y")
    except ValueError:
        end_date = datetime.datetime.strptime(end_date_str, "%m/%d/%Y")

    Order.add_current_session(request, begin_date, end_date)

    orders_list = Order.get_orders_list(request.user, begin_date, end_date)
    return HttpResponseAjax(
        list_orders=render_to_string('orders/list_orders_table.html', {
            'orders_list': orders_list
        })
    )
Ejemplo n.º 11
0
def cart_delete_row(request):
    try:
        guid = request.GET.get('guid')
    except MultiValueDictKeyError:
        return HttpResponseAjaxError(code=302, message='no request GET guid')

    cart = Cart(request)
    product = get_object_or_404(Product, guid=guid)
    cart.remove(product)

    return HttpResponseAjax(
        header_cart=render_to_string('cart/header_cart.html', {
            'cart': cart,
            'user': request.user
        }),
        user_cart=render_to_string('header/user_tools_cart.html', {
            'cart': cart,
            'user': request.user
        }))