diff --git a/core/doctype/control_panel/control_panel.py b/core/doctype/control_panel/control_panel.py
index cad9748815..c487e2a97d 100644
--- a/core/doctype/control_panel/control_panel.py
+++ b/core/doctype/control_panel/control_panel.py
@@ -25,9 +25,6 @@ import webnotes
from webnotes import form, msgprint
-
-
-
class DocType:
def __init__(self, doc, doclist):
self.doc = doc
diff --git a/core/doctype/doctype/doctype.py b/core/doctype/doctype/doctype.py
index b0a1aebfbd..9ce5b630b2 100644
--- a/core/doctype/doctype/doctype.py
+++ b/core/doctype/doctype/doctype.py
@@ -111,7 +111,7 @@ class DocType:
webnotes.conn.sql("delete from `tabProperty Setter` where doc_type = %s", self.doc.name)
webnotes.conn.sql("delete from `tabSearch Criteria` where doc_type = %s", self.doc.name)
- def on_rename(self, new, old):
+ def on_rename(self, new, old, merge=False):
if self.doc.issingle:
webnotes.conn.sql("""\
update tabSingles set doctype=%s
diff --git a/core/doctype/profile/profile.py b/core/doctype/profile/profile.py
index 10bdd86a8b..af96bf2b9b 100644
--- a/core/doctype/profile/profile.py
+++ b/core/doctype/profile/profile.py
@@ -22,7 +22,7 @@
from __future__ import unicode_literals
import webnotes, json
-from webnotes.utils import cint, now
+from webnotes.utils import cint, now, cstr
from webnotes import _
class DocType:
@@ -32,19 +32,14 @@ class DocType:
def autoname(self):
"""set name as email id"""
- import re
- from webnotes.utils import validate_email_add
-
if self.doc.name not in ('Guest','Administrator'):
- self.doc.email = self.doc.email.strip()
- if not validate_email_add(self.doc.email):
- webnotes.msgprint("%s is not a valid email id" % self.doc.email)
- raise Exception
-
+ self.doc.email = self.doc.email.strip()
self.doc.name = self.doc.email
def validate(self):
self.in_insert = self.doc.fields.get("__islocal")
+ if self.doc.name not in ('Guest','Administrator'):
+ self.validate_email_type(self.doc.email)
self.validate_max_users()
self.check_one_system_manager()
self.check_enable_disable()
@@ -67,9 +62,11 @@ class DocType:
import conf
# check only when enabling a user
if hasattr(conf, 'max_users') and self.doc.enabled and \
- self.doc.name not in ["Administrator", "Guest"]:
+ self.doc.name not in ["Administrator", "Guest"] and \
+ cstr(self.doc.user_type).strip() in ("", "System User"):
active_users = webnotes.conn.sql("""select count(*) from tabProfile
where ifnull(enabled, 0)=1 and docstatus<2
+ and ifnull(user_type, "System User") = "System User"
and name not in ('Administrator', 'Guest', %s)""", (self.doc.name,))[0][0]
if active_users >= conf.max_users and conf.max_users:
webnotes.msgprint("""
@@ -188,7 +185,7 @@ Thank you,
'user_fullname': get_user_fullname(webnotes.session['user'])
}
- sender = webnotes.session.user != "Administrator" and webnotes.session.user or None
+ sender = webnotes.session.user not in ("Administrator", "Guest") and webnotes.session.user or None
sendmail_md(recipients=self.doc.email, sender=sender, subject=subject, msg=txt % args)
@@ -219,11 +216,8 @@ Thank you,
webnotes.conn.sql("""delete from `tabComment` where comment_doctype='Message'
and (comment_docname=%s or owner=%s)""", (self.doc.name, self.doc.name))
- def on_rename(self,newdn,olddn):
- # do not allow renaming administrator and guest
- if olddn in ["Administrator", "Guest"]:
- webnotes.msgprint("""Hey! You are restricted from renaming the user: %s""" % \
- (olddn, ), raise_exception=1)
+ def on_rename(self,newdn,olddn, merge=False):
+ self.validate_rename(newdn, olddn)
tables = webnotes.conn.sql("show tables")
for tab in tables:
@@ -244,7 +238,24 @@ Thank you,
where name=%s""", (newdn, newdn))
# update __Auth table
- webnotes.conn.sql("""update __Auth set user=%s where user=%s""", (newdn, olddn))
+ if not merge:
+ webnotes.conn.sql("""update __Auth set user=%s where user=%s""", (newdn, olddn))
+
+ def validate_rename(self, newdn, olddn):
+ # do not allow renaming administrator and guest
+ if olddn in ["Administrator", "Guest"]:
+ webnotes.msgprint("""Hey! You are restricted from renaming the user: %s""" % \
+ (olddn, ), raise_exception=1)
+
+ self.validate_email_type(newdn)
+
+ def validate_email_type(self, email):
+ from webnotes.utils import validate_email_add
+
+ email = email.strip()
+ if not validate_email_add(email):
+ webnotes.msgprint("%s is not a valid email id" % email)
+ raise Exception
@webnotes.whitelist()
def get_all_roles(arg=None):
diff --git a/core/page/data_import_tool/data_import_tool.py b/core/page/data_import_tool/data_import_tool.py
index 7aeff6672d..83a79c5281 100644
--- a/core/page/data_import_tool/data_import_tool.py
+++ b/core/page/data_import_tool/data_import_tool.py
@@ -4,8 +4,8 @@ import webnotes
import webnotes.model.doc
import webnotes.model.doctype
from webnotes.model.doc import Document
-from webnotes.utils import cstr, cint, flt
-from webnotes.utils.datautils import UnicodeWriter
+from webnotes.utils import cstr
+from webnotes.utils.datautils import UnicodeWriter, check_record, import_doc, getlink
from webnotes import _
data_keys = webnotes._dict({
@@ -15,8 +15,6 @@ data_keys = webnotes._dict({
"columns": "Column Name:"
})
-doctype_dl = None
-
@webnotes.whitelist()
def get_doctypes():
return [r[0] for r in webnotes.conn.sql("""select name from `tabDocType`
@@ -31,8 +29,6 @@ def get_doctype_options():
@webnotes.whitelist(allow_roles=['System Manager', 'Administrator'])
def get_template():
- global doctype_dl
-
doctype = webnotes.form_dict['doctype']
parenttype = webnotes.form_dict.get('parent_doctype')
@@ -133,8 +129,6 @@ def get_template():
@webnotes.whitelist(allow_roles=['System Manager', 'Administrator'])
def upload():
"""upload data"""
- global doctype_dl
-
webnotes.mute_emails = True
from webnotes.utils.datautils import read_csv_content_from_uploaded_file
@@ -214,11 +208,11 @@ def upload():
row_idx = (i + 1) + start_row
- d = dict(zip(columns, row[1:]))
+ d = webnotes._dict(zip(columns, row[1:]))
d['doctype'] = doctype
try:
- check_record(d, parenttype)
+ check_record(d, parenttype, doctype_dl)
if parenttype:
# child doc
doc = Document(doctype)
@@ -262,72 +256,8 @@ def get_parent_field(doctype, parenttype):
raise Exception
return parentfield
-
-def check_record(d, parenttype=None):
- """check for mandatory, select options, dates. these should ideally be in doclist"""
-
- from webnotes.utils.dateutils import parse_date
- if parenttype and not d.get('parent'):
- raise Exception, "parent is required."
-
- global doctype_dl
- if not doctype_dl:
- doctype_dl = webnotes.model.doctype.get(d.doctype)
-
- for key in d:
- docfield = doctype_dl.get_field(key)
- val = d[key]
- if docfield:
- if docfield.reqd and (val=='' or val==None):
- raise Exception, "%s is mandatory." % key
-
- if docfield.fieldtype=='Select' and val and docfield.options:
- if docfield.options.startswith('link:'):
- link_doctype = docfield.options.split(':')[1]
- if not webnotes.conn.exists(link_doctype, val):
- raise Exception, "%s must be a valid %s" % (key, link_doctype)
- elif docfield.options == "attach_files:":
- pass
-
- elif val not in docfield.options.split('\n'):
- raise Exception, "%s must be one of: %s" % (key,
- ", ".join(filter(None, docfield.options.split("\n"))))
-
- if val and docfield.fieldtype=='Date':
- d[key] = parse_date(val)
- elif val and docfield.fieldtype in ["Int", "Check"]:
- d[key] = cint(val)
- elif val and docfield.fieldtype in ["Currency", "Float"]:
- d[key] = flt(val)
-
-def getlink(doctype, name):
- return '%(name)s' % locals()
def delete_child_rows(rows, doctype):
"""delete child rows for all parents"""
for p in list(set([r[1] for r in rows])):
webnotes.conn.sql("""delete from `tab%s` where parent=%s""" % (doctype, '%s'), p)
-
-def import_doc(d, doctype, overwrite, row_idx, submit=False):
- """import main (non child) document"""
- if webnotes.conn.exists(doctype, d['name']):
- if overwrite:
- bean = webnotes.bean(doctype, d['name'])
- bean.doc.fields.update(d)
- if d.get("docstatus") == 1:
- bean.update_after_submit()
- else:
- bean.save()
- return 'Updated row (#%d) %s' % (row_idx, getlink(doctype, d['name']))
- else:
- return 'Ignored row (#%d) %s (exists)' % (row_idx,
- getlink(doctype, d['name']))
- else:
- bean = webnotes.bean([d])
- bean.insert()
-
- if submit:
- bean.submit()
-
- return 'Inserted row (#%d) %s' % (row_idx, getlink(doctype,
- bean.doc.fields['name']))
diff --git a/core/page/modules_setup/modules_setup.js b/core/page/modules_setup/modules_setup.js
index e5de902520..856bb63d10 100644
--- a/core/page/modules_setup/modules_setup.js
+++ b/core/page/modules_setup/modules_setup.js
@@ -24,7 +24,7 @@ wn.modules_setup = {
if(m!="Setup") {
var $chk = $("")
.prependTo($('
'+m+'
').appendTo("#modules-list")); - if(wn.boot.hidden_modules.indexOf(m)==-1) { + if(!wn.boot.hidden_modules || wn.boot.hidden_modules.indexOf(m)==-1) { $chk.attr("checked", true); } } diff --git a/public/js/legacy/utils/datatype.js b/public/js/legacy/utils/datatype.js index 1494aaa04e..56a568c934 100644 --- a/public/js/legacy/utils/datatype.js +++ b/public/js/legacy/utils/datatype.js @@ -73,7 +73,7 @@ function cint(v, def) { v=v+''; v=lstrip(v, ['0']); v=parseInt(v); - if(isNaN(v))v=def?def:0; + if(isNaN(v))v=def===undefined?0:def; return v; } function validate_email(txt) { diff --git a/public/js/legacy/widgets/form/fields.js b/public/js/legacy/widgets/form/fields.js index 48c98b6fc2..4f801d7e77 100644 --- a/public/js/legacy/widgets/form/fields.js +++ b/public/js/legacy/widgets/form/fields.js @@ -942,9 +942,9 @@ CurrencyField.prototype.get_field_currency = function() { }; CurrencyField.prototype.get_formatted = function(val) { - if(this.not_in_form) + if(!this.doctype) return val; - + return format_currency(val, this.get_field_currency()); } CurrencyField.prototype.set_disp = function(val) { @@ -1088,7 +1088,7 @@ SelectField.prototype.make_input = function() { padding-left: 6px; padding-right: 6px; margin-left: 6px;'>\ ") .click(function() { - cur_frm.attachments.new_attachment(); + cur_frm.attachments.new_attachment(me.df.fieldname); }) .appendTo(this.input_area); } diff --git a/public/js/legacy/widgets/form/form.js b/public/js/legacy/widgets/form/form.js index d1b9a7b569..c31c09a8fa 100644 --- a/public/js/legacy/widgets/form/form.js +++ b/public/js/legacy/widgets/form/form.js @@ -696,11 +696,15 @@ _f.Frm.prototype.refresh_dependency = function() { // show / hide if(f.guardian_has_value) { - f.df.hidden = 0; - f.refresh(); + if(f.df.hidden != 0) { + f.df.hidden = 0; + f.refresh(); + } } else { - f.df.hidden = 1; - f.refresh(); + if(f.df.hidden != 1) { + f.df.hidden = 1; + f.refresh(); + } } } } diff --git a/public/js/legacy/widgets/form/grid.js b/public/js/legacy/widgets/form/grid.js index 26db9cdde7..9c3db75182 100644 --- a/public/js/legacy/widgets/form/grid.js +++ b/public/js/legacy/widgets/form/grid.js @@ -247,7 +247,8 @@ _f.Grid.prototype.set_cell_value = function(cell) { // variations if(cell.cellIndex) { $(cell.div).html(wn.format(v, hc.df, {for_print: - ((doc && doc.docstatus==0 && !cint(hc.df ? hc.df.read_only : 1)) ? true : false)})); + ((doc && doc.docstatus==0 && !cint(hc.df ? hc.df.read_only : 1)) + ? true : false)}, doc)); } else { // Index column cell.div.style.padding = '2px'; diff --git a/public/js/wn/form/attachments.js b/public/js/wn/form/attachments.js index cb9788ac82..7c43151c70 100644 --- a/public/js/wn/form/attachments.js +++ b/public/js/wn/form/attachments.js @@ -62,11 +62,14 @@ wn.ui.form.Attachments = Class.extend({ var file_list = this.get_file_list(); var file_names = keys(file_list).sort(); - + // add attachment objects for(var i=0; i