Exemplo n.º 1
0
def best(req):
    logger.debug('Requesting best');
    page = to_int(req.GET.get('page'), 1)

    countPerPage = 30
    products, count = Product.get_bids(page, countPerPage)
    context = {
        'menu': JSArray(get_menu()),
        'category': 'Лучшие предложения',
        'count': count,
        'products': js.eval(products),
        'paginator': {
            'totalPages': math.ceil(float(count) / countPerPage) or 1,
            'currentPage': page,
            'url': req.path,
            'config': {
                'HTTP': {
                    'list': '#'
                }
            }
        }
    }

    html = js.render(context, 'pages.category', env=get_env())
    res = HttpResponse(html);
    return res
Exemplo n.º 2
0
def main(req):
    logger.debug("Requesting main")

    products, count = Product.get_bids(1, 5)
    promo = Banner.objects.filter(hidden=False)
    if req.is_ajax():
        return HttpResponse(
            json.dumps(
                {"promo": map(BannerSerializer().normalize, promo), "products": json.loads(products), "count": count},
                cls=JSONEncoder,
            )
        )

    ctime = time()

    context = {
        "menu": get_menu(),
        "promo": map(BannerSerializer().normalize, promo),
        "products": json.loads(products),
        "count": count,
    }
    context = json.dumps(context, cls=JSONEncoder)
    logger.info("Generating context: %gs" % (time() - ctime))

    ctime = time()
    html = js.render(context, 'pages["index.str"]', env=get_env())
    logger.info("Render: %gs" % (time() - ctime))

    res = HttpResponse(html)
    return res
Exemplo n.º 3
0
def generate_category_sitemap():
    countPerPage = 30

    for category in get_menu():
        categoryUrl = category['href']
        append_node(categoryUrl, NOW, 0.5)
        products = Product.customs.filter(type__url__exact=categoryUrl)
        paginator = Paginator(products, 30)
        print "%s: %d pages" % (categoryUrl, paginator.num_pages)

        page = paginator.page(1)
        path = urljoin(categoryUrl, '?page=%d' % page.number)
        while page.has_next():
            page = paginator.page(page.next_page_number())
            path = urljoin(categoryUrl, '?page=%d' % page.number)
            append_node(path, NOW, 0.4)
Exemplo n.º 4
0
def product(req, slug):
    try:
        product = Product.objects.prefetch_related('item_set').get(slug__exact=slug)
    except Product.DoesNotExist:
        raise Http404

    items = product.item_set.all()
    if not len(items):
        raise Http404

    #TODO: merge
    if (req.is_ajax()):
        context = {
            'title': generate_title(product),
            'description': generate_description(product),

            #breadcrumbs
            'name': product.name,
            'category': product.type.name,
            'categoryUrl': "/%s" % product.type.url,

            'item': json.loads(product.json())
        }
        return HttpResponse(json.dumps(context), 'application/json')

    context = {
        'title': generate_title(product),
        'description': generate_description(product),

        #breadcrumbs
        'name': product.name,
        'category': product.type.name,
        'categoryUrl': "/%s" % product.type.url,

        'menu': JSArray(get_menu()),
        'item': product.json(),
    }

    html = js.render(context, 'pages["item.json"]', env=get_env())
    return HttpResponse(html)