Standard Module View if config/{module}.py file is not found

This commit is contained in:
Anand Doshi 2014-03-03 17:01:02 +05:30
parent d6a0b951ae
commit 5a89da1643
3 changed files with 62 additions and 7 deletions

View file

@ -349,3 +349,16 @@ ul.linked-with-list li {
margin: 0px -15px;
box-shadow: 1px 1px 5px rgba(0,0,0,0.5);
}
/* on small screens, show only icons on top */
@media (max-width: 767px) {
.module-view-layout .nav-stacked > li {
float: left;
margin-bottom: 5px;
}
.nav-stacked > li + li {
margin-top: 0px;
margin-left: 2px;
}
}

View file

@ -101,7 +101,7 @@ frappe.views.moduleview.ModuleView = Class.extend({
},
make_layout: function(wrapper) {
return $('<div class="row">\
return $('<div class="row module-view-layout">\
<div class="col-sm-3">\
<ul class="nav nav-pills nav-stacked"></ul>\
</div>\
@ -118,8 +118,9 @@ frappe.views.moduleview.ModuleView = Class.extend({
// if not found, add section
if(!$nav.length) {
// create nav tab
$nav = $('<li><a><i class="'+d.icon+' icon-fixed-width"></i> '
+ frappe._(d.label)+'</a></li>')
$nav = $('<li title="'+__(d.label)+'">\
<a><i class="'+d.icon+' icon-fixed-width"></i><span class="hidden-xs"> '
+ frappe._(d.label)+'</span></a></li>')
.attr("data-label", d._label)
.appendTo($sections);
@ -210,7 +211,7 @@ frappe.views.moduleview.ModuleView = Class.extend({
var reports_section = {
label: __("Custom Reports"),
icon: "icon-list",
icon: "icon-list-alt",
items: reports
}
this.add_section(reports_section, $layout);

View file

@ -5,10 +5,14 @@ from __future__ import unicode_literals
import frappe, json
from frappe.widgets import reportview
from frappe.utils import cint
from frappe import _
@frappe.whitelist()
def get(module):
data = get_data(module)
if not data:
data = build_standard_config(module)
doctypes = get_doctypes(data)
return {
@ -29,6 +33,43 @@ def get_data(module):
return data
def build_standard_config(module):
if not frappe.db.get_value("Module Def", module):
frappe.throw(_("Module Not Found"))
data = []
doctypes = frappe.db.sql("""select "doctype" as type, name, description,
ifnull(document_type, "") as document_type
from `tabDocType` where module=%s and ifnull(istable, 0)=0
order by document_type desc, name asc""", module, as_dict=True)
documents = [d for d in doctypes if d.document_type in ("Transaction", "Master", "")]
if documents:
data.append({
"label": _("Documents"),
"icon": "icon-star",
"items": documents
})
setup = [d for d in doctypes if d.document_type in ("System", "Other")]
if setup:
data.append({
"label": _("Setup"),
"icon": "icon-cog",
"items": setup
})
reports = get_report_list(module, is_standard="Yes")
if reports:
data.append({
"label": _("Standard Reports"),
"icon": "icon-list",
"items": reports
})
return data
def get_config(app, module):
config = frappe.get_module("{app}.config.{module}".format(app=app, module=module))
return config.get_data() if hasattr(config, "get_data") else config.data
@ -63,7 +104,7 @@ def get_doctype_count_from_table(doctype):
raise
return cint(count)
def get_report_list(module):
def get_report_list(module, is_standard="No"):
"""return list on new style reports for modules"""
return frappe.db.sql("""
select distinct "report" as type, tabReport.name, tabReport.ref_doctype as doctype,
@ -74,6 +115,6 @@ def get_report_list(module):
where tabDocType.module=%s
and tabDocType.name = tabReport.ref_doctype
and tabReport.docstatus in (0, NULL)
and ifnull(tabReport.is_standard, "No")="No"
and ifnull(tabReport.is_standard, "No")=%s
and ifnull(tabReport.disabled,0) != 1
order by tabReport.name""", module, as_dict=True)
order by tabReport.name""", (module, is_standard), as_dict=True)