Parcourir la source

fix: has_content check for fieldtype TextEditor

When a TextEditor field contains only an image, while checking for
content, HTML tags are stripped off including the only image.
This change adds a loose but explicit check for img tag.

(cherry picked from commit d11692c52f)
version-14
Faris Ansari il y a 2 ans
committed by Mergify
Parent
révision
bd69c67f42
1 fichiers modifiés avec 10 ajouts et 1 suppressions
  1. +10
    -1
      frappe/model/base_document.py

+ 10
- 1
frappe/model/base_document.py Voir le fichier

@@ -671,10 +671,19 @@ class BaseDocument:

return _("Error: Value missing for {0}: {1}").format(_(df.parent), _(df.label))

def has_content(df):
value = cstr(self.get(df.fieldname))
has_text_content = strip_html(value).strip()
has_img_tag = "<img" in value
if df.fieldtype == "Text Editor" and (has_text_content or has_img_tag):
return True
else:
return has_text_content

missing = []

for df in self.meta.get("fields", {"reqd": ("=", 1)}):
if self.get(df.fieldname) in (None, []) or not strip_html(cstr(self.get(df.fieldname))).strip():
if self.get(df.fieldname) in (None, []) or not has_content(df):
missing.append((df.fieldname, get_msg(df)))

# check for missing parent and parenttype


Chargement…
Annuler
Enregistrer