def SetFieldValue(self, book, newValue, strField=None):
"""Determines the proper write to book technique (Standard or Custom Field) and applies value"""
if dmGlobals.TraceFunctionMessages: print 'Method: dmAction:SetValue(book, objNewValue, stringFieldName)'
FieldValue = self.Field
if strField != None:
FieldValue = strField
previousVal = self.GetFieldValue(book, FieldValue)
newVal = newValue
strReport = ''
if FieldValue in dmGlobals.FIELDSLIST:
if dmGlobals.SortLists:
newVal.sort()
newVal = dmGlobals.CRLISTDELIMITER.join(newVal)
previousVal = dmGlobals.CRLISTDELIMITER.join(previousVal)
if FieldValue in dmGlobals.ALLOWEDVALS:
try:
if FieldValue in dmGlobals.FIELDSNUMERIC:
setattr(book, FieldValue, dmGlobals.StringToFloat(newVal)) #convert to float
else:
setattr(book, FieldValue, newVal.ToString())
#prepare the report
strReport = ' Field: ' + FieldValue + ' Action: ' + self.ToString()
strReport = strReport + System.Environment.NewLine + ' Previous Value: ' + dmGlobals.ToString(previousVal)
strReport = strReport + System.Environment.NewLine + ' New Value: ' + dmGlobals.ToString(newVal) + '\r\n'
except Exception as er:
#report errors instead
strReport = ' An unexpected error occured in Action: ' + self.ToString() + ' Parent Ruleset : ' + self.Parent.Name
if isinstance(er, dmConversionError):
strReport = strReport + ' Error' + er.msg
pass
else:
self.SetCustomField(book, FieldValue, newVal)
#prepare the report
if strReport != '': strReport = System.Environment.NewLine
strReport = ' CustomField: ' + self.Field + ' Action: ' + self.ToString()
strReport = strReport + System.Environment.NewLine + ' Previous Value: ' + dmGlobals.ToString(previousVal)
strReport = strReport + System.Environment.NewLine + ' New Value: ' + dmGlobals.ToString(newVal)
return strReport
评论列表
文章目录