From 4ae43539c9cccaaf324932abc611f5d871628521 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Wed, 11 Jun 2014 14:19:25 +0530 Subject: [PATCH 1/5] autoname is hookable --- frappe/model/document.py | 3 ++- frappe/model/naming.py | 12 +++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/frappe/model/document.py b/frappe/model/document.py index 66e1bd1bf0..c8db03992f 100644 --- a/frappe/model/document.py +++ b/frappe/model/document.py @@ -369,9 +369,10 @@ class Document(BaseDocument): def run_method(self, method, *args, **kwargs): """run standard triggers, plus those in frappe""" - if hasattr(self, method): + if hasattr(self, method) and hasattr(getattr(self, method), "__call__"): fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs) else: + # hack! to run hooks even if method does not exist fn = lambda self, *args, **kwargs: None fn.__name__ = method.encode("utf-8") diff --git a/frappe/model/naming.py b/frappe/model/naming.py index 48b551f209..e9ea157bd0 100644 --- a/frappe/model/naming.py +++ b/frappe/model/naming.py @@ -13,13 +13,11 @@ def set_new_name(doc): # amendments if getattr(doc, "amended_from", None): return _get_amended_name(doc) - else: - tmp = getattr(doc, "autoname", None) - if tmp and not isinstance(tmp, basestring): - # autoname in a function, not a property - doc.autoname() - if doc.name: - return + + elif hasattr(doc, "run_method"): + doc.run_method("autoname") + if doc.name: + return autoname = frappe.get_meta(doc.doctype).autoname From 9d6450d69b3a8c950f7a64b9549c8abf688dcbe3 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 12 Jun 2014 11:44:05 +0530 Subject: [PATCH 2/5] Patch: change default fields like name, owner, etc to varchar(255) --- frappe/model/db_schema.py | 4 ++-- frappe/patches.txt | 1 + frappe/patches/v4_0/change_varchar_length.py | 23 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 frappe/patches/v4_0/change_varchar_length.py diff --git a/frappe/model/db_schema.py b/frappe/model/db_schema.py index b6078e5b1c..488f623cea 100644 --- a/frappe/model/db_schema.py +++ b/frappe/model/db_schema.py @@ -77,8 +77,8 @@ class DbTable: name varchar(255) not null primary key, creation datetime(6), modified datetime(6), - modified_by varchar(40), - owner varchar(60), + modified_by varchar(255), + owner varchar(255), docstatus int(1) default '0', parent varchar(255), parentfield varchar(255), diff --git a/frappe/patches.txt b/frappe/patches.txt index 37baaaf15b..76e8367c8f 100644 --- a/frappe/patches.txt +++ b/frappe/patches.txt @@ -9,6 +9,7 @@ execute:frappe.reload_doc('core', 'doctype', 'report') #2014-06-03 execute:frappe.reload_doc('core', 'doctype', 'version') #2014-02-21 execute:frappe.db.sql("alter table `tabSessions` modify `user` varchar(255), engine=InnoDB") execute:frappe.db.sql("delete from `tabDocField` where parent='0'") +frappe.patches.v4_0.change_varchar_length frappe.patches.v4_0.webnotes_to_frappe execute:frappe.reset_perms("Module Def") diff --git a/frappe/patches/v4_0/change_varchar_length.py b/frappe/patches/v4_0/change_varchar_length.py new file mode 100644 index 0000000000..f822bced5a --- /dev/null +++ b/frappe/patches/v4_0/change_varchar_length.py @@ -0,0 +1,23 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# MIT License. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + for dt in frappe.db.sql_list("""select name from `tabDocType` where ifnull(issingle, 0)=0"""): + desc = dict((d["Field"], d) for d in frappe.db.sql("desc `tab{}`".format(dt), as_dict=True)) + alter_table = [] + + if desc["name"]["Type"] != "varchar(255)": + alter_table.append("change `name` `name` varchar(255) not null primary key") + + for fieldname in ("modified_by", "owner", "parent", "parentfield", "parenttype"): + if desc[fieldname]["Type"] != "varchar(255)": + alter_table.append("change `{fieldname}` `{fieldname}` varchar(255)".format(fieldname=fieldname)) + + if alter_table: + alter_table_query = "alter table `tab{doctype}` {alter_table}".format(doctype=dt, alter_table=",\n".join(alter_table)) + # print alter_table_query + frappe.db.sql_ddl(alter_table_query) + From 065876468ad7c82073bc926a75815c9305ca505d Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 12 Jun 2014 12:33:25 +0530 Subject: [PATCH 3/5] Fixed load js via hook = doctype_js --- frappe/widgets/form/meta.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/frappe/widgets/form/meta.py b/frappe/widgets/form/meta.py index 0a63444db7..f36404a5b2 100644 --- a/frappe/widgets/form/meta.py +++ b/frappe/widgets/form/meta.py @@ -5,7 +5,6 @@ from __future__ import unicode_literals import frappe, os -from frappe.utils import cstr, cint from frappe.model.meta import Meta from frappe.modules import scrub, get_module_path from frappe.model.workflow import get_workflow_name @@ -60,8 +59,8 @@ class FormMeta(Meta): self._add_code(_get_path(self.name + '_calendar.js'), '__calendar_js') self._add_code(_get_path(self.name + '_map.js'), '__map_js') - self.add_custom_script() self.add_code_via_hook("doctype_js", "__js") + self.add_custom_script() def _add_code(self, path, fieldname): js = frappe.read_file(path) @@ -69,9 +68,16 @@ class FormMeta(Meta): self.set(fieldname, (self.get(fieldname) or "") + "\n\n" + render_jinja(js)) def add_code_via_hook(self, hook, fieldname): - hook = "{}:{}".format(hook, self.name) for app_name in frappe.get_installed_apps(): - for file in frappe.get_hooks(hook, app_name=app_name): + code_hook = frappe.get_hooks(hook, default={}, app_name=app_name) + if not code_hook: + continue + + files = code_hook.get(self.name, []) + if not isinstance(files, list): + files = [files] + + for file in files: path = frappe.get_app_path(app_name, *file.strip("/").split("/")) self._add_code(path, fieldname) From 5c03f1c9074c72f79c6428894e6b572f676f1439 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 12 Jun 2014 12:33:46 +0530 Subject: [PATCH 4/5] Clear primary actions if not dirty --- frappe/public/js/frappe/form/toolbar.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frappe/public/js/frappe/form/toolbar.js b/frappe/public/js/frappe/form/toolbar.js index e969871c07..b0a2acfbd3 100644 --- a/frappe/public/js/frappe/form/toolbar.js +++ b/frappe/public/js/frappe/form/toolbar.js @@ -207,12 +207,12 @@ frappe.ui.form.Toolbar = Class.extend({ } this.frm.linked_with.show(); }, - set_title_right: function() { + set_title_right: function(dirty) { var me = this, current = this.appframe.get_title_right_text(), status = null; - if (!this.frm.doc.__unsaved) { + if (!dirty) { // don't clear actions menu if dirty this.appframe.clear_primary_action(); } @@ -290,7 +290,7 @@ frappe.ui.form.Toolbar = Class.extend({ .toggleClass("text-warning", this.frm.doc.__unsaved ? true : false) this.set_title(); - this.set_title_right(); + this.set_title_right(true); // set state in wrapper $(this.frm.wrapper).attr("data-state", this.frm.doc.__unsaved ? "dirty" : "clean"); From 430d5b0829d30f6d10fc7ece50badc1db7ae649b Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 12 Jun 2014 12:55:35 +0530 Subject: [PATCH 5/5] Fixed add_options of dom.js --- frappe/core/doctype/custom_field/custom_field.py | 2 +- frappe/public/js/frappe/dom.js | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/frappe/core/doctype/custom_field/custom_field.py b/frappe/core/doctype/custom_field/custom_field.py index 9188e07b93..0180b996cf 100644 --- a/frappe/core/doctype/custom_field/custom_field.py +++ b/frappe/core/doctype/custom_field/custom_field.py @@ -78,7 +78,7 @@ class CustomField(Document): @frappe.whitelist() def get_fields_label(doctype=None): - return [{"value": df.fieldname, "label": _(df.label)} for df in frappe.get_meta(doctype).get("fields")] + return [{"value": df.fieldname or "", "label": _(df.label or "")} for df in frappe.get_meta(doctype).get("fields")] def create_custom_field_if_values_exist(doctype, df): df = frappe._dict(df) diff --git a/frappe/public/js/frappe/dom.js b/frappe/public/js/frappe/dom.js index 1fec30516c..cac0bc1193 100644 --- a/frappe/public/js/frappe/dom.js +++ b/frappe/public/js/frappe/dom.js @@ -247,8 +247,16 @@ frappe.dom.set_box_shadow = function(ele, spread) { var value = null; var label = null; } else { - var value = is_null(v.value) ? v : v.value; - var label = is_null(v.label) ? __(v) : __(v.label); + var is_value_null = is_null(v.value); + var is_label_null = is_null(v.label); + + if (is_value_null && is_label_null) { + var value = v; + var label = __(v); + } else { + var value = is_value_null ? "" : v.value; + var label = is_label_null ? __(value) : __(v.label); + } } $('