コード例 #1
0
ファイル: views.py プロジェクト: wooshe/Shop
def main_view(request):
    cart = getUserCart(request)

    # all_product = Product.objects.all().exclude(Q(size__isnull=True))

    all_product = Product.objects.all()[0:10]
    min_price = all_product.aggregate(Min('price'))
    max_price = all_product.aggregate(Max('price'))

    min_price = str(min_price.get('price__min'))
    max_price = str(max_price.get('price__max'))

    pop_products = Product.objects.all().order_by('-count_buy')

    pop_products = get_random_objects(pop_products[0:40], 10)

    rating_products = Product.objects.all().order_by('-rating')

    rating_products = get_random_objects(rating_products[0:40], 10)

    context = {
        'min_price': min_price,
        'max_price': max_price,
        'products': all_product,
        'cart': cart,
        'cat_range': range(2),
        'pop_products': pop_products,
        'rating_products': rating_products
    }

    getDataForNavBaR(context, request)

    category_menu = context['category_menu']
    count = math.ceil((category_menu.count() / 2))
    range_group = range(count)

    bbx = {}
    cur = -1
    p = 0

    for cat in category_menu:

        if p % 2 == 0:
            cat.top = True
        else:
            cat.top = False

        p = p + 1

    for g in range_group:
        val = {}
        cur = cur + 1
        val[0] = g + cur
        val[1] = cur + 1 + g

        bbx[g] = val

    context.update({'group': bbx})

    return render(request, 'main.html', context)
コード例 #2
0
ファイル: views.py プロジェクト: wooshe/Shop
def cart_view(request, ):
    cart = getUserCart(request)

    cart.CalculatePrice()

    if request.user.is_authenticated:
        address_form = AddressForm(instance=request.user.profile)
        with_save = "true"
    else:
        address_form = AddressForm()
        with_save = "false"

    delivery_total = 0
    delivery_max_day = 0
    delivery_min_day = 0

    try:
        info = address_form.initial
        normalize = pr_address_normalize(info['country'], info['region'],
                                         info['area'], info['city'],
                                         info['street'], info['house'],
                                         info['room'], info['index'])

        if normalize['ret_status'] == 'success':
            delivery_total_ret = pr_pre_calc(normalize['body']['index'])
            delivery_total = delivery_total_ret['total_nds']
            delivery_max_day = delivery_total_ret['max-days']
            delivery_min_day = delivery_total_ret['min-days']

    except:
        pass

    delivery_and_cart_price = cart.price_all + delivery_total

    context = {
        'cart': cart,
        'address_form': address_form,
        'with_save': with_save,
        'delivery_price': delivery_total,
        "delivery_and_cart_price": delivery_and_cart_price,
        'delivery_max_day': delivery_max_day,
        'delivery_min_day': delivery_min_day
    }

    order_id = request.GET.get('order_id')
    if order_id != None and order_id != 'undefined':
        ord = Order.objects.get(id=order_id)
        cart.cart_from_order(ord)
        context['message_act'] = 'true'
        context['message'] = message(
            "Оплата не произведена, попробуйте еще раз!", request)

    getDataForNavBaR(context, request)
    return render(request, 'cart.html', context)
コード例 #3
0
ファイル: views.py プロジェクト: wooshe/Shop
def catalog_view(request, category=None):
    cart = getUserCart(request)

    query = request.GET.get('query')

    active_link = None

    if query != None:
        all_product = Product.objects.annotate(
            search=SearchVector('name', 'description')).filter(search=query)

    elif category == 'all' or category == None:
        all_product = Product.objects.all()
        active_link = "catalog"

    elif category == 'sale':
        all_product = Product.objects.all().filter(sale__gt=0)
        active_link = "sale"

    elif category != None:
        cat = Category.objects.get(slug=category)
        active_link = cat.get_absolute_url()
        all_product = Product.objects.filter(category=cat)

    if query == None:
        query = ''
    context = {}
    get_min_max(all_product, context)

    if all_product.count() <= 20:
        all_pagination_end = 'True'
    else:
        all_pagination_end = 'False'

    all_product = sorter(all_product, "sort_by_price",
                         'sort_from_zero')[0:settings.PAGINATION_ELEMENT]

    context.update({
        'products': all_product,
        'cart': cart,
        'active_link': active_link,
        'query': query,
        'all_pagination_end': all_pagination_end
    })

    getDataForNavBaR(context, request)
    return render(request, 'catalog.html', context)
