Переглянути джерело

[notifications] added match permissions #552

version-14
Rushabh Mehta 12 роки тому
джерело
коміт
ce666c05be
3 змінених файлів з 25 додано та 22 видалено
  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 Переглянути файл

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

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

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

def get_doctype_count_from_table(doctype):
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:
if e.args[0]==1146:
count = None


+ 5
- 3
webnotes/widgets/notification.py Переглянути файл

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

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

@webnotes.whitelist()
def get():
@@ -19,11 +20,12 @@ def get():
if d in can_read:
condition = for_doctype[d]
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:
open_count_doctype[d] = result
for m in for_module:
open_count_module[m] = for_module[m]()



+ 18
- 18
webnotes/widgets/reportview.py Переглянути файл

@@ -174,22 +174,25 @@ def build_filter_conditions(filters, conditions):
from webnotes.utils import cstr
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:
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])
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):
"""add match conditions if applicable"""
@@ -235,7 +238,6 @@ def get_tables(doctype, fields):
table_name = f.split('.')[0]
if table_name.lower().startswith('group_concat('):
table_name = table_name[13:]
# check if ifnull function is used
if table_name.lower().startswith('ifnull('):
table_name = table_name[7:]
if not table_name[0]=='`':
@@ -347,10 +349,8 @@ def get_stats(stats, doctype):
columns = get_table_columns(doctype)
for tag in tags:
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':
stats[tag] = scrub_user_tags(tagcount)


Завантаження…
Відмінити
Зберегти