ソースを参照

[hotfix] don't allow no value fields in the search fields

version-14
mbauskar 8年前
コミット
5c8bd63a7c
2個のファイルの変更28行の追加4行の削除
  1. +10
    -4
      frappe/core/doctype/doctype/doctype.py
  2. +18
    -0
      frappe/core/doctype/doctype/test_doctype.py

+ 10
- 4
frappe/core/doctype/doctype/doctype.py ファイルの表示

@@ -512,14 +512,20 @@ def validate_fields(meta):
else: else:
frappe.throw(_("Fold can not be at the end of the form")) frappe.throw(_("Fold can not be at the end of the form"))


def check_search_fields(meta):
def check_search_fields(meta, fields):
"""Throw exception if `search_fields` don't contain valid fields.""" """Throw exception if `search_fields` don't contain valid fields."""
if not meta.search_fields: if not meta.search_fields:
return return


for fieldname in (meta.search_fields or "").split(","):
# No value fields should not be included in search field
search_fields = [field.strip() for field in (meta.search_fields or "").split(",")]
fieldtype_mapper = { field.fieldname: field.fieldtype \
for field in filter(lambda field: field.fieldname in search_fields, fields) }

for fieldname in search_fields:
fieldname = fieldname.strip() fieldname = fieldname.strip()
if fieldname not in fieldname_list:
if (fieldtype_mapper.get(fieldname) in no_value_fields) or \
(fieldname not in fieldname_list):
frappe.throw(_("Search field {0} is not valid").format(fieldname)) frappe.throw(_("Search field {0} is not valid").format(fieldname))


def check_title_field(meta): def check_title_field(meta):
@@ -616,7 +622,7 @@ def validate_fields(meta):
check_unique_and_text(d) check_unique_and_text(d)


check_fold(fields) check_fold(fields)
check_search_fields(meta)
check_search_fields(meta, fields)
check_title_field(meta) check_title_field(meta)
check_timeline_field(meta) check_timeline_field(meta)
check_is_published_field(meta) check_is_published_field(meta)


+ 18
- 0
frappe/core/doctype/doctype/test_doctype.py ファイルの表示

@@ -54,3 +54,21 @@ class TestDocType(unittest.TestCase):
doc2.insert() doc2.insert()
doc1.delete() doc1.delete()
doc2.delete() doc2.delete()

def test_validate_search_fields(self):
doc = self.new_doctype("Test Search Fields")
doc.search_fields = "some_fieldname"
doc.insert()
self.assertEqual(doc.name, "Test Search Fields")

# check if invalid fieldname is allowed or not
doc.search_fields = "some_fieldname_1"
self.assertRaises(frappe.ValidationError, doc.save)

# check if no value fields are allowed in search fields
field = doc.append("fields", {})
field.fieldname = "some_html_field"
field.fieldtype = "HTML"
field.label = "Some HTML Field"
doc.search_fields = "some_fieldname,some_html_field"
self.assertRaises(frappe.ValidationError, doc.save)

読み込み中…
キャンセル
保存