コード例 #4
0
ファイル: views.py プロジェクト: wooshe/Shop
def product_view(request, product_slug):
    archive = False
    try:
        product = Product.objects.get(slug=product_slug)
        product.incr_view()

    except models.ObjectDoesNotExist:
        product = Product.archive.get(slug=product_slug)
        archive = True

    obraz_products = get_random_objects(Product.objects.all(), 5)
    equal_products = get_random_objects(
        Product.objects.filter(category=product.category), 5)
    category_menu = Category.objects.all()

    context = {
        'category_menu': category_menu,
        'product': product,
        'equal_products': equal_products,
        'obraz_products': obraz_products,
        'archive': archive
    }
    getDataForNavBaR(context, request)
    return render(request, 'product.html', context)
コード例 #5
0
def shopadmin_view(request):
    get_permission(request)
    method = request.GET.get('method')

    if method == 'doc_download':

        try:
            order = Order.objects.get(id=request.GET.get('id'))
            ret = pr_get_doc(order.pr_batch_name)
            if ret['ret_status'] == 'success':
                return JsonResponse({
                    'h': reverse('main') + ret['url'],
                    'result': 'success'
                })
            else:
                return JsonResponse({'result': 'error'})
        except:
            return JsonResponse({'result': 'error'})

    elif method == 'get_track':

        try:
            order = Order.objects.get(id=request.GET.get('id'))
            tracking = pr_tracking(order.pr_barcode)
            if tracking['ret_status'] == 'success':
                return JsonResponse({
                    'status': tracking['status'],
                    'result': 'success'
                })
            else:
                return JsonResponse({'result': 'error'})
        except:
            return JsonResponse({'result': 'error'})

    if request.GET.get('method') == 'get_order':
        try:
            order = Order.objects.get(id=request.GET.get('order_id'))
            order_response = render_template('order_expand.html', {
                'admin': 'true',
                'order': order
            }, request)
            return JsonResponse({
                'order_response': order_response,
                'result': 'success'
            })
        except:
            return JsonResponse({'result': 'error'})

    if request.GET.get('method') == 'order_confirm_delivery':
        try:
            order = Order.objects.get(id=request.GET.get('order_id'))
            order.send_confirm = True
            order.save()
            return JsonResponse({'result': 'success'})
        except:
            return JsonResponse({'result': 'error'})

    orders = Order.objects.all()
    statusForm = StatusForm()

    product_form = ProductForm()
    products = Product.objects.all()[0:10]

    category_form = CategoryForm()
    category = Category.objects.all()

    sale_form = SaleForm()
    sale = ProductSale.objects.all()

    SizeFormSet = modelformset_factory(ProductSize, form=SizeForm)
    size_formset = SizeFormSet()

    EmptySizeFormSet = modelformset_factory(ProductSize,
                                            form=SizeForm,
                                            can_delete=True,
                                            extra=3)
    empty_size_formset = EmptySizeFormSet(queryset=ProductSize.objects.none(),
                                          prefix="empty_form")
    context = {
        'product_form': product_form,
        'sale_form': sale_form,
        'product_form_edit': ProductForm(),
        'products': products,
        'photos': None,
        'category': category,
        'category_form': category_form,
        'category_form_edit': CategoryForm(),
        'related_category': None,
        'orders': orders,
        'statusForm': statusForm,
        'size_formset': size_formset,
        'empty_size_formset': empty_size_formset,
        'sale': sale
    }
    getDataForNavBaR(context, request)
    return render(request, 'shopadmin.html', context)
