Merge pull request #4867 from KanchanChauhan/item-group

Added pagination to Products web page
This commit is contained in:
Nabin Hait 2016-02-25 11:56:30 +05:30
commit a1d5494fb3
2 changed files with 16 additions and 6 deletions

View File

@ -16,7 +16,8 @@ class ItemGroup(NestedSet, WebsiteGenerator):
website = frappe._dict( website = frappe._dict(
condition_field = "show_in_website", condition_field = "show_in_website",
template = "templates/generators/item_group.html", 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): 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)) 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): def get_context(self, context):
start = int(frappe.form_dict.start or 0)
if start < 0:
start = 0
context.update({ 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), "parent_groups": get_parent_item_groups(self.name),
"title": self.name "title": self.name
}) })
@ -63,6 +67,7 @@ class ItemGroup(NestedSet, WebsiteGenerator):
return context return context
@frappe.whitelist(allow_guest=True)
def get_product_list_for_group(product_group=None, start=0, limit=10): 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)]) child_groups = ", ".join(['"' + i[0] + '"' for i in get_child_groups(product_group)])

View File

@ -25,9 +25,14 @@
{{ item }} {{ item }}
{% endfor %} {% endfor %}
</div> </div>
{% if (items|length)==100 %} <div class="text-center">
<div class="text-muted info">Showing top 100 items.</div> {% if frappe.form_dict.start|int > 0 %}
<a class="btn btn-default" href="{{ pathname }}?start={{ frappe.form_dict.start|int - 24 }}">Prev</a>
{% endif %} {% endif %}
{% if items|length == 24 %}
<a class="btn btn-default" href="{{ pathname }}?start={{ frappe.form_dict.start|int + 24 }}">Next</a>
{% endif %}
</div>
{% else %} {% else %}
<div class="text-muted">No items listed.</div> <div class="text-muted">No items listed.</div>
{% endif %} {% endif %}