From 2622f3398e61df302ab94a6ef839a1f55304e0d4 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 7 Oct 2021 17:21:13 +0530 Subject: [PATCH] style: Black-ish queries * feat(minor): Added DocType to frappe.query_builder namespace --- frappe/modules/import_file.py | 12 +++++++----- frappe/query_builder/__init__.py | 2 +- frappe/query_builder/utils.py | 3 +++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/frappe/modules/import_file.py b/frappe/modules/import_file.py index 00f298655f..230a59df6e 100644 --- a/frappe/modules/import_file.py +++ b/frappe/modules/import_file.py @@ -8,7 +8,7 @@ import frappe from frappe.model.base_document import get_controller from frappe.modules import get_module_path, scrub_dt_dn from frappe.utils import get_datetime_str - +from frappe.query_builder import DocType def caclulate_hash(path: str) -> str: """Calculate md5 hash of the file in binary mode @@ -106,7 +106,9 @@ def import_file_by_path(path, force=False, data_import=False, pre_process=None, # not using db.set_value to avoid making changes in tabSingles if doc["doctype"] == "DocType": doctype_table = frappe.qb.DocType("DocType") - frappe.qb.update(doctype_table).set(doctype_table.migration_hash, calculated_hash).where(doctype_table.name == doc["name"]).run() + frappe.qb.update(doctype_table).set( + doctype_table.migration_hash, calculated_hash + ).where(doctype_table.name == doc["name"]).run() if original_modified: update_modified(original_modified, doc) @@ -138,7 +140,7 @@ def read_doc_from_file(path): def update_modified(original_modified, doc): # since there is a new timestamp on the file, update timestamp in if doc["doctype"] == doc["name"] and doc["name"] != "DocType": - singles_table = frappe.qb.DocType("Singles") + singles_table = DocType("Singles") frappe.qb.update( singles_table @@ -150,8 +152,8 @@ def update_modified(original_modified, doc): singles_table.doctype == doc["name"] ).run() else: - doctype_table = frappe.qb.DocType(doc['doctype']) - + doctype_table = DocType(doc['doctype']) + frappe.qb.update(doctype_table ).set( doctype_table.modified, original_modified diff --git a/frappe/query_builder/__init__.py b/frappe/query_builder/__init__.py index 6987ba24ab..4a1fe8fb84 100644 --- a/frappe/query_builder/__init__.py +++ b/frappe/query_builder/__init__.py @@ -1,2 +1,2 @@ from pypika import * -from frappe.query_builder.utils import Column, get_query_builder, patch_query_execute +from frappe.query_builder.utils import Column, DocType, get_query_builder, patch_query_execute diff --git a/frappe/query_builder/utils.py b/frappe/query_builder/utils.py index abd700c396..386ddda751 100644 --- a/frappe/query_builder/utils.py +++ b/frappe/query_builder/utils.py @@ -44,6 +44,9 @@ def get_attr(method_string): methodname = method_string.split('.')[-1] return getattr(import_module(modulename), methodname) +def DocType(*args, **kwargs): + return frappe.qb.DocType(*args, **kwargs) + def patch_query_execute(): """Patch the Query Builder with helper execute method This excludes the use of `frappe.db.sql` method while