コード例 #6
0
ファイル: views.py プロジェクト: wooshe/Shop
def anonymous_profile_view(request):
    user = request.user
    if user.is_authenticated:
        return custom_redirect('profile',
                               order_id=request.GET.get('order_id'),
                               success_pay=request.GET.get('success_pay'))

    if request.method == 'GET':

        if request.GET.get('method') == 'get_order':
            try:
                order = Order.objects.get(id=request.GET.get('order_id'))
                order_response = render_template('order_expand.html',
                                                 {'order': order}, request)
                return JsonResponse({
                    'order_response': order_response,
                    'result': 'success'
                })
            except:
                return JsonResponse({'result': 'error'})

        if request.GET.get('method') == 'order_confirm_delivery':
            try:
                order = Order.objects.get(id=request.GET.get('order_id'))
                order.send_confirm = True
                order.save()
                return JsonResponse({'result': 'success'})
            except:
                return JsonResponse({'result': 'error'})

    context = {}
    context['message_act'] = 'false'
    context['success_pay'] = 'False'

    order_id = request.GET.get('order_id')

    if str(order_id) != 'None' and str(
            request.GET.get('success_pay')) == 'None':

        context['order_id'] = order_id
        response = status_pay(order_id)

        url = reverse('anonymous_profile')

        if response['ret_status'] != 'error':
            if response['status'] == 'authorized' or response[
                    'status'] == 'acknowledged':
                url += '?success_pay=True&order_id=' + order_id
                context['success_pay'] = 'True'

        context.update({
            'redirect_url': url,
        })

        getDataForNavBaR(context, request)
        return render(request, 'anonymous_profile.html', context)

    elif str(order_id) != 'None' and str(
            request.GET.get('success_pay')) == 'True':
        pay_order = Order.objects.get(id=order_id)
        response = status_pay(pay_order.id)
        if response['ret_status'] != 'error':
            if pay_order.pay == False and (
                    response['status'] == 'authorized' or response['status']
                    == 'acknowledged') and pay_order.status == 'registered':
                pay_order.pay = True
                pay_order.incr_buy_for_items()
                pay_order.status = 'ready_to_send'
                pay_order.save()
                notify_admin(request, pay_order)
                context['message_act'] = 'true'
                context['message'] = message('Заказ совершен!', request)

    context['success_pay'] = 'False'

    order_update(request)
    orders = Order.objects.filter(
        Q(sk=request.session.session_key) & Q(pay=True))

    context.update({
        'orders': orders,
    })

    getDataForNavBaR(context, request)
    return render(request, 'anonymous_profile.html', context)
