瀏覽代碼

[minor] validate web form and upload in customize form

version-14
Rushabh Mehta 8 年之前
父節點
當前提交
b79dfe9970
共有 4 個文件被更改,包括 30 次插入6 次删除
  1. +3
    -0
      frappe/custom/doctype/customize_form/customize_form.js
  2. +8
    -6
      frappe/custom/doctype/customize_form/customize_form.py
  3. +5
    -0
      frappe/public/js/frappe/form/grid.js
  4. +14
    -0
      frappe/website/doctype/web_form/web_form.py

+ 3
- 0
frappe/custom/doctype/customize_form/customize_form.js 查看文件

@@ -4,6 +4,9 @@
frappe.provide("frappe.customize_form"); frappe.provide("frappe.customize_form");


frappe.ui.form.on("Customize Form", { frappe.ui.form.on("Customize Form", {
setup: function(frm) {
frm.get_docfield("fields").allow_bulk_edit = 1;
},
onload: function(frm) { onload: function(frm) {
frappe.customize_form.add_fields_help(frm); frappe.customize_form.add_fields_help(frm);




+ 8
- 6
frappe/custom/doctype/customize_form/customize_form.py 查看文件

@@ -195,10 +195,11 @@ class CustomizeForm(Document):


def update_custom_fields(self): def update_custom_fields(self):
for i, df in enumerate(self.get("fields")): for i, df in enumerate(self.get("fields")):
if df.get("__islocal"):
self.add_custom_field(df, i)
else:
self.update_in_custom_field(df, i)
if df.get("is_custom_field"):
if not frappe.db.exists('Custom Field', {'dt': self.doc_type, 'fieldname': df.fieldname}):
self.add_custom_field(df, i)
else:
self.update_in_custom_field(df, i)


self.delete_custom_fields() self.delete_custom_fields()


@@ -209,8 +210,8 @@ class CustomizeForm(Document):


for property in docfield_properties: for property in docfield_properties:
d.set(property, df.get(property)) d.set(property, df.get(property))
if i!=0:
if i!=0:
d.insert_after = self.fields[i-1].fieldname d.insert_after = self.fields[i-1].fieldname
d.idx = i d.idx = i


@@ -221,6 +222,7 @@ class CustomizeForm(Document):
meta = frappe.get_meta(self.doc_type) meta = frappe.get_meta(self.doc_type)
meta_df = meta.get("fields", {"fieldname": df.fieldname}) meta_df = meta.get("fields", {"fieldname": df.fieldname})
if not (meta_df and meta_df[0].get("is_custom_field")): if not (meta_df and meta_df[0].get("is_custom_field")):
# not a custom field
return return


custom_field = frappe.get_doc("Custom Field", meta_df[0].name) custom_field = frappe.get_doc("Custom Field", meta_df[0].name)


+ 5
- 0
frappe/public/js/frappe/form/grid.js 查看文件

@@ -460,6 +460,11 @@ frappe.ui.form.Grid = Class.extend({
if(df.fieldtype==="Date" && value) { if(df.fieldtype==="Date" && value) {
value = frappe.datetime.user_to_str(value); value = frappe.datetime.user_to_str(value);
} }

if(df.fieldtype==="Int" || df.fieldtype==="Check") {
value = cint(value);
}

d[fieldnames[ci]] = value; d[fieldnames[ci]] = value;
}); });
} }


+ 14
- 0
frappe/website/doctype/web_form/web_form.py 查看文件

@@ -36,6 +36,20 @@ class WebForm(WebsiteGenerator):
and self.is_standard and not frappe.conf.developer_mode): and self.is_standard and not frappe.conf.developer_mode):
frappe.throw(_("You need to be in developer mode to edit a Standard Web Form")) frappe.throw(_("You need to be in developer mode to edit a Standard Web Form"))


self.validate_fields()

def validate_fields(self):
'''Validate all fields are present'''
from frappe.model import no_value_fields
missing = []
meta = frappe.get_meta(self.doc_type)
for df in self.web_form_fields:
if df.fieldname and (df.fieldtype not in no_value_fields and not meta.has_field(df.fieldname)):
missing.append(df.fieldname)

if missing:
frappe.throw(_('Following fields are missing:') + '<br>' + '<br>'.join(missing))

def reset_field_parent(self): def reset_field_parent(self):
'''Convert link fields to select with names as options''' '''Convert link fields to select with names as options'''
for df in self.web_form_fields: for df in self.web_form_fields:


Loading…
取消
儲存