Procházet zdrojové kódy

[notifications] added match permissions #552

version-14
Rushabh Mehta před 12 roky
rodič
revize
ce666c05be
3 změnil soubory, kde provedl 25 přidání a 22 odebrání
  1. +2
    -1
      webnotes/widgets/moduleview.py
  2. +5
    -3
      webnotes/widgets/notification.py
  3. +18
    -18
      webnotes/widgets/reportview.py

+ 2
- 1
webnotes/widgets/moduleview.py Zobrazit soubor

@@ -3,6 +3,7 @@


from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes, json import webnotes, json
from webnotes.widgets import reportview


@webnotes.whitelist() @webnotes.whitelist()
def get_data(module, doctypes='[]'): def get_data(module, doctypes='[]'):
@@ -20,7 +21,7 @@ def get_count(doctypes):


def get_doctype_count_from_table(doctype): def get_doctype_count_from_table(doctype):
try: try:
count = webnotes.conn.sql("""select count(*) from `tab%s`""" % doctype)[0][0]
count = reportview.execute(doctype, fields=["count(*)"], as_list=True)[0][0]
except Exception, e: except Exception, e:
if e.args[0]==1146: if e.args[0]==1146:
count = None count = None


+ 5
- 3
webnotes/widgets/notification.py Zobrazit soubor

@@ -3,6 +3,7 @@


from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes.widgets import reportview


@webnotes.whitelist() @webnotes.whitelist()
def get(): def get():
@@ -19,11 +20,12 @@ def get():
if d in can_read: if d in can_read:
condition = for_doctype[d] condition = for_doctype[d]
key = condition.keys()[0] key = condition.keys()[0]
query = "select count(*) from `tab%s` where `%s`=%s and docstatus<2" % (d, key, '%s')
result = webnotes.conn.sql(query, condition[key])[0][0]

result = reportview.execute(d, fields=["count(*)"],
filters=[[d, key, "=", condition[key]]], as_list=True)[0][0]
if result: if result:
open_count_doctype[d] = result open_count_doctype[d] = result
for m in for_module: for m in for_module:
open_count_module[m] = for_module[m]() open_count_module[m] = for_module[m]()




+ 18
- 18
webnotes/widgets/reportview.py Zobrazit soubor

@@ -174,22 +174,25 @@ def build_filter_conditions(filters, conditions):
from webnotes.utils import cstr from webnotes.utils import cstr
for f in filters: for f in filters:
tname = ('`tab' + f[0] + '`')
if not tname in tables:
tables.append(tname)
# prepare in condition
if f[2]=='in':
opts = ["'" + t.strip().replace("'", "\\'") + "'" for t in f[3].split(',')]
f[3] = "(" + ', '.join(opts) + ")"
conditions.append(tname + '.' + f[1] + " " + f[2] + " " + f[3])
if isinstance(f, basestring):
conditions.append(f)
else: else:
if isinstance(f[3], basestring):
f[3] = "'" + f[3].replace("'", "\\'") + "'"
tname = ('`tab' + f[0] + '`')
if not tname in tables:
tables.append(tname)
# prepare in condition
if f[2]=='in':
opts = ["'" + t.strip().replace("'", "\\'") + "'" for t in f[3].split(',')]
f[3] = "(" + ', '.join(opts) + ")"
conditions.append(tname + '.' + f[1] + " " + f[2] + " " + f[3]) conditions.append(tname + '.' + f[1] + " " + f[2] + " " + f[3])
else: else:
conditions.append('ifnull(' + tname + '.' + f[1] + ",0) " + f[2] \
+ " " + cstr(f[3]))
if isinstance(f[3], basestring):
f[3] = "'" + f[3].replace("'", "\\'") + "'"
conditions.append(tname + '.' + f[1] + " " + f[2] + " " + f[3])
else:
conditions.append('ifnull(' + tname + '.' + f[1] + ",0) " + f[2] \
+ " " + cstr(f[3]))
def build_match_conditions(doctype, fields=None): def build_match_conditions(doctype, fields=None):
"""add match conditions if applicable""" """add match conditions if applicable"""
@@ -235,7 +238,6 @@ def get_tables(doctype, fields):
table_name = f.split('.')[0] table_name = f.split('.')[0]
if table_name.lower().startswith('group_concat('): if table_name.lower().startswith('group_concat('):
table_name = table_name[13:] table_name = table_name[13:]
# check if ifnull function is used
if table_name.lower().startswith('ifnull('): if table_name.lower().startswith('ifnull('):
table_name = table_name[7:] table_name = table_name[7:]
if not table_name[0]=='`': if not table_name[0]=='`':
@@ -347,10 +349,8 @@ def get_stats(stats, doctype):
columns = get_table_columns(doctype) columns = get_table_columns(doctype)
for tag in tags: for tag in tags:
if not tag in columns: continue if not tag in columns: continue
tagcount = webnotes.conn.sql("""select %(tag)s, count(*)
from `tab%(doctype)s`
where ifnull(%(tag)s, '')!=''
group by %(tag)s;""" % locals(), as_list=1)
tagcount = execute(doctype, fields=[tag, "count(*)"],
filters=["ifnull(%s,'')!=''" % tag], group_by=tag, as_list=True)
if tag=='_user_tags': if tag=='_user_tags':
stats[tag] = scrub_user_tags(tagcount) stats[tag] = scrub_user_tags(tagcount)


Načítá se…
Zrušit
Uložit