[enhancement] use thumbnails in grid views, patch to make thumbnails

This commit is contained in:
Rushabh Mehta 2015-10-07 14:30:19 +05:30
parent 73e73795f1
commit 6e322d0a02
11 changed files with 67 additions and 8 deletions

View File

@ -218,13 +218,11 @@ erpnext.patches.v6_4.fix_status_in_sales_and_purchase_order
erpnext.patches.v6_4.fix_modified_in_sales_order_and_purchase_order
erpnext.patches.v6_4.fix_duplicate_bins
erpnext.patches.v6_4.fix_sales_order_maintenance_status
<<<<<<< HEAD
erpnext.patches.v6_4.email_digest_update
# delete shopping cart doctypes
execute:frappe.delete_doc_if_exists("DocType", "Applicable Territory")
execute:frappe.delete_doc_if_exists("DocType", "Shopping Cart Price List")
execute:frappe.delete_doc_if_exists("DocType", "Shopping Cart Taxes and Charges Master")
=======
erpnext.patches.v6_4.set_user_in_contact
>>>>>>> [minor] Added 'Invite User' in Contact
erpnext.patches.v6_4.make_image_thumbnail

View File

@ -0,0 +1,14 @@
import frappe
def execute():
frappe.reload_doctype("File")
frappe.reload_doctype("Item")
for item in frappe.get_all("Item", fields=("name", "website_image")):
if item.website_image:
item_doc = frappe.get_doc("Item", item.name)
try:
item_doc.make_thumbnail()
if item_doc.thumbnail:
item_doc.db_set("thumbnail", item_doc.thumbnail)
except Exception:
print "Unable to make thumbnail for {0}".format(item.website_image)

View File

@ -1,5 +1,6 @@
import frappe
def execute():
frappe.reload_doctype("Contact")
frappe.db.sql("""update tabContact, tabUser set tabContact.user = tabUser.name
where tabContact.email_id = tabUser.email""")

View File

@ -66,7 +66,7 @@ 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)])
# base query
query = """select name, item_name, page_name, website_image, item_group,
query = """select name, item_name, page_name, website_image, thumbnail, item_group,
web_long_description as website_description,
concat(parent_website_route, "/", page_name) as route
from `tabItem`

View File

@ -143,7 +143,7 @@ def guess_territory():
def decorate_quotation_doc(doc):
for d in doc.get("items", []):
d.update(frappe.db.get_value("Item", d.item_code,
["website_image", "description", "page_name"], as_dict=True))
["thumbnail", "website_image", "description", "page_name"], as_dict=True))
return doc

View File

@ -1902,6 +1902,28 @@
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "thumbnail",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Thumbnail",
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"read_only": 1,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,

View File

@ -66,6 +66,7 @@ class Item(WebsiteGenerator):
self.validate_has_variants()
self.validate_attributes()
self.validate_variant_attributes()
self.make_thumbnail()
if not self.get("__islocal"):
self.old_item_group = frappe.db.get_value(self.doctype, self.name, "item_group")
@ -79,6 +80,26 @@ class Item(WebsiteGenerator):
self.update_item_price()
self.update_variants()
def make_thumbnail(self):
"""Make a thumbnail of `website_image`"""
if self.website_image and not self.thumbnail:
file_doc = frappe.get_doc("File", {
"file_url": self.website_image,
"attached_to_doctype": "Item",
"attached_to_name": self.name
})
if not file_doc:
file_doc = frappe.get_doc({
"doctype": "File",
"file_url": self.website_image,
"attached_to_doctype": "Item",
"attached_to_name": self.name
}).insert()
if file_doc:
self.thumbnail = file_doc.make_thumbnail()
def get_context(self, context):
context.parent_groups = get_parent_item_groups(self.item_group) + \
[{"name": self.name}]

View File

@ -94,6 +94,8 @@
{% if variant_info %}
window.variant_info = {{ variant_info }};
{% else %}
window.variant_info = null;
{% endif %}
</script>
{% endblock %}

View File

@ -2,7 +2,7 @@
<a class="product-link" href="{{ (route or page_name)|abs_url }}">
<div class="col-sm-2 col-xs-4 product-image-wrapper">
{{ product_image_square(website_image) }}
{{ product_image_square(thumbnail or website_image) }}
<div class="text-ellipsis inline-block small product-text">{{ item_name }}</div>
</div>
</a>

View File

@ -3,7 +3,8 @@
<div style="height: 120px; overflow: hidden;">
<a href="{{ (route or page_name)|abs_url }}">
{%- if website_image -%}
<img class="product-image" style="width: 80%; margin: auto;" src="{{ website_image|abs_url }}">
<img class="product-image" style="width: 80%; margin: auto;" src="{{
(thumbnail or website_image)|abs_url }}">
{%- else -%}
<div style="width: 80%; height: 120px; background-color: #F7FAFC;"></div>
{%- endif -%}

View File

@ -12,7 +12,7 @@ no_sitemap = 1
@frappe.whitelist(allow_guest=True)
def get_product_list(search=None, start=0, limit=10):
# base query
query = """select name, item_name, page_name, website_image, item_group,
query = """select name, item_name, page_name, website_image, thumbnail, item_group,
web_long_description as website_description, parent_website_route
from `tabItem` where show_in_website = 1 and (variant_of is null or variant_of = '')"""