def validate_rename(doctype, new, meta, merge, force, ignore_permissions): exists = frappe.db.exists(doctype, new) if merge and not exists: frappe.msgprint( _("{0} {1} does not exist, select a new target to merge").format( doctype, new), raise_exception=1) if (not merge) and exists: frappe.msgprint( _("Another {0} with name {1} exists, select another name").format( doctype, new), raise_exception=1) if not (ignore_permissions or frappe.has_permission(doctype, "write")): frappe.msgprint(_("You need write permission to rename"), raise_exception=1) if not force and not meta.allow_rename: frappe.msgprint(_("{0} not allowed to be renamed").format(_(doctype)), raise_exception=1) # validate naming like it's done in doc.py new = validate_name(doctype, new, merge=merge) return new
def validate_rename(doctype, new, meta, merge, force, ignore_permissions): # using for update so that it gets locked and someone else cannot edit it while this rename is going on! exists = frappe.db.sql( "select name from `tab{doctype}` where name=%s for update".format( doctype=doctype), new) exists = exists[0][0] if exists else None if merge and not exists: frappe.msgprint( _("{0} {1} does not exist, select a new target to merge").format( doctype, new), raise_exception=1) if (not merge) and exists == new: frappe.msgprint( _("Another {0} with name {1} exists, select another name").format( doctype, new), raise_exception=1) if not (ignore_permissions or frappe.has_permission(doctype, "write")): frappe.msgprint(_("You need write permission to rename"), raise_exception=1) if not force and not meta.allow_rename: frappe.msgprint(_("{0} not allowed to be renamed").format(_(doctype)), raise_exception=1) # validate naming like it's done in doc.py new = validate_name(doctype, new, merge=merge) return new
def validate_rename(doctype, new, meta, merge, force, ignore_permissions): # using for update so that it gets locked and someone else cannot edit it while this rename is going on! exists = frappe.db.sql("select name from `tab{doctype}` where name=%s for update".format(doctype=frappe.db.escape(doctype)), new) exists = exists[0][0] if exists else None if merge and not exists: frappe.msgprint(_("{0} {1} does not exist, select a new target to merge").format(doctype, new), raise_exception=1) if exists and exists != new: # for fixing case, accents exists = None if (not merge) and exists: frappe.msgprint(_("Another {0} with name {1} exists, select another name").format(doctype, new), raise_exception=1) if not (ignore_permissions or frappe.has_permission(doctype, "write")): frappe.msgprint(_("You need write permission to rename"), raise_exception=1) if not (force or ignore_permissions) and not meta.allow_rename: frappe.msgprint(_("{0} not allowed to be renamed").format(_(doctype)), raise_exception=1) # validate naming like it's done in doc.py new = validate_name(doctype, new, merge=merge) return new
def set_new_name(self, force=False, set_name=None, set_child_names=True): """Calls `frappe.naming.set_new_name` for parent and child docs.""" if self.flags.name_set and not force: return # If autoname has set as Prompt (name) if self.get("__newname"): self.name = validate_name(self.doctype, self.get("__newname")) self.flags.name_set = True return if set_name: self.name = validate_name(self.doctype, set_name) else: set_new_name(self) if set_child_names: # set name for children for d in self.get_all_children(): set_new_name(d) self.flags.name_set = True
def validate_rename(doctype, new, meta, merge, force, ignore_permissions): exists = frappe.db.get_value(doctype, new) if merge and not exists: frappe.msgprint(_("{0} {1} does not exist, select a new target to merge").format(_(doctype), new), raise_exception=1) if (not merge) and exists == new: frappe.msgprint(_("Another {0} with name {1} exists, select another name").format(_(doctype), new), raise_exception=1) if not (ignore_permissions or frappe.has_permission(doctype, "write")): frappe.msgprint(_("You need write permission to rename"), raise_exception=1) if not force and not meta.allow_rename: frappe.msgprint(_("{0} not allowed to be renamed").format(_(doctype)), raise_exception=1) # validate naming like it's done in doc.py new = validate_name(doctype, new, merge=merge) return new