def show_unique_validation_message(self, e): type, value, traceback = sys.exc_info() fieldname, label = str(e).split("'")[-2], None # unique_first_fieldname_second_fieldname is the constraint name # created using frappe.db.add_unique if "unique_" in fieldname: fieldname = fieldname.split("_", 1)[1] df = self.meta.get_field(fieldname) if df: label = df.label frappe.msgprint(_("{0} must be unique".format(label or fieldname))) # this is used to preserve traceback raise frappe.UniqueValidationError(self.doctype, self.name, e)
def show_unique_validation_message(self, e): if frappe.db.db_type != 'postgres': fieldname = str(e).split("'")[-2] label = None # MariaDB gives key_name in error. Extracting fieldname from key name try: fieldname = self.get_field_name_by_key_name(fieldname) except IndexError: pass label = self.get_label_from_fieldname(fieldname) frappe.msgprint(_("{0} must be unique").format(label or fieldname)) # this is used to preserve traceback raise frappe.UniqueValidationError(self.doctype, self.name, e)
def show_unique_validation_message(self, e): # TODO: Find a better way to extract fieldname if frappe.db.db_type != 'postgres': fieldname = str(e).split("'")[-2] label = None # unique_first_fieldname_second_fieldname is the constraint name # created using frappe.db.add_unique if "unique_" in fieldname: fieldname = fieldname.split("_", 1)[1] df = self.meta.get_field(fieldname) if df: label = df.label frappe.msgprint(_("{0} must be unique".format(label or fieldname))) # this is used to preserve traceback raise frappe.UniqueValidationError(self.doctype, self.name, e)