dmClasses.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:CRDataManager 作者: NobahdiAtoll 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号