Browse Source

Validate Select field values

Conflicts:
	frappe/model/base_document.py
	frappe/model/meta.py
version-14
Anand Doshi 11 years ago
parent
commit
53f04414cf
2 changed files with 6 additions and 4 deletions
  1. +4
    -3
      frappe/model/base_document.py
  2. +2
    -1
      frappe/model/meta.py

+ 4
- 3
frappe/model/base_document.py View File

@@ -292,16 +292,17 @@ class BaseDocument(object):
continue continue


# strip and set # strip and set
self.set(df.fieldname, self.get(df.fieldname).strip())
self.set(df.fieldname, cstr(self.get(df.fieldname)).strip())
value = self.get(df.fieldname)


if self.get(df.fieldname) not in options:
if value not in options and not (frappe.flags.in_test and value.startswith("_T-")):
# show an elaborate message # show an elaborate message
prefix = _("Row #{0}:").format(self.idx) if self.get("parentfield") else "" prefix = _("Row #{0}:").format(self.idx) if self.get("parentfield") else ""
label = _(self.meta.get_label(df.fieldname)) label = _(self.meta.get_label(df.fieldname))
comma_options = '", "'.join(_(each) for each in options) comma_options = '", "'.join(_(each) for each in options)


frappe.throw(_('{0} {1} cannot be "{2}". It should be one of "{3}"').format(prefix, label, frappe.throw(_('{0} {1} cannot be "{2}". It should be one of "{3}"').format(prefix, label,
self.get(df.fieldname), comma_options))
value, comma_options))


def _validate_constants(self): def _validate_constants(self):
if frappe.flags.in_import: if frappe.flags.in_import:


+ 2
- 1
frappe/model/meta.py View File

@@ -62,7 +62,8 @@ class Meta(Document):
return self.get("fields", {"fieldtype": "Link", "options":["!=", "[Select]"]}) return self.get("fields", {"fieldtype": "Link", "options":["!=", "[Select]"]})


def get_select_fields(self): def get_select_fields(self):
return self.get("fields", {"fieldtype": "Select", "options":["not in", ["[Select]", "Loading..."]]})
return self.get("fields", {"fieldtype": "Select", "options":["not in",
["[Select]", "Loading...", "attach_files:"]]})


def get_table_fields(self): def get_table_fields(self):
if not hasattr(self, "_table_fields"): if not hasattr(self, "_table_fields"):


Loading…
Cancel
Save