From 0d6db633f721ac345457979abd75b7fb8c49633a Mon Sep 17 00:00:00 2001 From: Kanchan Chauhan Date: Wed, 24 Feb 2016 17:29:25 +0530 Subject: [PATCH] Added pagination to Products web page --- erpnext/setup/doctype/item_group/item_group.py | 11 ++++++++--- erpnext/templates/generators/item_group.html | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/erpnext/setup/doctype/item_group/item_group.py b/erpnext/setup/doctype/item_group/item_group.py index ed7da9ccab..7669bff2fd 100644 --- a/erpnext/setup/doctype/item_group/item_group.py +++ b/erpnext/setup/doctype/item_group/item_group.py @@ -16,7 +16,8 @@ class ItemGroup(NestedSet, WebsiteGenerator): website = frappe._dict( condition_field = "show_in_website", template = "templates/generators/item_group.html", - parent_website_route_field = "parent_item_group" + parent_website_route_field = "parent_item_group", + no_cache = 1 ) def autoname(self): @@ -52,8 +53,11 @@ class ItemGroup(NestedSet, WebsiteGenerator): frappe.throw(frappe._("An item exists with same name ({0}), please change the item group name or rename the item").format(self.name)) def get_context(self, context): + start = int(frappe.form_dict.start or 0) + if start < 0: + start = 0 context.update({ - "items": get_product_list_for_group(product_group = self.name, limit=100), + "items": get_product_list_for_group(product_group = self.name, start=start, limit=24), "parent_groups": get_parent_item_groups(self.name), "title": self.name }) @@ -63,6 +67,7 @@ class ItemGroup(NestedSet, WebsiteGenerator): return context +@frappe.whitelist(allow_guest=True) def get_product_list_for_group(product_group=None, start=0, limit=10): child_groups = ", ".join(['"' + i[0] + '"' for i in get_child_groups(product_group)]) @@ -122,4 +127,4 @@ def invalidate_cache_for(doc, item_group=None): d = frappe.get_doc("Item Group", d.name) route = d.get_route() if route: - clear_cache(route) + clear_cache(route) \ No newline at end of file diff --git a/erpnext/templates/generators/item_group.html b/erpnext/templates/generators/item_group.html index eb1278c91d..7e68bc7701 100644 --- a/erpnext/templates/generators/item_group.html +++ b/erpnext/templates/generators/item_group.html @@ -25,9 +25,14 @@ {{ item }} {% endfor %} - {% if (items|length)==100 %} -
Showing top 100 items.
- {% endif %} +
+ {% if frappe.form_dict.start|int > 0 %} + Prev + {% endif %} + {% if items|length == 24 %} + Next + {% endif %} +
{% else %}
No items listed.
{% endif %}