def execute(): """Make server custom script readonly for system manager""" import webnotes.model.doc new_perms = [ { 'parent': 'Custom Script', 'parentfield': 'permissions', 'parenttype': 'DocType', 'role': 'System Manager', 'permlevel': 1, 'read': 1, }, { 'parent': 'Custom Script', 'parentfield': 'permissions', 'parenttype': 'DocType', 'role': 'Administrator', 'permlevel': 1, 'read': 1, 'write': 1 }, ] for perms in new_perms: doc = webnotes.model.doc.Document('DocPerm') doc.fields.update(perms) doc.save() webnotes.conn.commit() webnotes.conn.begin() import webnotes.model.sync webnotes.model.sync.sync('core', 'custom_script')
def execute(): """Make server custom script readonly for system manager""" import webnotes.model.doc new_perms = [ { "parent": "Custom Script", "parentfield": "permissions", "parenttype": "DocType", "role": "System Manager", "permlevel": 1, "read": 1, }, { "parent": "Custom Script", "parentfield": "permissions", "parenttype": "DocType", "role": "Administrator", "permlevel": 1, "read": 1, "write": 1, }, ] for perms in new_perms: doc = webnotes.model.doc.Document("DocPerm") doc.fields.update(perms) doc.save() webnotes.conn.commit() webnotes.conn.begin() import webnotes.model.sync webnotes.model.sync.sync("core", "custom_script")
def execute(): import webnotes import webnotes.model.doc webnotes.conn.sql( "delete from `tabDocPerm` where parent='Profile' and permlevel=1") new_perms = [ { 'parent': 'Profile', 'parentfield': 'permissions', 'parenttype': 'DocType', 'role': 'Administrator', 'permlevel': 1, 'read': 1, 'write': 1 }, { 'parent': 'Profile', 'parentfield': 'permissions', 'parenttype': 'DocType', 'role': 'System Manager', 'permlevel': 1, 'read': 1, 'write': 1 }, ] for perms in new_perms: doc = webnotes.model.doc.Document('DocPerm') doc.fields.update(perms) doc.save() webnotes.conn.commit() webnotes.conn.begin() import webnotes.model.sync webnotes.model.sync.sync('core', 'profile')
def execute(): """Make server custom script readonly for system manager""" import webnotes.model.doc new_perms = [ { 'parent': 'Custom Script', 'parentfield': 'permissions', 'parenttype': 'DocType', 'role': 'System Manager', 'permlevel': 1, 'read': 1, }, { 'parent': 'Custom Script', 'parentfield': 'permissions', 'parenttype': 'DocType', 'role': 'Administrator', 'permlevel': 1, 'read': 1, 'write': 1 }, ] for perms in new_perms: doc = webnotes.model.doc.Document('DocPerm') doc.fields.update(perms) doc.save() webnotes.conn.commit() webnotes.conn.begin() webnotes.reload_doc('core', 'doctype', 'custom_script')
def execute(): import webnotes import webnotes.model.doc webnotes.conn.sql("delete from `tabDocPerm` where parent='Profile' and permlevel=1") new_perms = [ { 'parent': 'Profile', 'parentfield': 'permissions', 'parenttype': 'DocType', 'role': 'Administrator', 'permlevel': 1, 'read': 1, 'write': 1 }, { 'parent': 'Profile', 'parentfield': 'permissions', 'parenttype': 'DocType', 'role': 'System Manager', 'permlevel': 1, 'read': 1, 'write': 1 }, ] for perms in new_perms: doc = webnotes.model.doc.Document('DocPerm') doc.fields.update(perms) doc.save() webnotes.conn.commit() webnotes.conn.begin() import webnotes.model.sync webnotes.model.sync.sync('core', 'profile')
def execute(): """Make standard print formats readonly for system manager""" import webnotes.model.doc new_perms = [ { 'parent': 'Print Format', 'parentfield': 'permissions', 'parenttype': 'DocType', 'role': 'System Manager', 'permlevel': 1, 'read': 1, }, { 'parent': 'Print Format', 'parentfield': 'permissions', 'parenttype': 'DocType', 'role': 'Administrator', 'permlevel': 1, 'read': 1, 'write': 1 }, ] for perms in new_perms: doc = webnotes.model.doc.Document('DocPerm') doc.fields.update(perms) doc.save() webnotes.conn.commit() webnotes.conn.begin() webnotes.reload_doc('core', 'doctype', 'print_format')
def execute(): """Make standard print formats readonly for system manager""" import webnotes.model.doc new_perms = [ { 'parent': 'Print Format', 'parentfield': 'permissions', 'parenttype': 'DocType', 'role': 'System Manager', 'permlevel': 1, 'read': 1, }, { 'parent': 'Print Format', 'parentfield': 'permissions', 'parenttype': 'DocType', 'role': 'Administrator', 'permlevel': 1, 'read': 1, 'write': 1 }, ] for perms in new_perms: doc = webnotes.model.doc.Document('DocPerm') doc.fields.update(perms) doc.save() webnotes.conn.commit() webnotes.conn.begin() import webnotes.model.sync webnotes.model.sync.sync('core', 'print_format')
def execute(): """Make profile readonly for role All""" import webnotes.model.doc webnotes.conn.sql("delete from `tabDocPerm` where parent='Profile' and role='All'") new_perms = [ { 'parent': 'Profile', 'parentfield': 'permissions', 'parenttype': 'DocType', 'role': 'All', 'permlevel': 0, 'read': 1, }, ] for perms in new_perms: doc = webnotes.model.doc.Document('DocPerm') doc.fields.update(perms) doc.save() webnotes.conn.commit() webnotes.conn.begin() webnotes.reload_doc('core', 'doctype', 'profile')
def execute(): """Make profile readonly for role All""" import webnotes.model.doc webnotes.conn.sql("delete from `tabDocPerm` where parent='Profile' and role='All'") new_perms = [ { 'parent': 'Profile', 'parentfield': 'permissions', 'parenttype': 'DocType', 'role': 'All', 'permlevel': 0, 'read': 1, }, ] for perms in new_perms: doc = webnotes.model.doc.Document('DocPerm') doc.fields.update(perms) doc.save() webnotes.conn.commit() webnotes.conn.begin() import webnotes.model.sync webnotes.model.sync.sync('core', 'profile')
bean.insert() ret.append('Inserted row (#%d) %s' % (row_idx + 1, getlink(bean.doc.doctype, bean.doc.name))) if submit_after_import: bean.submit() ret.append('Submitted row (#%d) %s' % (row_idx + 1, getlink(bean.doc.doctype, bean.doc.name))) else: check_record(doclist[0], parenttype, doctype_dl) if parenttype: # child doc doc = Document(doctype) doc.fields.update(doclist[0]) if parenttype: doc.parenttype = parenttype doc.parentfield = parentfield doc.save() ret.append('Inserted row for %s at #%s' % (getlink(parenttype, doc.parent), unicode(doc.idx))) parent_list.append(doc.parent) else: ret.append(import_doc(doclist[0], doctype, overwrite, row_idx, submit_after_import, ignore_links)) except Exception, e: error = True if bean: webnotes.errprint(bean.doclist) err_msg = webnotes.local.message_log and "<br>".join(webnotes.local.message_log) or cstr(e) ret.append('Error for row (#%d) %s : %s' % (row_idx + 1, len(row)>1 and row[1] or "", err_msg)) webnotes.errprint(webnotes.get_traceback())
if submit_after_import: bean.submit() ret.append('Submitted row (#%d) %s' % (row_idx + 1, getlink(bean.doc.doctype, bean.doc.name))) else: check_record(doclist[0], parenttype, doctype_dl) if parenttype: # child doc doc = Document(doctype) doc.fields.update(doclist[0]) if parenttype: doc.parenttype = parenttype doc.parentfield = parentfield doc.save() ret.append( 'Inserted row for %s at #%s' % (getlink(parenttype, doc.parent), unicode(doc.idx))) parent_list.append(doc.parent) else: ret.append( import_doc(doclist[0], doctype, overwrite, row_idx, submit_after_import, ignore_links)) except Exception, e: error = True if bean: webnotes.errprint(bean.doclist) err_msg = webnotes.message_log and "<br>".join( webnotes.message_log) or cstr(e)
def upload(): """upload data""" webnotes.mute_emails = True from webnotes.utils.datautils import read_csv_content_from_uploaded_file def bad_template(): webnotes.msgprint("Please do not change the rows above '%s'" % data_keys.data_separator, raise_exception=1) def check_data_length(): max_rows = 5000 if not data: webnotes.msgprint("No data found", raise_exception=True) elif len(data) > max_rows: webnotes.msgprint("Please upload only upto %d %ss at a time" % \ (max_rows, doctype), raise_exception=True) def get_start_row(): for i, row in enumerate(rows): if row and row[0]==data_keys.data_separator: return i+1 bad_template() def get_header_row(key): for i, row in enumerate(header): if row and row[0]==key: return row return [] def filter_empty_columns(columns): empty_cols = filter(lambda x: x in ("", None), columns) if empty_cols: if columns[-1*len(empty_cols):] == empty_cols: # filter empty columns if they exist at the end columns = columns[:-1*len(empty_cols)] else: webnotes.msgprint(_("Please make sure that there are no empty columns in the file."), raise_exception=1) return columns # extra input params import json params = json.loads(webnotes.form_dict.get("params") or '{}') # header rows = read_csv_content_from_uploaded_file(params.get("ignore_encoding_errors")) start_row = get_start_row() header = rows[:start_row] data = rows[start_row:] doctype = get_header_row(data_keys.main_table)[1] columns = filter_empty_columns(get_header_row(data_keys.columns)[1:]) parenttype = get_header_row(data_keys.parent_table) if len(parenttype) > 1: parenttype = parenttype[1] parentfield = get_parent_field(doctype, parenttype) # allow limit rows to be uploaded check_data_length() webnotes.conn.begin() overwrite = params.get('overwrite') doctype_dl = webnotes.model.doctype.get(doctype) # delete child rows (if parenttype) if parenttype and overwrite: delete_child_rows(data, doctype) ret = [] error = False parent_list = [] for i, row in enumerate(data): # bypass empty rows if not row: continue row_idx = (i + 1) + start_row d = webnotes._dict(zip(columns, row[1:])) d['doctype'] = doctype try: check_record(d, parenttype, doctype_dl) if parenttype: # child doc doc = Document(doctype) doc.fields.update(d) if parenttype: doc.parenttype = parenttype doc.parentfield = parentfield doc.save() ret.append('Inserted row for %s at #%s' % (getlink(parenttype, doc.parent), unicode(doc.idx))) parent_list.append(doc.parent) else: ret.append(import_doc(d, doctype, overwrite, row_idx, params.get("_submit"))) except Exception, e: error = True err_msg = webnotes.message_log and "<br>".join(webnotes.message_log) or cstr(e) ret.append('Error for row (#%d) %s : %s' % (row_idx, len(row)>1 and row[1] or "", err_msg)) webnotes.errprint(webnotes.getTraceback()) webnotes.message_log = []
def upload(): """upload data""" global doctype_dl webnotes.mute_emails = True from webnotes.utils.datautils import read_csv_content_from_uploaded_file def bad_template(): webnotes.msgprint("Please do not change the rows above '%s'" % data_keys.data_separator, raise_exception=1) def check_data_length(): max_rows = 500 if not data: webnotes.msgprint("No data found", raise_exception=True) elif len(data) > max_rows: webnotes.msgprint("Please upload only upto %d %ss at a time" % \ (max_rows, doctype), raise_exception=True) def get_start_row(): for i, row in enumerate(rows): if row and row[0]==data_keys.data_separator: return i+1 bad_template() def get_header_row(key): for i, row in enumerate(header): if row and row[0]==key: return row return [] # header rows = read_csv_content_from_uploaded_file() start_row = get_start_row() header = rows[:start_row] data = rows[start_row:] doctype = get_header_row(data_keys.main_table)[1] columns = get_header_row(data_keys.columns)[1:] parenttype = get_header_row(data_keys.parent_table) if len(parenttype) > 1: parenttype = parenttype[1] parentfield = get_parent_field(doctype, parenttype) # allow limit rows to be uploaded check_data_length() webnotes.conn.begin() overwrite = webnotes.form_dict.get('overwrite') doctype_dl = webnotes.model.doctype.get(doctype) # delete child rows (if parenttype) if parenttype and overwrite: delete_child_rows(data, doctype) ret = [] error = False for i, row in enumerate(data): # bypass empty rows if not row: continue row_idx = (i + 1) + start_row d = dict(zip(columns, row[1:])) d['doctype'] = doctype try: check_record(d, parenttype) if parenttype: # child doc doc = Document(doctype) doc.fields.update(d) if parenttype: doc.parenttype = parenttype doc.parentfield = parentfield doc.save() ret.append('Inserted row for %s at #%s' % (getlink(parenttype, doc.parent), unicode(doc.idx))) else: ret.append(import_doc(d, doctype, overwrite, row_idx)) except Exception, e: error = True ret.append('Error for row (#%d) %s : %s' % (row_idx, len(row)>1 and row[1] or "", cstr(e))) webnotes.errprint(webnotes.getTraceback())
def upload(): """upload data""" webnotes.mute_emails = True from webnotes.utils.datautils import read_csv_content_from_uploaded_file def bad_template(): webnotes.msgprint("Please do not change the rows above '%s'" % data_keys.data_separator, raise_exception=1) def check_data_length(): max_rows = 5000 if not data: webnotes.msgprint("No data found", raise_exception=True) elif len(data) > max_rows: webnotes.msgprint("Please upload only upto %d %ss at a time" % \ (max_rows, doctype), raise_exception=True) def get_start_row(): for i, row in enumerate(rows): if row and row[0] == data_keys.data_separator: return i + 1 bad_template() def get_header_row(key): for i, row in enumerate(header): if row and row[0] == key: return row return [] def filter_empty_columns(columns): empty_cols = filter(lambda x: x in ("", None), columns) if empty_cols: if columns[-1 * len(empty_cols):] == empty_cols: # filter empty columns if they exist at the end columns = columns[:-1 * len(empty_cols)] else: webnotes.msgprint(_( "Please make sure that there are no empty columns in the file." ), raise_exception=1) return columns # extra input params import json params = json.loads(webnotes.form_dict.get("params") or '{}') # header rows = read_csv_content_from_uploaded_file( params.get("ignore_encoding_errors")) start_row = get_start_row() header = rows[:start_row] data = rows[start_row:] doctype = get_header_row(data_keys.main_table)[1] columns = filter_empty_columns(get_header_row(data_keys.columns)[1:]) parenttype = get_header_row(data_keys.parent_table) if len(parenttype) > 1: parenttype = parenttype[1] parentfield = get_parent_field(doctype, parenttype) # allow limit rows to be uploaded check_data_length() webnotes.conn.begin() overwrite = params.get('overwrite') doctype_dl = webnotes.model.doctype.get(doctype) # delete child rows (if parenttype) if parenttype and overwrite: delete_child_rows(data, doctype) ret = [] error = False parent_list = [] for i, row in enumerate(data): # bypass empty rows if not row: continue row_idx = (i + 1) + start_row d = webnotes._dict(zip(columns, row[1:])) d['doctype'] = doctype try: check_record(d, parenttype, doctype_dl) if parenttype: # child doc doc = Document(doctype) doc.fields.update(d) if parenttype: doc.parenttype = parenttype doc.parentfield = parentfield doc.save() ret.append('Inserted row for %s at #%s' % (getlink(parenttype, doc.parent), unicode(doc.idx))) parent_list.append(doc.parent) else: ret.append( import_doc(d, doctype, overwrite, row_idx, params.get("_submit"))) except Exception, e: error = True err_msg = webnotes.message_log and "<br>".join( webnotes.message_log) or cstr(e) ret.append('Error for row (#%d) %s : %s' % (row_idx, len(row) > 1 and row[1] or "", err_msg)) webnotes.errprint(webnotes.getTraceback()) webnotes.message_log = []
def savedocs(): import webnotes.model.doclist from webnotes.model.code import get_server_obj from webnotes.model.code import run_server_obj import webnotes.utils from webnotes.utils import cint sql = webnotes.conn.sql form = webnotes.form # action action = form.getvalue('action') # get docs doc, doclist = _get_doclist(webnotes.model.doclist.expand(form.getvalue('docs'))) # get server object server_obj = get_server_obj(doc, doclist) # check integrity if not check_integrity(doc): return if not doc.check_perm(verbose=1): webnotes.msgprint("Not enough permission to save %s" % doc.doctype) return # validate links ret = webnotes.model.doclist.validate_links_doclist([doc] + doclist) if ret: webnotes.msgprint("[Link Validation] Could not find the following values: %s. Please correct and resave. Document Not Saved." % ret) return # saving & post-saving try: # validate befor saving and submitting if action in ('Save', 'Submit') and server_obj: if hasattr(server_obj, 'validate'): t = run_server_obj(server_obj, 'validate') if hasattr(server_obj, 'custom_validate'): t = run_server_obj(server_obj, 'custom_validate') # set owner and modified times is_new = cint(doc.fields.get('__islocal')) if is_new and not doc.owner: doc.owner = form.getvalue('user') doc.modified, doc.modified_by = webnotes.utils.now(), webnotes.session['user'] # save main doc try: t = doc.save(is_new) except NameError, e: webnotes.msgprint('%s "%s" already exists' % (doc.doctype, doc.name)) if webnotes.conn.sql("select docstatus from `tab%s` where name=%s" % (doc.doctype, '%s'), doc.name)[0][0]==2: webnotes.msgprint('[%s "%s" has also been trashed / cancelled]' % (doc.doctype, doc.name)) webnotes.errprint(webnotes.utils.getTraceback()) raise e # save child docs for d in doclist: deleted, local = d.fields.get('__deleted',0), d.fields.get('__islocal',0) if cint(local) and cint(deleted): pass elif d.fields.has_key('parent'): if d.parent and (not d.parent.startswith('old_parent:')): d.parent = doc.name # rename if reqd d.parenttype = doc.doctype d.modified, d.modified_by = webnotes.utils.now(), webnotes.session['user'] d.save(new = cint(local)) # on_update if action in ('Save','Submit') and server_obj: # special for DocType, DocType if doc.doctype == 'DocType': import webnotes.model.doctype webnotes.model.doctype.update_doctype([doc] + doclist) else: if hasattr(server_obj, 'on_update'): t = run_server_obj(server_obj, 'on_update') if t: webnotes.msgprint(t) if hasattr(server_obj, 'custom_on_update'): t = run_server_obj(server_obj, 'custom_on_update') if t: webnotes.msgprint(t) # on_submit if action == 'Submit': _do_action(doc, doclist, server_obj, 'on_submit', 1) # on_submit if action == 'Update': _do_action(doc, doclist, server_obj, 'on_update_after_submit', 0) # on_cancel if action == 'Cancel': _do_action(doc, doclist, server_obj, 'on_cancel', 2) # On Trash if action == 'Trash': _do_action(doc, doclist, server_obj, 'on_trash', 2) # validate validate_trash_doc(doc, doclist) # update recent documents webnotes.user.update_recent(doc.doctype, doc.name) # send updated docs webnotes.response['saved'] = '1' webnotes.response['main_doc_name'] = doc.name webnotes.response['docname'] = doc.name webnotes.response['docs'] = [doc] + doclist
def upload(): """upload data""" global doctype_dl from webnotes.utils.datautils import read_csv_content_from_uploaded_file def bad_template(): webnotes.msgprint("Please do not change the rows above '%s'" % data_keys.data_separator, raise_exception=1) def check_data_length(): max_rows = 500 if not data: webnotes.msgprint("No data found", raise_exception=True) elif len(data) > max_rows: webnotes.msgprint("Please upload only upto %d %ss at a time" % \ (max_rows, doctype), raise_exception=True) def get_start_row(): for i, row in enumerate(rows): if row[0] == data_keys.data_separator: return i + 1 bad_template() def get_header_row(key): for i, row in enumerate(header): if row[0] == key: return row return [] # header rows = read_csv_content_from_uploaded_file() start_row = get_start_row() header = rows[:start_row] data = rows[start_row:] doctype = get_header_row(data_keys.main_table)[1] columns = get_header_row(data_keys.columns)[1:] parenttype = get_header_row(data_keys.parent_table) if len(parenttype) > 1: parenttype = parenttype[1] parentfield = get_parent_field(doctype, parenttype) # allow limit rows to be uploaded check_data_length() webnotes.conn.begin() overwrite = webnotes.form_dict.get('overwrite') doctype_dl = webnotes.model.doctype.get(doctype) # delete child rows (if parenttype) if parenttype and overwrite: delete_child_rows(data, doctype) ret = [] error = False for i, row in enumerate(data): # bypass empty rows if not row: continue row_idx = (i + 1) + start_row d = dict(zip(columns, row[1:])) d['doctype'] = doctype try: check_record(d, parenttype) if parenttype: # child doc doc = Document(doctype) doc.fields.update(d) if parenttype: doc.parenttype = parenttype doc.parentfield = parentfield doc.save() ret.append('Inserted row for %s at #%s' % (getlink(parenttype, doc.parent), unicode(doc.idx))) else: ret.append(import_doc(d, doctype, overwrite, row_idx)) except Exception, e: error = True ret.append('Error for row (#%d) %s : %s' % (row_idx, len(row) > 1 and row[1] or "", cstr(e))) webnotes.errprint(webnotes.getTraceback())