fix: Use cast in favour of cast_fieldtype
Use newly introduced casting util for Python-Frappe types mapping
This commit is contained in:
parent
a2cb9be7a4
commit
ed6533f737
3 changed files with 10 additions and 27 deletions
|
|
@ -14,7 +14,7 @@ import frappe.model.meta
|
|||
|
||||
from frappe import _
|
||||
from time import time
|
||||
from frappe.utils import now, getdate, cast_fieldtype, get_datetime, get_table_name
|
||||
from frappe.utils import now, getdate, cast, get_datetime, get_table_name
|
||||
from frappe.model.utils.link_count import flush_local_link_count
|
||||
|
||||
|
||||
|
|
@ -516,7 +516,6 @@ class Database(object):
|
|||
FROM `tabSingles`
|
||||
WHERE doctype = %s
|
||||
""", doctype)
|
||||
# result = _cast_result(doctype, result)
|
||||
|
||||
dict_ = frappe._dict(result)
|
||||
|
||||
|
|
@ -557,7 +556,7 @@ class Database(object):
|
|||
if not df:
|
||||
frappe.throw(_('Invalid field name: {0}').format(frappe.bold(fieldname)), self.InvalidColumnName)
|
||||
|
||||
val = cast_fieldtype(df.fieldtype, val)
|
||||
val = cast(df.fieldtype, val)
|
||||
|
||||
self.value_cache[doctype][fieldname] = val
|
||||
|
||||
|
|
@ -1052,19 +1051,3 @@ def enqueue_jobs_after_commit():
|
|||
q.enqueue_call(execute_job, timeout=job.get("timeout"),
|
||||
kwargs=job.get("queue_args"))
|
||||
frappe.flags.enqueue_after_commit = []
|
||||
|
||||
# Helpers
|
||||
def _cast_result(doctype, result):
|
||||
batch = [ ]
|
||||
|
||||
try:
|
||||
for field, value in result:
|
||||
df = frappe.get_meta(doctype).get_field(field)
|
||||
if df:
|
||||
value = cast_fieldtype(df.fieldtype, value)
|
||||
|
||||
batch.append(tuple([field, value]))
|
||||
except frappe.exceptions.DoesNotExistError:
|
||||
return result
|
||||
|
||||
return tuple(batch)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from frappe.model.utils.link_count import notify_link_count
|
|||
from frappe.modules import load_doctype_module
|
||||
from frappe.model import display_fieldtypes
|
||||
from frappe.utils import (cint, flt, now, cstr, strip_html,
|
||||
sanitize_html, sanitize_email, cast_fieldtype)
|
||||
sanitize_html, sanitize_email, cast)
|
||||
from frappe.utils.html_utils import unescape_html
|
||||
|
||||
max_positive_value = {
|
||||
|
|
@ -969,7 +969,7 @@ class BaseDocument(object):
|
|||
return self.cast(val, df)
|
||||
|
||||
def cast(self, value, df):
|
||||
return cast_fieldtype(df.fieldtype, value)
|
||||
return cast(df.fieldtype, value)
|
||||
|
||||
def _extract_images_from_text_editor(self):
|
||||
from frappe.core.doctype.file.file import extract_images_from_doc
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ Example:
|
|||
'''
|
||||
from datetime import datetime
|
||||
import frappe, json, os
|
||||
from frappe.utils import cstr, cint, cast_fieldtype
|
||||
from frappe.utils import cstr, cint, cast
|
||||
from frappe.model import default_fields, no_value_fields, optional_fields, data_fieldtypes, table_fields
|
||||
from frappe.model.document import Document
|
||||
from frappe.model.base_document import BaseDocument
|
||||
|
|
@ -322,24 +322,24 @@ class Meta(Document):
|
|||
|
||||
for ps in property_setters:
|
||||
if ps.doctype_or_field=='DocType':
|
||||
self.set(ps.property, cast_fieldtype(ps.property_type, ps.value))
|
||||
self.set(ps.property, cast(ps.property_type, ps.value))
|
||||
|
||||
elif ps.doctype_or_field=='DocField':
|
||||
for d in self.fields:
|
||||
if d.fieldname == ps.field_name:
|
||||
d.set(ps.property, cast_fieldtype(ps.property_type, ps.value))
|
||||
d.set(ps.property, cast(ps.property_type, ps.value))
|
||||
break
|
||||
|
||||
elif ps.doctype_or_field=='DocType Link':
|
||||
for d in self.links:
|
||||
if d.name == ps.row_name:
|
||||
d.set(ps.property, cast_fieldtype(ps.property_type, ps.value))
|
||||
d.set(ps.property, cast(ps.property_type, ps.value))
|
||||
break
|
||||
|
||||
elif ps.doctype_or_field=='DocType Action':
|
||||
for d in self.actions:
|
||||
if d.name == ps.row_name:
|
||||
d.set(ps.property, cast_fieldtype(ps.property_type, ps.value))
|
||||
d.set(ps.property, cast(ps.property_type, ps.value))
|
||||
break
|
||||
|
||||
def add_custom_links_and_actions(self):
|
||||
|
|
@ -532,7 +532,7 @@ class Meta(Document):
|
|||
label = link.group,
|
||||
items = [link.parent_doctype or link.link_doctype]
|
||||
))
|
||||
|
||||
|
||||
if not link.is_child_table:
|
||||
if link.link_fieldname != data.fieldname:
|
||||
if data.fieldname:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue