Merge pull request #4867 from KanchanChauhan/item-group
Added pagination to Products web page
This commit is contained in:
commit
a1d5494fb3
@ -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)
|
@ -25,9 +25,14 @@
|
||||
{{ item }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% if (items|length)==100 %}
|
||||
<div class="text-muted info">Showing top 100 items.</div>
|
||||
{% endif %}
|
||||
<div class="text-center">
|
||||
{% if frappe.form_dict.start|int > 0 %}
|
||||
<a class="btn btn-default" href="{{ pathname }}?start={{ frappe.form_dict.start|int - 24 }}">Prev</a>
|
||||
{% endif %}
|
||||
{% if items|length == 24 %}
|
||||
<a class="btn btn-default" href="{{ pathname }}?start={{ frappe.form_dict.start|int + 24 }}">Next</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="text-muted">No items listed.</div>
|
||||
{% endif %}
|
||||
|
Loading…
Reference in New Issue
Block a user