Skip to content

Commit

Permalink
refactor!: remove compare util from frappe package (#19234)
Browse files Browse the repository at this point in the history
Use `from frappe.utils import compare` instead of `frappe.compare`.
  • Loading branch information
barredterra committed Dec 11, 2022
1 parent ed72e93 commit bb5b0e5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 25 deletions.
21 changes: 0 additions & 21 deletions frappe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1724,27 +1724,6 @@ def remove_no_copy_fields(d):
return newdoc


def compare(val1, condition, val2):
"""Compare two values using `frappe.utils.compare`
`condition` could be:
- "^"
- "in"
- "not in"
- "="
- "!="
- ">"
- "<"
- ">="
- "<="
- "not None"
- "None"
"""
import frappe.utils

return frappe.utils.compare(val1, condition, val2)


def respond_as_web_page(
title,
html,
Expand Down
4 changes: 2 additions & 2 deletions frappe/model/base_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from frappe.model.naming import set_new_name
from frappe.model.utils.link_count import notify_link_count
from frappe.modules import load_doctype_module
from frappe.utils import cast_fieldtype, cint, cstr, flt, now, sanitize_html, strip_html
from frappe.utils import cast_fieldtype, cint, compare, cstr, flt, now, sanitize_html, strip_html
from frappe.utils.html_utils import unescape_html

max_positive_value = {"smallint": 2**15 - 1, "int": 2**31 - 1, "bigint": 2**63 - 1}
Expand Down Expand Up @@ -1227,7 +1227,7 @@ def _filter(data, filters, limit=None):

for d in data:
for f, fval in _filters.items():
if not frappe.compare(getattr(d, f, None), fval[0], fval[1]):
if not compare(getattr(d, f, None), fval[0], fval[1]):
break
else:
out.append(d)
Expand Down
4 changes: 2 additions & 2 deletions frappe/model/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from frappe.model.naming import set_new_name, validate_name
from frappe.model.utils import is_virtual_doctype
from frappe.model.workflow import set_workflow_state_on_action, validate_workflow
from frappe.utils import cstr, date_diff, file_lock, flt, get_datetime_str, now
from frappe.utils import compare, cstr, date_diff, file_lock, flt, get_datetime_str, now
from frappe.utils.data import get_absolute_url
from frappe.utils.global_search import update_global_search

Expand Down Expand Up @@ -1300,7 +1300,7 @@ def validate_value(self, fieldname, condition, val2, doc=None, raise_exception=N
df = doc.meta.get_field(fieldname)
val2 = doc.cast(val2, df)

if not frappe.compare(val1, condition, val2):
if not compare(val1, condition, val2):
label = doc.meta.get_label(fieldname)
condition_str = error_condition_map.get(condition, condition)
if doc.get("parentfield"):
Expand Down

0 comments on commit bb5b0e5

Please sign in to comment.