Commits

Viorel Stirbu committed 7a31560

set consistent limit for homepage top products

Comments (0)

Files changed (3)

atexpc/ancora_api/api.py

         products = self.adapter.read(products_uri, post_process)
         return products
 
-    def products_recommended(self):
+    def products_recommended(self, limit):
         def post_process(data):
             json_root = 'recommended_products'
             products = []
                                  'price': product.get('zpret_site')})
             return products
 
-        recommended_uri = self.adapter.base_uri_with_args({'cod_formular': '740'})
+        recommended_uri = self.adapter.base_uri_with_args({
+            'cod_formular': '740',
+            'start': 0,
+            'stop': limit})
         recommended = self.adapter.read(recommended_uri, post_process)
         return recommended
 
-    def products_sales(self):
+    def products_sales(self, limit):
         def post_process(data):
             json_root = 'promo_products'
             products = []
             return products
 
         sales_uri = self.adapter.base_uri_with_args({'cod_formular': '737',
-                                                     'start':0,
-                                                     'stop': 4})
+                                                     'start': 0,
+                                                     'stop': limit})
         sales = self.adapter.read(sales_uri, post_process)
         return sales
 

atexpc/atex_web/models.py

     def get_product(self, product_id):
         return self._api.product(product_id)
 
-    def get_recommended(self):
-        return self._api.products_recommended()
+    def get_recommended(self, limit):
+        return self._api.products_recommended(limit)
 
-    def get_sales(self):
-        return self._api.products_sales()
+    def get_sales(self, limit):
+        return self._api.products_sales(limit)
 
 ancora = AncoraBackend()
 

atexpc/atex_web/views.py

         product['url'] = _product_url(product)
         hits.append(product)
         
-    recommended = ancora.get_recommended()[:top_limit]
+    recommended = ancora.get_recommended(limit=top_limit)
     for product in recommended:
         product['images'] = Product(model=product['model']).images
         product['url'] = _product_url(product)
 
-    sales = ancora.get_sales()[:top_limit]
+    sales = ancora.get_sales(limit=top_limit)
     for product in sales:
         product['images'] = Product(model=product['model']).images
         product['url'] = _product_url(product)