コード例 #7
0
ファイル: views.py プロジェクト: wooshe/Shop
def profile_view(request):
    user = request.user

    if not user.is_authenticated:
        return custom_redirect('anonymous_profile',
                               order_id=request.GET.get('order_id'),
                               success_pay=request.GET.get('success_pay'))

    if request.method == 'GET':

        if request.GET.get('method') == 'get_order':
            try:
                order = Order.objects.get(id=request.GET.get('order_id'))
                order_response = render_template('order_expand.html',
                                                 {'order': order}, request)
                return JsonResponse({
                    'order_response': order_response,
                    'result': 'success'
                })
            except:
                return JsonResponse({'result': 'error'})

        if request.GET.get('method') == 'order_confirm_delivery':
            try:
                order = Order.objects.get(id=request.GET.get('order_id'))
                order.send_confirm = True
                order.save()
                return JsonResponse({'result': 'success'})
            except:
                return JsonResponse({'result': 'error'})

        context = {}
        context['message_act'] = 'false'
        context['success_pay'] = 'False'

        order_id = request.GET.get('order_id')

        if str(order_id) != 'None' and str(
                request.GET.get('success_pay')) == 'None':

            context['order_id'] = order_id

            user_form = UserForm(instance=request.user)
            address_form = AddressForm(instance=request.user.profile)
            password_change_form = PasswordChangeForm()

            response = status_pay(order_id)

            url = reverse('profile')
            if response['ret_status'] != 'error':
                if response['status'] == 'authorized' or response[
                        'status'] == 'acknowledged':
                    url += '?success_pay=True&order_id=' + order_id
                    context['success_pay'] = 'True'

            context.update({
                'redirect_url': url,
                'user_form': user_form,
                'address_form': address_form,
                'with_save': "true",
                'password_change_form': password_change_form
            })

            getDataForNavBaR(context, request)
            return render(request, 'profile.html', context)

        elif str(order_id) != 'None' and str(
                request.GET.get('success_pay')) == 'True':
            pay_order = Order.objects.get(id=order_id)
            response = status_pay(pay_order.id)
            if response['ret_status'] != 'error':
                if pay_order.pay == False and (
                        response['status'] == 'authorized'
                        or response['status'] == 'acknowledged'
                ) and pay_order.status == 'registered':
                    pay_order.pay = True
                    pay_order.incr_buy_for_items()
                    pay_order.status = 'ready_to_send'
                    pay_order.save()
                    notify_admin(request, pay_order)
                    context['message_act'] = 'true'
                    context['message'] = message('Заказ совершен!', request)

        order_update(request)

        orders = Order.objects.filter(Q(user=user) & Q(pay=True))

        user_form = UserForm(instance=request.user)
        address_form = AddressForm(instance=request.user.profile)
        password_change_form = PasswordChangeForm()

        context.update({
            'orders': orders,
            'user_form': user_form,
            'address_form': address_form,
            'with_save': "true",
            'password_change_form': password_change_form
        })

        getDataForNavBaR(context, request)
        return render(request, 'profile.html', context)

    if request.method == 'POST':
        type_post = request.POST.get('type_post')

        if type_post == "user_form":

            user_form = UserForm(request.POST, instance=request.user)

            if user_form.is_valid():
                user_form.save()
                user_change_form_response = render_template(
                    'user_change.html', {'user_form': user_form}, request)
                return JsonResponse({
                    'user_change_form_response':
                    user_change_form_response,
                    'result':
                    'success',
                    'message':
                    message("Профиль изменен!", request)
                })
            else:
                user_change_form_response = render_template(
                    'user_change.html', {'user_form': user_form}, request)
                return JsonResponse({
                    'user_change_form_response': user_change_form_response,
                    'result': 'error'
                })

        else:

            address_form = AddressForm(request.POST,
                                       instance=request.user.profile)

            if address_form.is_valid():
                address_form.save()

                address_change_form_response = render_template(
                    'address_change.html', {
                        'address_form': address_form,
                        'with_save': "true"
                    }, request)
                return JsonResponse({
                    'address_change_form_response':
                    address_change_form_response,
                    'result':
                    'success',
                    'message':
                    message("Адрес изменен!", request)
                })
            else:
                address_change_form_response = render_template(
                    'address_change.html', {
                        'address_form': address_form,
                        'with_save': "true"
                    }, request)
                return JsonResponse({
                    'address_change_form_response':
                    address_change_form_response,
                    'result': 'error'
                })
コード例 #8
0
ファイル: views.py プロジェクト: wooshe/Shop
def oferta_view(request):
    context = {}
    getDataForNavBaR(context, request)
    return render(request, 'oferta.html', context)
コード例 #9
0
ファイル: views.py プロジェクト: wooshe/Shop
def user_confirm_view(request):
    context = {}
    getDataForNavBaR(context, request)
    return render(request, 'user_confirm.html', context)
コード例 #10
0
ファイル: views.py プロジェクト: wooshe/Shop
def police_view(request):
    context = {}
    getDataForNavBaR(context, request)
    return render(request, 'police.html', context)
コード例 #11
0
ファイル: views.py プロジェクト: wooshe/Shop
def return_view(request):
    context = {}
    getDataForNavBaR(context, request)
    return render(request, 'return.html', context)
コード例 #12
0
ファイル: views.py プロジェクト: wooshe/Shop
def delivery_view(request):
    context = {}
    getDataForNavBaR(context, request)
    return render(request, 'delivery.html', context)
コード例 #13
0
ファイル: views.py プロジェクト: wooshe/Shop
def about_view(request):
    context = {}
    getDataForNavBaR(context, request)
    return render(request, 'about.html', context)
コード例 #14
0
ファイル: views.py プロジェクト: wooshe/Shop
def handler500(request, exception=None, template_name="e500.html"):
    context = {}
    getDataForNavBaR(context, request)
    return render(request, 'e500.html', context, status=500)
コード例 #15
0
ファイル: views.py プロジェクト: wooshe/Shop
def handler403(request, exception=None, template_name="e403.html"):
    context = {}
    getDataForNavBaR(context, request)
    return render(request, 'permission.html', context, status=403)