⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 input.py

📁 一个工作流设计及定义的系统,可以直接与数据库结合进行系统工作流程的定义及应用.
💻 PY
📖 第 1 页 / 共 2 页
字号:
    def __hash__ (self):        return self.hashCode    def __cmp__ (self, other):        if other == None: return 1        return cmp(self.hashCode, other.hashCode)## FILE INPUT#class FileInput (Input, Attribute):    def __init__ (self):        Input.__init__(self)    def parseRequest (self, req, prefix):        upload = req.uploads[0]        result = ListAttribute()        result.add(StringAttribute(upload.fileName))        result.add(StringAttribute(upload.fullFileName))        result.add(StringAttribute(upload.contentType))        result.add(StringAttribute(upload.size))        return result    def displayInputTag (self, viewOnly, indentation, writer, value, prefix):        if viewOnly: return        writer.write(indent(indentation))        writer.write('<input type=file name="%s"' % prefix)        self.outputHtmlAttributes(writer)        writer.write('>')    def getEmptyValue (self):        return self## ATOMIC ATTRIBUTE INPUT#def _isMultiLine (stringValue):    if stringValue.find("\n") > -1: return 1    if stringValue.find("\r") > -1: return 1    return 0def _htmlize (multiLineString):    return _neutralize(multiLineString).replace('\n', '<br>')class AtomicAttributeInput (Input):    """        parsing/displaying AtomicAttribute instances.        the base.    """    def __init__ (self):        Input.__init__(self)        self.forClass = StringAttribute        self.params = { 'align': 'left' }    def parseRequest (self, req, prefix):        v = self.forClass(req.getParameter(prefix))        #v = InputHelper.getParameter(req.originalRequest, prefix)        log.debug("AtomicAttributeInput.parseRequest() '%s' -> '%s'" % (prefix, v))        return v    def getEmptyValue (self):        return self.forClass()        def displayInputTag (self, viewOnly, indentation, writer, attValue, prefix):        sValue = str(attValue)        if viewOnly:            sValue = _htmlize(sValue)            if sValue.find('://') > -1:                writer.write('<a target=_blank href="%s">' % sValue)                writer.write(sValue)                writer.write('</a>')            else:                writer.write(sValue)            return        writer.write(indent(indentation))        sValue = _neutralize(sValue)        if attValue and _isMultiLine(sValue):            writer.write('<textarea name="%s" rows=4 cols=49>' % prefix)            if attValue: writer.write(sValue)            writer.write('</textarea>')        else:            writer.write('<input type=text name="%s"' % prefix)            if attValue: writer.write(' value="%s"' % sValue)            self.outputHtmlAttributes(writer)            writer.write('>')            if sValue.find('://') > -1:                writer.write('<a target=_blank href="%s">' % sValue)                writer.write(IMG_LINK)                writer.write('</a>')class NumericInput (AtomicAttributeInput):    """        common behaviours for long/int/double input    """    def __init__ (self):        AtomicAttributeInput.__init__(self)        self.params = { 'align': 'right', 'size': '9' }class StringInput (AtomicAttributeInput):    """        parsing/displaying StringAttribute instances    """    def __init__ (self):        AtomicAttributeInput.__init__(self)        self.forClass = StringAttribute        self.params = { 'size': '50' }class IntegerInput (NumericInput):    """        parsing/displaying IntegerAttribute instances    """    def __init__ (self):        NumericInput.__init__(self)        self.forClass = IntegerAttributeclass LongInput (NumericInput):    """        parsing/displaying LongAttribute instances    """    def __init__ (self):        NumericInput.__init__(self)        self.forClass = LongAttributeclass DoubleInput (NumericInput):    """        parsing/displaying DoubleAttribute instances    """    def __init__ (self):        NumericInput.__init__(self)        self.forClass = DoubleAttributeclass BooleanInput (Input):    """        parsing/displaying BooleanAttribute instances    """    def parseRequest (self, req, prefix):        return BooleanAttribute('true' == req.getParameter(prefix))    def displayInputTag (self, viewOnly, indentation, writer, attValue, prefix):        if viewOnly:            writer.write(str(attValue))            return        sValue = str(attValue.getValue())        trueChecked = (sValue == 'true' or sValue == '1')        writer.write(indent(indentation))        writer.write('<input type=radio name="%s" value="true"' % prefix)        if trueChecked: writer.write(' checked')        writer.write('> true ')        writer.write('<input type=radio name="%s" value="false"' % prefix)        if not trueChecked: writer.write(' checked')        writer.write('> false &nbsp;')    def getEmptyValue (self):        return BooleanAttribute(0)class Cumulative:    """        Just a flag class for isinstance() calls. Denotes list or map        input    """    passclass ListInput (Input, Cumulative):    """        parsing/display lists    """    def parseRequest (self, req, prefix):        originalPrefix = ''+prefix        prefix = prefix + DOUBLE_POINT        tempMap = {}        hasToMoveUp = None        hasToMoveDown = None        for paramName in req.getParameterNames():            if not startsWith(paramName, prefix): continue            couple = _getNextCouple(paramName, prefix)            subPrefix = prefix+str(couple)            if not _hasToBeRemoved(req, subPrefix):                item = couple.input.parseRequest(req, subPrefix)                index = couple.getIntIndex()                tempMap[index] = item            if _hasToMoveUp(req, subPrefix):                hasToMoveUp = index                hasToMoveDown = index-1            elif _hasToMoveDown(req, subPrefix):                hasToMoveUp = index+1                hasToMoveDown = index                # movement        if hasToMoveUp:            movesUp = tempMap[hasToMoveUp]            tempMap[hasToMoveUp] = tempMap[hasToMoveDown]            tempMap[hasToMoveDown] = movesUp                # reorganize        list = ListAttribute()        index = 0        while 1:            if tempMap.has_key(index): list.add(tempMap[index])            index = index + 1            if index > 2 * len(tempMap): break        tempMap = None        # should we add a new element to the list ?        prefixForNewElement = req.getParameter(PREFIX_FOR_NEW_ELEMENT)        #log.debug('prefixForNewElement : "%s"' % prefixForNewElement)        #log.debug('original prefix :     "%s"' % originalPrefix)        if prefixForNewElement and originalPrefix == prefixForNewElement:            list.add(NewFieldInput())        # return result        return list    def displayInputTag (self, viewOnly, indentation, writer, value, prefix):        list = value        #log.debug('list class is %s' % list.__class__)        if len(list) < 1:            writer.write(indent(indentation+1))            writer.write('%s<br>' % MSG_EMPTY_LIST)            writer.write('<input type=hidden name="%s" ' % prefix)            writer.write('value="empty">')        for index in xrange(len(list)):            subValue = list.get(index)            subType = TYPE_MAP[subValue.__class__]            subPrefix = prefix + DOUBLE_POINT + str(index) + POINT + subType            subInput = INPUT_MAP[subType]            subInput = subInput()            subInput.displayInputTag\                (viewOnly, indentation+1, writer, subValue, subPrefix)                        if not viewOnly:                #                # display up and down buttons                _displayUpDownButtons(writer, subPrefix, index, len(list))                #                # display 'delete element'                _displayDeleteElement(writer, subPrefix)                    writer.write('<br>\n')        # display 'add element'        if not viewOnly:            _displayAddElement(indentation, writer, prefix)    def getEmptyValue (self):        return ListAttribute()class MapInput (Input, Cumulative):    """        parsing/display MapAttribute or StringMapAttribute instances    """    def parseRequest (self, req, prefix):        originalPrefix = ''+prefix        prefix = prefix + DOUBLE_POINT        keyMap = {}        valueMap = {}            # keys and values are temporarily stored in separate maps                for paramName in req.getParameterNames():            if not startsWith(paramName, prefix): continue            if _hasToBeRemoved(req, paramName): continue            couple = _getNextCouple(paramName, prefix)            item = couple.input.parseRequest(req, prefix+str(couple))            index = couple.getIntIndex()            entryIndex = index/2            if index % 2 == 0:                keyMap[entryIndex] = item            else:                valueMap[entryIndex] = item                # reconciliate keys and values                map = MapAttribute()        i = 0        while 1:            key = keyMap.get(i)            value = valueMap.get(i)            if key == None and value == None: break                        if key and value: map.put(key, value)                        i = i + 1        keyMap = None        valueMap = None                # should we add a new element to this map ?        prefixForNewElement = req.getParameter(PREFIX_FOR_NEW_ELEMENT)                if prefixForNewElement and prefixForNewElement == originalPrefix:            map.put(NewFieldInput(), NewFieldInput())                # return result        return map    def _displayKeyOrValue (self, isKey, viewOnly, indentation, writer, item, prefix, index):        type = TYPE_MAP[item.__class__]        input = INPUT_MAP[type]        input = input()        subPrefix = prefix + DOUBLE_POINT + str(index) + POINT + type        input.displayInputTag(viewOnly, indentation+1, writer, item, subPrefix)        # display 'delete element'        if not isKey and not viewOnly:            _displayDeleteElement(writer, subPrefix)    def displayInputTag (self, viewOnly, indentation, writer, value, prefix):        map = value        if len(map) < 1:            writer.write(indent(indentation+1))            writer.write('%s<br>' % MSG_EMPTY_MAP)            writer.write('<input type=hidden name="%s"' % prefix)            writer.write(' value="empty">')                index = 0        for aKey in map.keySet():            aValue = map.get(aKey)            # display key            writer.write('%s<br>\n' % MSG_KEY)                        self._displayKeyOrValue \                (1, viewOnly, indentation, writer, aKey, prefix, index)                        index = index + 1            writer.write('<br>\n')            # display value            writer.write('%s<br>\n' % MSG_VALUE)            self._displayKeyOrValue \                (0, viewOnly, indentation, writer, aValue, prefix, index)                        index = index + 1            writer.write('<br>\n')                # display 'add element'        if not viewOnly:            _displayAddElement(indentation, writer, prefix)    def getEmptyValue (self):        return MapAttribute()## the INPUT / ATTRIBUTE mapsTYPES = \    ['text', 'integer', 'long', 'double', 'boolean', 'list', 'map', 'smap', 'file']INPUT_MAP = \    {         'text': StringInput,         'integer': IntegerInput,         'long': LongInput,         'double': DoubleInput,         'boolean': BooleanInput,         'list': ListInput,         'map': MapInput,         'smap': MapInput,         '_default': AtomicAttributeInput,        'newfield': NewFieldInput,        'file': FileInput    }TYPE_MAP = \    {        StringAttribute: 'text',        IntegerAttribute: 'integer',        LongAttribute: 'long',        DoubleAttribute: 'double',        BooleanAttribute: 'boolean',        ListAttribute: 'list',        MapAttribute: 'map',        StringMapAttribute: 'smap',        NoneValue: 'newfield',        NewFieldInput: 'newfield',        FileInput: 'file'    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -