Преглед на файлове

refactor report view to make it thread safe

version-14
Pratik Vyas преди 12 години
родител
ревизия
f8c32bbd11
променени са 1 файла, в които са добавени 15 реда и са изтрити 16 реда
  1. +15
    -16
      webnotes/widgets/reportview.py

+ 15
- 16
webnotes/widgets/reportview.py Целия файл

@@ -7,9 +7,9 @@ from __future__ import unicode_literals
import webnotes, json import webnotes, json
import webnotes.defaults import webnotes.defaults


tables = None
doctypes = {}
roles = []
tables = webnotes.local('reportview_tables')
doctypes = webnotes.local('reportview_doctypes')
roles = webnotes.local('reportview_roles')


@webnotes.whitelist() @webnotes.whitelist()
def get(): def get():
@@ -48,8 +48,7 @@ def execute(doctype, query=None, filters=None, fields=None, docstatus=None,
return webnotes.conn.sql(query, as_dict=not as_list, debug=debug) return webnotes.conn.sql(query, as_dict=not as_list, debug=debug)
def prepare_args(doctype, filters, fields, docstatus, group_by, order_by, with_childnames): def prepare_args(doctype, filters, fields, docstatus, group_by, order_by, with_childnames):
global tables
tables = get_tables(doctype, fields)
webnotes.local.reportview_tables = get_tables(doctype, fields)
load_doctypes() load_doctypes()
remove_user_tags(doctype, fields) remove_user_tags(doctype, fields)
conditions = build_conditions(doctype, fields, filters, docstatus) conditions = build_conditions(doctype, fields, filters, docstatus)
@@ -107,11 +106,13 @@ def run_custom_query(query):


def load_doctypes(): def load_doctypes():
"""load all doctypes and roles""" """load all doctypes and roles"""
global doctypes, roles
import webnotes.model.doctype import webnotes.model.doctype


roles = webnotes.get_roles()
webnotes.local.reportview_roles = webnotes.get_roles()
if not doctypes:
webnotes.local.reportview_doctypes = {}

for t in tables: for t in tables:
if t.startswith('`'): if t.startswith('`'):
doctype = t[4:-1] doctype = t[4:-1]
@@ -158,8 +159,8 @@ def build_conditions(doctype, fields, filters, docstatus):
def build_filter_conditions(filters, conditions): def build_filter_conditions(filters, conditions):
"""build conditions from user filters""" """build conditions from user filters"""
from webnotes.utils import cstr from webnotes.utils import cstr
global tables
if not tables: tables = []
if not tables:
webnotes.local.reportview_tables = []
for f in filters: for f in filters:
if isinstance(f, basestring): if isinstance(f, basestring):
@@ -184,18 +185,17 @@ def build_filter_conditions(filters, conditions):
def build_match_conditions(doctype, fields=None, as_condition=True): def build_match_conditions(doctype, fields=None, as_condition=True):
"""add match conditions if applicable""" """add match conditions if applicable"""
global tables, roles
match_filters = {} match_filters = {}
match_conditions = [] match_conditions = []
match = True match = True
if not tables or not doctypes: if not tables or not doctypes:
tables = get_tables(doctype, fields)
webnotes.local.reportview_tables = get_tables(doctype, fields)
load_doctypes() load_doctypes()


if not roles: if not roles:
roles = webnotes.get_roles()
webnotes.local.reportview_roles = webnotes.get_roles()


for d in doctypes[doctype]: for d in doctypes[doctype]:
if d.doctype == 'DocPerm' and d.parent == doctype: if d.doctype == 'DocPerm' and d.parent == doctype:
@@ -309,8 +309,7 @@ def export_query():


def verify_export_allowed(): def verify_export_allowed():
"""throw exception if user is not allowed to export""" """throw exception if user is not allowed to export"""
global roles
roles = webnotes.get_roles()
webnotes.local.reportview_roles = webnotes.get_roles()
if not ('Administrator' in roles or 'System Manager' in roles or 'Report Manager' in roles): if not ('Administrator' in roles or 'System Manager' in roles or 'Report Manager' in roles):
raise webnotes.PermissionError raise webnotes.PermissionError


@@ -395,4 +394,4 @@ def get_match_cond(doctype, searchfield = 'name'):
cond = ' and ' + cond cond = ' and ' + cond
else: else:
cond = '' cond = ''
return cond
return cond

Зареждане…
Отказ
Запис