예제 #1
0
def show_static_page(request,
                     static_page_url,
                     template_name=u'static_page.jinja2', ):
    from apps.static.models import Static
    try:
        page = Static.objects.get(url=static_page_url, )
    except Static.DoesNotExist:
        from django.http import Http404
        raise Http404
    import markdown
    if page:
        html_text = markdown.markdown(page.text, )
    else:
        html_text = None
    response = render(request=request,
                      template_name=template_name,
                      context={'page': page,
                               'html_text': html_text, },
                      content_type='text/html', )
    # from datetime import datetime
    from apps.utils.datetime2rfc import datetime2rfc
    response['Last-Modified'] = datetime2rfc(page.updated_at, )
    return response
예제 #2
0
def show_product(request,
                 product_url,
                 id,
                 template_name=u'product/show_product.jinja2', ):
    current_category = request.session.get(u'current_category', None, )
    request.session[u'product'] = True
    if request.method == 'POST':
        if request.session.get(u'cookie', False, ):
        # if cookie:
        # if request.session.test_cookie_worked():
            action = request.POST.get(u'action', None, )
            if action == u'addtocard' or action == u'makeanorder':
                if current_category:
                    product_pk = request.POST.get(u'product_pk', None, )
                    product_url = request.POST.get(u'product_url', None, )
                    quantity = request.POST.get(u'quantity', None, )
                    try:
                        product = Product.objects.get(pk=product_pk, )
                        # product = Product.objects.get(pk=product_pk, url=product_url, )
                    except Product.DoesNotExist:
                        raise Http404
                    else:
                        if product.is_availability == 2:
                            available_to_order = True
                        else:
                            available_to_order = False
                        add_to_cart(request=request,
                                    product=product,
                                    int_product_pk=product_pk,
                                    product_url=product_url,
                                    quantity=quantity,
                                    available_to_order=available_to_order, )
#                        if request.
#                        try:
#                            cart = Cart.objects.get(sessionid=, )
                    if action == u'makeanorder':
                        return redirect(to='show_cart', )
                    try:
                        current_category = Category.objects.get(pk=int(current_category, ), )
                    except Category.DoesNotExist:
                        raise Http404
                    else:
                        return HttpResponseRedirect(current_category.get_absolute_url(), )
#            elif action == u'makeanorder':
#                pass
                else:
                    raise Http404
            else:
                raise Http404
        else:
            raise Http404
    else:
        product = get_product(product_pk=id, product_url=product_url, )

        product.get_or_create_ItemID()
        viewed = get_or_create_Viewed(request=request, product=product, )
        # product_is_availability = product.is_availability
        categories_of_product = product.category.all()
        if current_category:
            for cat in categories_of_product:
                if int(current_category) == cat.pk:
                    try:
                        current_category = categories_of_product[0]
                    except IndexError:
                        send_error_manager(request, product=product, error_id=1, )
                        raise Http404
                    break
            else:
                try:
                    current_category = categories_of_product[0]
                except IndexError:
                    send_error_manager(request, product=product, error_id=1, )
                    raise Http404
                else:
                    request.session[u'current_category'] = current_category.pk
        else:
            current_category = categories_of_product[0]
            request.session[u'current_category'] = current_category.pk
        quantity_ = product.minimal_quantity
        minimal_quantity_ = product.minimal_quantity
        quantity_of_complete_ = product.quantity_of_complete

    response = render(request=request,
                      template_name=template_name,
                      context=locals(),
                      # context_instance=RequestContext(request, ),
                      content_type='text/html', )
    if SERVER:
        updated_at = product.updated_at
    else:
        updated_at = datetime.now()

    response['Last-Modified'] = datetime2rfc(updated_at, )
    return response
예제 #3
0
def show_product(request, product_url, id,
                 template_name=u'product/show_product.jinja2.html',
                 ):
    current_category = request.session.get(u'current_category', None, )
    request.session[u'product'] = True
    if request.method == 'POST':
        if request.session.get(u'cookie', False, ):
        # if cookie:
        # if request.session.test_cookie_worked():
            action = request.POST.get(u'action', None, )
            if action == u'addtocard' or action == u'makeanorder':
                if current_category:
                    product_pk = request.POST.get(u'product_pk', None, )
                    product_url = request.POST.get(u'product_url', None, )
                    quantity_ = request.POST.get(u'quantity', None, )
                    from apps.product.models import Product
                    try:
                        product = Product.objects.get(pk=product_pk, url=product_url, )
                    except Product.DoesNotExist:
                        # request.session[u'test1-product_pk'] = product_pk
                        # request.session[u'test1-product_url'] = product_url
                        from django.http import Http404
                        raise Http404
                    else:
                        if product.is_availability == 2:
                            available_to_order = True
                        else:
                            available_to_order = False
                        add_to_cart(request=request,
                                    product=product,
                                    int_product_pk=product_pk,
                                    product_url=product_url,
                                    quantity=quantity_,
                                    available_to_order=available_to_order, )
#                        if request.
#                        try:
#                            from apps.cart.models import Cart
#                            cart = Cart.objects.get(sessionid=, )
                    if action == u'makeanorder':
                        from django.shortcuts import redirect
                        return redirect(to='show_cart', )
                    from apps.product.models import Category
                    try:
                        current_category = Category.objects.get(pk=int(current_category, ), )
                    except Category.DoesNotExist:
                        from django.http import Http404
                        raise Http404
                    else:
                        from django.http import HttpResponseRedirect
                        return HttpResponseRedirect(current_category.get_absolute_url(), )
#            elif action == u'makeanorder':
#                pass
                else:
                    from django.http import Http404
                    raise Http404
            else:
                from django.http import Http404
                raise Http404
        else:
            from django.http import Http404
            raise Http404
    else:
#        request.session.set_test_cookie()
        product = get_product(product_pk=id, product_url=product_url, )
#        from apps.product.models import Product
#        try:
#            product = Product.objects.get(pk=id, url=product_url, )
#        except Product.DoesNotExist:
#            from django.http import Http404
#            raise Http404
#        else:
#        products_recommended = product.recommended.all()
        # print(product)
        # print(products_recommended)
        # print(len(products_recommended))
        product.get_or_create_ItemID
        viewed = get_or_create_Viewed(request=request, product=product, )
        # product_is_availability = product.is_availability
        categories_of_product = product.category.all()
        if current_category:
            for cat in categories_of_product:
                if int(current_category) == cat.pk:
                    try:
                        current_category = categories_of_product[0]
                    except IndexError:
                        send_error_manager(request, product=product, error_id=1, )
                        from django.http import Http404
                        raise Http404
                    break
            else:
                    try:
                        current_category = categories_of_product[0]
                    except IndexError:
                        send_error_manager(request, product=product, error_id=1, )
                        from django.http import Http404
                        raise Http404
                    else:
                        request.session[u'current_category'] = current_category.pk
        else:
            current_category = categories_of_product[0]
            request.session[u'current_category'] = current_category.pk
        quantity_ = product.minimal_quantity
        minimal_quantity_ = product.minimal_quantity
        quantity_of_complete_ = product.quantity_of_complete

    response = render_to_response(u'product/show_product.jinja2.html',
                                  locals(),
                                  context_instance=RequestContext(request, ),
                                  )
    from proj.settings import SERVER
    if SERVER:
        updated_at = product.updated_at
    else:
        from datetime import datetime
        updated_at = datetime.now()
    from apps.utils.datetime2rfc import datetime2rfc
    response['Last-Modified'] = datetime2rfc(updated_at, )
    return response