Merge pull request #604 from anandpdoshi/wip-anand
Fixes add_options, clear primary actions, js files via hook, change to varchar 255, autoname hookable
This commit is contained in:
commit
d144a2b307
9 changed files with 57 additions and 20 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
23
frappe/patches/v4_0/change_varchar_length.py
Normal file
23
frappe/patches/v4_0/change_varchar_length.py
Normal file
|
|
@ -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)
|
||||
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
$('<option>').html(cstr(label)).attr('value', value).appendTo(this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue