Przeglądaj źródła

refactor(utils): Use qb & db APIs inplace of raw SQls

version-14
Gavin D'souza 3 lat temu
rodzic
commit
459c179916
3 zmienionych plików z 12 dodań i 8 usunięć
  1. +6
    -2
      frappe/utils/error.py
  2. +1
    -1
      frappe/utils/install.py
  3. +5
    -5
      frappe/utils/user.py

+ 6
- 2
frappe/utils/error.py Wyświetl plik

@@ -176,9 +176,13 @@ def collect_error_snapshots():

def clear_old_snapshots():
"""Clear snapshots that are older than a month"""
from frappe.query_builder import DocType, Interval
from frappe.query_builder.functions import Now

frappe.db.sql("""delete from `tabError Snapshot`
where creation < (NOW() - INTERVAL '1' MONTH)""")
ErrorSnapshot = DocType("Error Snapshot")
frappe.db.delete(ErrorSnapshot, filters=(
ErrorSnapshot.creation < (Now() - Interval(months=1))
))

path = get_error_snapshot_path()
today = datetime.datetime.now()


+ 1
- 1
frappe/utils/install.py Wyświetl plik

@@ -34,7 +34,7 @@ def after_install():
print_settings.save()

# all roles to admin
frappe.get_doc("User", "Administrator").add_roles(*frappe.db.sql_list("""select name from tabRole"""))
frappe.get_doc("User", "Administrator").add_roles(*frappe.get_all("Role", pluck="name"))

# update admin password
update_password("Administrator", get_admin_password())


+ 5
- 5
frappe/utils/user.py Wyświetl plik

@@ -64,14 +64,14 @@ class UserPermissions:

def build_doctype_map(self):
"""build map of special doctype properties"""
self.doctype_map = {}

active_domains = frappe.get_active_domains()
all_doctypes = frappe.get_all("DocType", fields=["name", "in_create", "module", "istable", "issingle", "read_only", "restrict_to_domain"])

self.doctype_map = {}
for r in frappe.db.sql("""select name, in_create, issingle, istable,
read_only, restrict_to_domain, module from tabDocType""", as_dict=1):
if (not r.restrict_to_domain) or (r.restrict_to_domain in active_domains):
self.doctype_map[r['name']] = r
for dt in all_doctypes:
if not dt.restrict_to_domain or (dt.restrict_to_domain in active_domains):
self.doctype_map[dt["name"]] = dt

def build_perm_map(self):
"""build map of permissions at level 0"""


Ładowanie…
Anuluj
Zapisz