mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-21 22:19:18 +00:00
fixes to website, item (added table for cross listing), modules_setup and form_header
This commit is contained in:
@@ -74,6 +74,14 @@ footer {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.website-missing-image {
|
||||
background-color: #eee;
|
||||
padding: 40px;
|
||||
width: 32px;
|
||||
font-size: 32px;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
.clear {
|
||||
clear: both;
|
||||
}
|
||||
|
||||
0
website/doctype/website_item_group/__init__.py
Normal file
0
website/doctype/website_item_group/__init__.py
Normal file
8
website/doctype/website_item_group/website_item_group.py
Normal file
8
website/doctype/website_item_group/website_item_group.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# For license information, please see license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
|
||||
class DocType:
|
||||
def __init__(self, d, dl):
|
||||
self.doc, self.doclist = d, dl
|
||||
36
website/doctype/website_item_group/website_item_group.txt
Normal file
36
website/doctype/website_item_group/website_item_group.txt
Normal file
@@ -0,0 +1,36 @@
|
||||
[
|
||||
{
|
||||
"owner": "Administrator",
|
||||
"docstatus": 0,
|
||||
"creation": "2012-12-25 13:52:11",
|
||||
"modified_by": "Administrator",
|
||||
"modified": "2012-12-25 13:52:11"
|
||||
},
|
||||
{
|
||||
"istable": 1,
|
||||
"description": "Cross Listing of Item in multiple groups",
|
||||
"doctype": "DocType",
|
||||
"module": "Website",
|
||||
"document_type": "Other",
|
||||
"name": "__common__"
|
||||
},
|
||||
{
|
||||
"parent": "Website Item Group",
|
||||
"doctype": "DocField",
|
||||
"name": "__common__",
|
||||
"label": "Item Group",
|
||||
"parenttype": "DocType",
|
||||
"options": "Item Group",
|
||||
"fieldname": "item_group",
|
||||
"fieldtype": "Link",
|
||||
"permlevel": 0,
|
||||
"parentfield": "fields"
|
||||
},
|
||||
{
|
||||
"name": "Website Item Group",
|
||||
"doctype": "DocType"
|
||||
},
|
||||
{
|
||||
"doctype": "DocField"
|
||||
}
|
||||
]
|
||||
@@ -25,37 +25,78 @@ def get_product_info(item_code):
|
||||
}
|
||||
|
||||
@webnotes.whitelist(allow_guest=True)
|
||||
def get_product_list(search=None, product_group=None, start=0):
|
||||
import webnotes
|
||||
def get_product_list(search=None, product_group=None, start=0, limit=10):
|
||||
from webnotes.utils import cstr
|
||||
|
||||
# base query
|
||||
query = """\
|
||||
select name, item_name, page_name, website_image, item_group,
|
||||
query = """select name, item_name, page_name, website_image, item_group,
|
||||
web_long_description as website_description
|
||||
from `tabItem`
|
||||
where docstatus = 0
|
||||
and show_in_website = 1 """
|
||||
from `tabItem` where docstatus = 0 and show_in_website = 1 """
|
||||
|
||||
# search term condition
|
||||
if search:
|
||||
query += """
|
||||
and (
|
||||
web_long_description like %(search)s or
|
||||
item_name like %(search)s or
|
||||
name like %(search)s
|
||||
)"""
|
||||
query += """and (web_long_description like %(search)s or
|
||||
item_name like %(search)s or name like %(search)s)"""
|
||||
search = "%" + cstr(search) + "%"
|
||||
|
||||
# product group condition
|
||||
if product_group:
|
||||
query += """
|
||||
and item_group = %(product_group)s """
|
||||
|
||||
# order by
|
||||
query += """order by item_name asc, name asc limit %s, 10""" % start
|
||||
query += """order by weightage desc, modified desc limit %s, %s""" % (start, limit)
|
||||
|
||||
return webnotes.conn.sql(query, {
|
||||
data = webnotes.conn.sql(query, {
|
||||
"search": search,
|
||||
"product_group": product_group
|
||||
}, as_dict=1)
|
||||
}, as_dict=1)
|
||||
|
||||
return [get_item_for_list_in_html(r) for r in data]
|
||||
|
||||
|
||||
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,
|
||||
web_long_description as website_description
|
||||
from `tabItem` where docstatus = 0 and show_in_website = 1
|
||||
and (item_group in (%s)
|
||||
or name in (select parent from `tabWebsite Item Group` where item_group in (%s))) """ % (child_groups, child_groups)
|
||||
|
||||
query += """order by weightage desc, modified desc limit %s, %s""" % (start, limit)
|
||||
|
||||
data = webnotes.conn.sql(query, {"product_group": product_group}, as_dict=1)
|
||||
|
||||
return [get_item_for_list_in_html(r) for r in data]
|
||||
|
||||
def get_child_groups(item_group_name):
|
||||
item_group = webnotes.doc("Item Group", item_group_name)
|
||||
return webnotes.conn.sql("""select name
|
||||
from `tabItem Group` where lft>=%(lft)s and rgt<=%(rgt)s""" \
|
||||
% item_group.fields)
|
||||
|
||||
def get_group_item_count(item_group):
|
||||
child_groups = ", ".join(['"' + i[0] + '"' for i in get_child_groups(item_group)])
|
||||
return webnotes.conn.sql("""select count(*) from `tabItem`
|
||||
where docstatus = 0 and show_in_website = 1
|
||||
and (item_group in (%s)
|
||||
or name in (select parent from `tabWebsite Item Group`
|
||||
where item_group in (%s))) """ % (child_groups, child_groups))[0][0]
|
||||
|
||||
def get_item_for_list_in_html(r):
|
||||
from website.utils import build_html
|
||||
scrub_item_for_list(r)
|
||||
r.template = "html/product_in_list.html"
|
||||
return build_html(r)
|
||||
|
||||
def scrub_item_for_list(r):
|
||||
if not r.website_description:
|
||||
r.website_description = "No description given"
|
||||
if len(r.website_description.split(" ")) > 24:
|
||||
r.website_description = " ".join(r.website_description.split(" ")[:24]) + "..."
|
||||
if r.website_image and not r.website_image.lower().startswith("http"):
|
||||
r.website_image = "files/" + r.website_image
|
||||
|
||||
def get_parent_item_groups(item_group_name):
|
||||
item_group = webnotes.doc("Item Group", item_group_name)
|
||||
return webnotes.conn.sql("""select name, page_name from `tabItem Group`
|
||||
where lft <= %s and rgt >= %s
|
||||
and ifnull(show_in_website,0)=1
|
||||
order by lft asc""", (item_group.lft, item_group.rgt), as_dict=True)
|
||||
8
website/templates/html/product_breadcrumbs.html
Normal file
8
website/templates/html/product_breadcrumbs.html
Normal file
@@ -0,0 +1,8 @@
|
||||
{% if obj.parent_groups and len(obj.parent_groups) > 1 %}
|
||||
<ul class="breadcrumb">
|
||||
{% for ig in obj.parent_groups[:-1] %}
|
||||
<li><a href="{{ ig.page_name }}.html">{{ ig.name }}</a> <span class="divider">/</span></li>
|
||||
{% endfor %}
|
||||
<li class="active">{{ obj.parent_groups[-1].name }}</li>
|
||||
</ul>
|
||||
{% endif %}
|
||||
@@ -1,50 +1,39 @@
|
||||
{% extends "html/page.html" %}
|
||||
|
||||
{% block javascript %}
|
||||
{% include "js/product_list.js" %}
|
||||
{% endblock %}
|
||||
{% block title %}{{ name }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
window.start = 0;
|
||||
window.product_group = "{{ name }}";
|
||||
window.get_product_list();
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="layout-wrapper layout-wrapper-background">
|
||||
<div class="web-content" id="content-product_group">
|
||||
<div class="layout-main" style="padding: 30px;">
|
||||
{% include 'html/product_search_box.html' %}
|
||||
{% include 'html/product_breadcrumbs.html' %}
|
||||
{% if description %}
|
||||
<div>{{ description or ""}}</div>
|
||||
{% else %}
|
||||
<h3>{{ name }}</h3>
|
||||
{% endif %}
|
||||
{% if sub_groups %}
|
||||
<div class="well">
|
||||
<div class="container-fluid">
|
||||
<div class="well well-small">
|
||||
<div class="container-fluid" style="padding-left: 0px; margin-left:-10px; line-height: 2em;">
|
||||
{% for d in sub_groups %}
|
||||
<div class="span2">
|
||||
<i class="icon-chevron-right"></i>
|
||||
<a href="{{ d.page_name }}">{{ d.name }}</a></div>
|
||||
<a href="{{ d.page_name }}">{{ d.name }} ({{ d.count }})</a>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<hr>
|
||||
<h3>Products</h3>
|
||||
{% if items %}
|
||||
<div id="search-list">
|
||||
|
||||
</div>
|
||||
<div style="text-align: center;">
|
||||
<div class="more-btn"
|
||||
style="display: none; text-align: center;">
|
||||
<button class="btn">More...</button>
|
||||
</div>
|
||||
<table class="table">
|
||||
{% for item in items %}
|
||||
{{ item }}
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
14
website/templates/html/product_in_list.html
Normal file
14
website/templates/html/product_in_list.html
Normal file
@@ -0,0 +1,14 @@
|
||||
<tr>
|
||||
<td style="width: 30%;">
|
||||
{% if website_image %}
|
||||
<img class="product-image" style="width: 80%;" src="{{ website_image }}">
|
||||
{% else %}
|
||||
{% include 'html/product_missing_image.html' %}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<h4><a href="{{ page_name }}">{{ item_name }}</a></h4>
|
||||
<p class="help">Item Code: {{ name }}</p>
|
||||
<p>{{ website_description }}</p>
|
||||
</td>
|
||||
</tr>
|
||||
1
website/templates/html/product_missing_image.html
Normal file
1
website/templates/html/product_missing_image.html
Normal file
@@ -0,0 +1 @@
|
||||
<div class='website-missing-image'><i class='icon-camera'></i></div>
|
||||
@@ -12,7 +12,7 @@
|
||||
{% if item_name != name %}
|
||||
{{ item_name }} [{{ name }}]
|
||||
{% else %}
|
||||
{{ item_name }}
|
||||
{{ item_name or name }}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -21,19 +21,17 @@
|
||||
<div class="web-content" id="content-product-{{ name }}">
|
||||
<div class="layout-main" style="padding: 30px;">
|
||||
{% include 'html/product_search_box.html' %}
|
||||
<h1>{{ item_name }}</h1>
|
||||
{% include 'html/product_breadcrumbs.html' %}
|
||||
<h3>{{ item_name }}</h3>
|
||||
<p class="help">Item Code: {{ name }}</p>
|
||||
<div class="product-page-content">
|
||||
<div class="span6">
|
||||
{% if website_image %}
|
||||
<image class="item-main-image" src="files/{{ website_image }}" />
|
||||
<image class="item-main-image" src="{% if website_image.lower().startswith('http') %}{{ website_image}}{% else %}files/{{ website_image }}{% endif %}" />
|
||||
{% else %}
|
||||
<div class="img-area">
|
||||
<div style='background-color: #eee; padding: 40px;
|
||||
width: 32px; font-size: 32px; color: #888;' title='No Image'>
|
||||
<i class='icon-camera'></i></div>
|
||||
{% include 'html/product_missing_image.html' %}
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
<br><br>
|
||||
</div>
|
||||
@@ -57,7 +55,7 @@
|
||||
{% for d in obj.doclist.get(
|
||||
{"doctype":"Item Website Specification"}) %}
|
||||
<tr>
|
||||
<td style="min-width: 150px;">{{ d.label }}</td>
|
||||
<td style="width: 30%;">{{ d.label }}</td>
|
||||
<td>{{ d.description }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
@@ -31,28 +31,8 @@ window.render_product_list = function(data) {
|
||||
var table = $("<table class='table'>").appendTo("#search-list");
|
||||
|
||||
$.each(data, function(i, d) {
|
||||
if(!d.web_short_description)
|
||||
d.web_short_description = "No description given."
|
||||
var $tr = $(repl('<tr>\
|
||||
<td style="width: 30%;">\
|
||||
<img class="product-image" \
|
||||
style="width: 80%;" src="files/%(website_image)s">\
|
||||
</td>\
|
||||
<td>\
|
||||
<h4><a href="%(page_name)s">%(item_name)s</a></h4>\
|
||||
<p class="help">Item Code: %(name)s</p>\
|
||||
<p>%(website_description)s</p>\
|
||||
</td>\
|
||||
</tr>', d)).appendTo(table);
|
||||
|
||||
if(!d.website_image) {
|
||||
$tr.find(".product-image").replaceWith("<div\
|
||||
style='background-color: #eee; padding: 40px; \
|
||||
width: 32px; font-size: 32px; color: #888;'>\
|
||||
<i class='icon-camera'></i></div>");
|
||||
}
|
||||
$(d).appendTo(table);
|
||||
});
|
||||
|
||||
}
|
||||
if(data.length < 10) {
|
||||
if(!table) {
|
||||
|
||||
@@ -123,6 +123,8 @@ def build_html(args):
|
||||
templates_path = os.path.join(os.path.dirname(conf.__file__),
|
||||
'app', 'website', 'templates')
|
||||
|
||||
args["len"] = len
|
||||
|
||||
jenv = Environment(loader = FileSystemLoader(templates_path))
|
||||
html = jenv.get_template(args['template']).render(args)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user