def execute(): tables = frappe.db.sql_list("show tables") if "tabUser" not in tables: frappe.rename_doc("DocType", "Profile", "User", force=True) if frappe.db.exists("DocType", "Website Route Permission"): frappe.reload_doc("website", "doctype", "website_route_permission") if "profile" in get_table_columns("Website Route Permission"): rename_field("Website Route Permission", "profile", "user") frappe.reload_doc("website", "doctype", "blogger") if "profile" in get_table_columns("Blogger"): rename_field("Blogger", "profile", "user")
def set_optional_columns(self): """Removes optional columns like `_user_tags`, `_comments` etc. if not in table""" columns = get_table_columns(self.doctype) # remove from fields to_remove = [] for fld in self.fields: for f in optional_fields: if f in fld and not f in columns: to_remove.append(fld) for fld in to_remove: del self.fields[self.fields.index(fld)] # remove from filters to_remove = [] for each in self.filters: if isinstance(each, string_types): each = [each] for element in each: if element in optional_fields and element not in columns: to_remove.append(each) for each in to_remove: if isinstance(self.filters, dict): del self.filters[each] else: self.filters.remove(each)
def get_table_columns(self): try: return get_table_columns(self.doctype) except frappe.db.TableMissingError: if self.ignore_ddl: return None else: raise
def get_valid_columns(self): if self.doctype not in frappe.local.valid_columns: if self.doctype in ("DocField", "DocPerm") and self.parent in ("DocType", "DocField", "DocPerm"): from frappe.model.meta import get_table_columns valid = get_table_columns(self.doctype) else: valid = self.meta.get_valid_columns() frappe.local.valid_columns[self.doctype] = valid return frappe.local.valid_columns[self.doctype]
def get_valid_columns(self): if self.doctype not in frappe.local.valid_columns: if self.doctype in DOCTYPES_FOR_DOCTYPE: from frappe.model.meta import get_table_columns valid = get_table_columns(self.doctype) else: valid = self.meta.get_valid_columns() frappe.local.valid_columns[self.doctype] = valid return frappe.local.valid_columns[self.doctype]
def init_valid_columns(self): for key in default_fields: if key not in self.__dict__: self.__dict__[key] = None if self.doctype in ("DocField", "DocPerm") and self.parent in ("DocType", "DocField", "DocPerm"): from frappe.model.meta import get_table_columns valid = get_table_columns(self.doctype) else: valid = self.meta.get_valid_columns() for key in valid: if key not in self.__dict__: self.__dict__[key] = None