Skip to content

Commit

Permalink
refactoring of zmssqldb (#32)
Browse files Browse the repository at this point in the history
Co-authored-by: zmsdev <zmsdev@sntl-publishing.com>
  • Loading branch information
zmsdev and zmsdev authored Nov 30, 2021
1 parent 048e10d commit a015d59
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
20 changes: 20 additions & 0 deletions Products/zms/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,24 @@ def strip_int(s):
#
############################################################################

security.declarePublic('operator_contains')
def operator_contains(c, v, ignorecase=False):
"""
Check if collection contains value.
@param c: Collection
@type c: C{list|set|tuple}
@param v: Value
@type v: C{any}
@param ignorecase: Ignore Case-Sensitivity
@type ignorecase: C{Bool}
@return: Collection contains value
@rtype: C{Bool}
"""
if ignorecase:
return v.lower() in [x.lower() for x in c]
else:
return v in c

security.declarePublic('operator_gettype')
def operator_gettype(v):
"""
Expand Down Expand Up @@ -1375,6 +1393,8 @@ def operator_getitem(a, b, c=None, ignorecase=True):
@type b: C{any}
@param c: Default-Value
@type c: C{any}
@param ignorecase: Ignore Case-Sensitivity
@type ignorecase: C{Bool}
@rtype: C{any}
"""
if ignorecase and ( isinstance(b, bytes) or isinstance(b, str) ):
Expand Down
12 changes: 5 additions & 7 deletions Products/zms/zmssqldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,7 @@ def record_encode__(self, cols, record, encoding='utf-8'):
for col in cols:
k = col['id']
v = record[k]
if self.getConfProperty('ZMSSqlDb.record_encode__.k.lower'):
k = k.lower()
if type(v) is bytes:
if isinstance(v, bytes):
v = str(v,encoding)
row[k] = v
return row
Expand Down Expand Up @@ -465,7 +463,7 @@ def handle_record(self, r):
context = self.parent
d = {}
if len(colNames)>0:
r = { k:r[k] for k in r.keys() if k.lower() in [c.lower() for c in colNames] }
r = { k: r[k] for k in r if standard.operator_contains(colNames,k,ignorecase=True) }
for k in r:
value = r[k]
try:
Expand Down Expand Up @@ -1048,7 +1046,6 @@ def getEntities(self):
#-- Defaults
for entity in entities:
for column in entity['columns']:
#column['id'] = column['id'].lower()
column['multilang'] = False
column['datatype'] = column.get('type', '?')
column['datatype_key'] = _globals.datatype_key(column['datatype'])
Expand Down Expand Up @@ -1280,8 +1277,9 @@ def recordSet_Sort(self, REQUEST):
if len(tabledefs) > 0:
tabledef = [x for x in tabledefs if x['id'].upper()==tablename.upper()][0]
tablecols = tabledef['columns']
colNames = [x['id'] for x in tablecols]
#-- ORDER BY
if qorder == '' or not qorder.lower() in [x['id'].lower() for x in tablecols]:
if qorder == '' or not standard.operator_contains(colNames,qorder,ignorecase=True):
for col in tablecols:
if col.get('hide', 0) != 1:
qorder = '%s.%s'%(tablename, col['id'])
Expand Down Expand Up @@ -1449,7 +1447,7 @@ def recordSet_Insert(self, tablename, values={}, update_intersections=False):
(not tablecol.get('details')) and \
(not tablecol.get('multiselect') or tablecol.get('multiselect').get('custom') or tablecol.get('multiselect').get('mysqlset')) and \
(not tablecol.get('multimultiselect')):
value = values.get(id, values.get(id.lower(), values.get(id.upper(), '')))
value = standard.operator_getitem(values, id, '', ignorecase=True)
if isinstance(value, list):
value = ','.join(value)
c.append({'id':id,'value':value})
Expand Down

0 comments on commit a015d59

Please sign in to comment.