Beispiel #1
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
Beispiel #2
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
Beispiel #3
0
    def test_create(self):
        materials = [
            {'name': 'Gold'},
            {'name': 'Silver'},
            {'name': 'Platinum'},
        ]

        gems = [
            {'name': '1'},
            {'name': '2'},
            {'name': '3'},
        ]

        product = Product(type=Type(1, name='Ring'), name='Ring XYZ')
        product.save()

        map(lambda m: product.materials.create(**m), materials);
        map(lambda g: product.gems.create(**g), gems);

        self.assertEqual(product.type.name, 'Ring')
        self.assertEqual(product.materials.all()[1].name, 'Silver')
        self.assertEqual(product.gems.all()[2].name, '3')