Merge branch 'master' of github.com:webnotes/wnframework

This commit is contained in:
Nabin Hait 2013-01-16 13:04:24 +05:30
commit be05135f60
7 changed files with 177 additions and 193 deletions

View file

@ -75,6 +75,9 @@ def send_comm_email(d, name, sent_via=None, print_html=None, attachments='[]', s
if hasattr(sent_via, "get_content"):
d.content = sent_via.get_content(d)
if not d.sender:
d.sender = webnotes.session.user
from webnotes.utils.email_lib.smtp import get_email
mail = get_email(d.recipients, sender=d.sender, subject=d.subject,
msg=d.content)
@ -102,21 +105,12 @@ def set_lead_and_contact(d):
email_addr = email.utils.parseaddr(d.sender)
# set contact
if not d.contact:
d.contact = webnotes.conn.get_value("Contact", {"email_id": email_addr[1]}, "name") or None
d.contact = webnotes.conn.get_value("Contact", {"email_id": email_addr[1]},
"name") or None
if not d.lead:
d.lead = webnotes.conn.get_value("Lead", {"email_id": email_addr[1]}, "name") or None
if not (d.lead or d.contact):
d.lead = make_lead(d, email_addr[0], email_addr[1])
def make_lead(d, real_name, email_id):
lead = webnotes.doc("Lead")
lead.lead_name = real_name or email_id
lead.email_id = email_id
lead.source = "Email"
lead.save(1)
return lead.name
d.lead = webnotes.conn.get_value("Lead", {"email_id": email_addr[1]},
"name") or None
class DocType():
def __init__(self, doc, doclist=[]):

View file

@ -496,7 +496,7 @@ _f.Frm.prototype.refresh = function(docname) {
this.check_doctype_conflict(this.docname);
} else {
if(this.doc && this.doc.__last_sync_on &&
(new Date() - this.doc.__last_sync_on) / 1000 > this.refresh_if_stale_for) {
(new Date() - this.doc.__last_sync_on) > (this.refresh_if_stale_for * 1000)) {
this.reload_doc();
return;
}

View file

@ -5,49 +5,66 @@ wn.provide("wn.views.moduleview");
wn.provide("wn.model.open_count_conditions")
wn.views.moduleview.make = function(wrapper, module) {
var doctypes = [];
wrapper.module_view = new wn.views.moduleview.ModuleView(wrapper, module);
wn.ui.make_app_page({
parent: wrapper,
single_column: true,
title: wn._(wn.modules[module].label || module)
});
wrapper.appframe.add_home_breadcrumb();
wrapper.appframe.add_breadcrumb(wn.modules[module].icon);
// make columns
$(wrapper).find(".layout-main").html("<div class='row'>\
<div class='span6 main-section'></div>\
<div class='span5 side-section'></div>\
</div>")
$(wrapper).on("click", ".badge-important", function() {
var doctype = $(this).parent().attr("data-doctype");
var condition = wn.model.open_count_conditions[doctype];
if(condition) {
wn.set_route("List", doctype, wn.utils.get_url_from_dict(condition));
wrapper.refresh = function() {
// remake on refresh
if((new Date() - wrapper.module_view.created_on) > (180 * 1000)) {
wrapper.module_view = new wn.views.moduleview.ModuleView(wrapper, module);
}
});
}
}
$(wrapper).on("click", ".badge-count", function() {
var doctype = $(this).attr("data-doctype-count");
wn.set_route("List", doctype);
});
var add_section = function(section) {
wn.views.moduleview.ModuleView = Class.extend({
init: function(wrapper, module) {
this.doctypes = [];
$(wrapper).empty();
wn.ui.make_app_page({
parent: wrapper,
single_column: true,
title: wn._(wn.modules[module].label || module)
});
wrapper.appframe.add_home_breadcrumb();
wrapper.appframe.add_breadcrumb(wn.modules[module].icon);
this.wrapper = wrapper;
this.module = module;
this.make_body();
this.render_static();
this.render_dynamic();
this.created_on = new Date();
},
make_body: function() {
var wrapper = this.wrapper;
// make columns
$(wrapper).find(".layout-main").html("<div class='row'>\
<div class='span6 main-section'></div>\
<div class='span5 side-section'></div>\
</div>")
$(wrapper).on("click", ".badge-important", function() {
var doctype = $(this).parent().attr("data-doctype");
var condition = wn.model.open_count_conditions[doctype];
if(condition) {
wn.set_route("List", doctype, wn.utils.get_url_from_dict(condition));
}
});
$(wrapper).on("click", ".badge-count", function() {
var doctype = $(this).attr("data-doctype-count");
wn.set_route("List", doctype);
});
},
add_section: function(section) {
var table = $(repl("<table class='table table-bordered'>\
<thead><tr>\
<th style='font-size: 120%;'><i class='%(icon)s'></i> %(title)s</th></tr></thead>\
<tbody></tbody>\
</table>", section)).appendTo(section.right
? $(wrapper).find(".side-section")
: $(wrapper).find(".main-section"));
? $(this.wrapper).find(".side-section")
: $(this.wrapper).find(".main-section"));
section.table = table;
}
var add_item = function(item, section) {
},
add_item: function(item, section) {
if(!item.description) item.description = "";
if(item.count==null) item.count = "";
@ -55,7 +72,7 @@ wn.views.moduleview.make = function(wrapper, module) {
<span"+
((item.doctype && item.description)
? " data-doctype='"+item.doctype+"'" : "")
+" class='"+(section.right ? 'span4' : 'span2')
+" class='"+(section.right ? 'spanf4' : 'span2')
+"'>%(link)s</span>\
<span class='help "+(section.right ? 'span4' : 'span3')
+"'>%(description)s</span>"
@ -64,108 +81,113 @@ wn.views.moduleview.make = function(wrapper, module) {
: '<span data-doctype-count="%(doctype)s"></span>')
+ "</div></td></tr>", item))
.appendTo(section.table.find("tbody"));
}
// render sections
$.each(wn.module_page[module], function(i, section) {
add_section(section);
$.each(section.items, function(i, item) {
if(item.doctype) doctypes.push(item.doctype);
if(item.doctype && !item.route) {
item.route = "List/" + encodeURIComponent(item.doctype);
}
if(item.page && !item.route) {
item.route = item.page;
}
// link
item.link = repl("<a href='#%(route)s'>%(label)s</a>", item);
// doctype permissions
if(item.doctype && !wn.model.can_read(item.doctype)) {
item.link = item.label;
}
// page permissions
if(item.page && !in_list(wn.boot.allowed_pages, item.page)) {
item.link = item.label;
}
if((item.country && wn.boot.control_panel.country==item.country)
|| !item.country)
add_item(item, section)
})
});
// render reports
wn.call({
method: "webnotes.widgets.moduleview.get_data",
args: {
module: module,
doctypes: doctypes
},
callback: function(r) {
if(r.message) {
// reports
if(r.message.reports.length) {
var section = {
title: wn._("Custom Reports"),
right: true,
icon: "icon-list",
}
add_section(section);
$.each(r.message.reports, function(i, item) {
if(wn.model.can_read(item.doctype)) {
if(item.is_query_report) {
item.link = repl("<a href=\"#query-report/%(name)s\">%(name)s</a>",
item);
} else {
item.link = repl("<a href=\"#Report2/%(doctype)s/%(name)s\">\
%(name)s</a>", item);
}
add_item(item, section);
}
})
},
render_static: function() {
// render sections
var me = this;
$.each(wn.module_page[this.module], function(i, section) {
me.add_section(section);
$.each(section.items, function(i, item) {
if(item.doctype)
me.doctypes.push(item.doctype);
if(item.doctype && !item.route) {
item.route = "List/" + encodeURIComponent(item.doctype);
}
// search criteria
if(r.message.search_criteria.length) {
var section = {
title: wn._("Old Style Reports"),
right: true,
icon: "icon-list-alt",
}
add_section(section);
$.each(r.message.search_criteria, function(i, item) {
item.criteria_name_enc = encodeURIComponent(item.criteria_name);
if(wn.model.can_read(item.parent_doctype || item.doctype)) {
item.link = repl(
"<a href=\"#Report/%(doctype)s/%(criteria_name_enc)s\">\
%(criteria_name)s</a>", item);
add_item(item, section);
}
})
}
// counts
if(r.message.item_count) {
$.each(r.message.item_count, function(doctype, count) {
$(wrapper).find("[data-doctype-count='"+doctype+"']")
.html(count)
.addClass("badge badge-count")
.css({cursor:"pointer"});
})
if(item.page && !item.route) {
item.route = item.page;
}
// counts
if(r.message.open_count) {
$.extend(wn.model.open_count_conditions, r.message.conditions);
$.each(r.message.open_count, function(doctype, count) {
$(wrapper).find("[data-doctype='"+doctype+"']")
.append(" <span class='badge badge-important pull-right'\
style='cursor:pointer'>" + count + "</span>");
})
// link
item.link = repl("<a href='#%(route)s'>%(label)s</a>", item);
// doctype permissions
if(item.doctype && !wn.model.can_read(item.doctype)) {
item.link = item.label;
}
// page permissions
if(item.page && !in_list(wn.boot.allowed_pages, item.page)) {
item.link = item.label;
}
if((item.country && wn.boot.control_panel.country==item.country)
|| !item.country)
me.add_item(item, section)
})
});
},
render_dynamic: function() {
// render reports
var me = this;
wn.call({
method: "webnotes.widgets.moduleview.get_data",
args: {
module: me.module,
doctypes: me.doctypes
},
callback: function(r) {
if(r.message) {
// reports
if(r.message.reports.length) {
var section = {
title: wn._("Custom Reports"),
right: true,
icon: "icon-list",
}
me.add_section(section);
$.each(r.message.reports, function(i, item) {
if(wn.model.can_read(item.doctype)) {
if(item.is_query_report) {
item.link = repl("<a href=\"#query-report/%(name)s\">%(name)s</a>",
item);
} else {
item.link = repl("<a href=\"#Report2/%(doctype)s/%(name)s\">\
%(name)s</a>", item);
}
me.add_item(item, section);
}
})
}
// search criteria
if(r.message.search_criteria.length) {
var section = {
title: wn._("Old Style Reports"),
right: true,
icon: "icon-list-alt",
}
me.add_section(section);
$.each(r.message.search_criteria, function(i, item) {
item.criteria_name_enc = encodeURIComponent(item.criteria_name);
if(wn.model.can_read(item.parent_doctype || item.doctype)) {
item.link = repl(
"<a href=\"#Report/%(doctype)s/%(criteria_name_enc)s\">\
%(criteria_name)s</a>", item);
me.add_item(item, section);
}
})
}
// counts
if(r.message.item_count) {
$.each(r.message.item_count, function(doctype, count) {
$(me.wrapper).find("[data-doctype-count='"+doctype+"']")
.html(count)
.addClass("badge badge-count")
.css({cursor:"pointer"});
})
}
// counts
if(r.message.open_count) {
$.extend(wn.model.open_count_conditions, r.message.conditions);
$.each(r.message.open_count, function(doctype, count) {
$(me.wrapper).find("[data-doctype='"+doctype+"']")
.append(" <span class='badge badge-important pull-right'\
style='cursor:pointer'>" + count + "</span>");
})
}
}
}
}
});
}
});
}
});

View file

@ -53,10 +53,6 @@ class CustomDocType(DocType):
'''
#=================================================================================
# execute a script with a lot of globals - deprecated
#=================================================================================
def execute(code, doc=None, doclist=[]):
"""
Execute the code, if doc is given, then return the instance of the `DocType` class created
@ -91,10 +87,6 @@ def execute(code, doc=None, doclist=[]):
if locals().get('out'):
return out
#=================================================================================
# load the DocType class from module & return an instance
#=================================================================================
def get_custom_script(doctype, script_type):
"""
Returns custom script if set in doctype `Custom Script`
@ -148,10 +140,6 @@ def get_server_obj(doc, doclist = [], basedoctype = ''):
else:
return DocType(doc, doclist)
#=================================================================================
# get object (from dt and/or dn or doclist)
#=================================================================================
def get_obj(dt = None, dn = None, doc=None, doclist=[], with_children = 0):
"""
Returns the instantiated `DocType` object. Here you can pass the DocType and name (ID) to get the object.
@ -163,17 +151,13 @@ def get_obj(dt = None, dn = None, doc=None, doclist=[], with_children = 0):
if not dn:
dn = dt
if with_children:
doclist = webnotes.model.doc.get(dt, dn, from_get_obj=1)
doclist = webnotes.model.doc.get(dt, dn, from_controller=1)
else:
doclist = webnotes.model.doc.get(dt, dn, with_children = 0, from_get_obj=1)
doclist = webnotes.model.doc.get(dt, dn, with_children = 0, from_controller=1)
return get_server_obj(doclist[0], doclist)
else:
return get_server_obj(doc, doclist)
#=================================================================================
# get object and run method
#=================================================================================
def run_server_obj(server_obj, method_name, arg=None):
"""
Executes a method (`method_name`) from the given object (`server_obj`)
@ -186,17 +170,6 @@ def run_server_obj(server_obj, method_name, arg=None):
else:
raise Exception, 'No method %s' % method_name
#=================================================================================
# deprecated methods to keep v160 apps happy
#=================================================================================
def updatedb(doctype, userfields = [], args = {}):
pass
def check_syntax(code):
return ''
#===================================================================================
def get_code(module, dt, dn, extn, fieldname=None):
from webnotes.modules import scrub, get_module_path
import os, webnotes

View file

@ -670,12 +670,7 @@ def get_report_builder_code(doc):
doc.report_script = get_code(doc.module, 'Search Criteria', doc.name, 'js')
doc.custom_query = get_code(doc.module, 'Search Criteria', doc.name, 'sql')
# called from everywhere
# load a record and its child records and bundle it in a list - doclist
# ---------------------------------------------------------------------
def get(dt, dn='', with_children = 1, from_get_obj = 0, prefix = 'tab'):
def get(dt, dn='', with_children = 1, from_controller = 0, prefix = 'tab'):
"""
Returns a doclist containing the main record and all child records
"""
@ -688,14 +683,8 @@ def get(dt, dn='', with_children = 1, from_get_obj = 0, prefix = 'tab'):
# load the main doc
doc = Document(dt, dn, prefix=prefix)
# check permission - for doctypes, pages
if (dt in ('DocType', 'Page', 'Control Panel', 'Search Criteria')) or (from_get_obj and webnotes.session.get('user') != 'Guest'):
if dt=='Page' and webnotes.session['user'] == 'Guest':
check_page_perm(doc)
else:
if not webnotes.has_permission(dt, "read", doc):
webnotes.response['403'] = 1
raise webnotes.ValidationError, '[WNF] No read permission for %s %s' % (dt, dn)
if dt=='Page' and webnotes.session['user'] == 'Guest':
check_page_perm(doc)
if not with_children:
# done
@ -710,7 +699,7 @@ def get(dt, dn='', with_children = 1, from_get_obj = 0, prefix = 'tab'):
doclist += getchildren(doc.name, t[0], t[1], dt, prefix=prefix)
# import report_builder code
if not from_get_obj:
if not from_controller:
get_report_builder_code(doc)
return doclist

View file

@ -240,6 +240,9 @@ class ModelWrapper:
self.doc.fields["__islocal"] = 1
return self.save()
def has_read_perm(self):
return webnotes.has_permission(self.doc.doctype, "read", self.doc)
def save(self, check_links=1):
if self.ignore_permissions or webnotes.has_permission(self.doc.doctype, "write", self.doc):
self.prepare_for_save(check_links)

View file

@ -22,6 +22,7 @@
from __future__ import unicode_literals
import webnotes
from webnotes import _
@webnotes.whitelist()
def runserverobj():
@ -45,6 +46,8 @@ def runserverobj():
else:
wrapper = ModelWrapper()
wrapper.from_compressed(webnotes.form_dict.get('docs'), dn)
if not wrapper.has_read_perm():
webnotes.msgprint(_("No Permission"), raise_exception = True)
so = wrapper.make_obj()
wrapper.check_if_latest()