예제 #1
0
    def metadataField(self, field, v=True, ed=True):
        """
        Crea un objeto FLFieldMetaData a partir de un elemento XML.

        Dado un elemento XML, que contiene la descripción de un
        campo de una tabla construye y agrega a una lista de descripciones
        de campos el objeto FLFieldMetaData correspondiente, que contiene
        dicha definición del campo. Tambien lo agrega a una lista de claves
        compuesta, si el campo construido pertenece a una clave compuesta.
        NO SE HACEN CHEQUEOS DE ERRORES SINTÁCTICOS EN EL XML.

        @param field Elemento XML con la descripción del campo
        @param v Valor utilizado por defecto para la propiedad visible
        @param ed Valor utilizado por defecto para la propiedad editable
        @return Objeto FLFieldMetaData que contiene la descripción del campo
        """
        if not field:
            return None

        util = FLUtil()

        ck = False
        n = None
        a = None
        ol = False
        rX = None
        assocBy = None
        assocWith = None
        so = None

        aN = True
        iPK = True
        c = False
        iNX = False
        uNI = False
        coun = False
        oT = False
        vG = True
        fullCalc = False
        trimm = False

        t = -1
        length = 0
        pI = 4
        pD = 0

        dV = None

        no = field.firstChild()

        while not no.isNull():
            e = no.toElement()
            if not e.isNull():
                if e.tagName() in ("relation", "associated"):
                    no = no.nextSibling()
                    continue

                if e.tagName() == "name":
                    n = e.text()
                    no = no.nextSibling()
                    continue

                if e.tagName() == "alias":
                    a = auto_qt_translate_text(e.text())
                    no = no.nextSibling()
                    continue

                if e.tagName() == "null":
                    aN = (e.text() == "true")
                    no = no.nextSibling()
                    continue

                if e.tagName() == "pk":
                    iPK = (e.text() == "true")
                    no = no.nextSibling()
                    continue

                if e.tagName() == "type":
                    if e.text() == "int":
                        t = "int"
                    elif e.text() == "uint":
                        t = "uint"
                    elif e.text() == "bool":
                        t = "bool"
                    elif e.text() == "double":
                        t = "double"
                    elif e.text() == "time":
                        t = "time"
                    elif e.text() == "date":
                        t = "date"
                    elif e.text() == "pixmap":
                        t = "pixmap"
                    elif e.text() == "bytearray":
                        t = "bytearray"
                    elif e.text() == "string":
                        t = "string"
                    elif e.text() == "stringlist":
                        t = "stringlist"
                    elif e.text() == "unlock":
                        t = "unlock"
                    elif e.text() == "serial":
                        t = "serial"
                    no = no.nextSibling()
                    continue

                if e.tagName() == "length":
                    length = int(e.text())
                    no = no.nextSibling()
                    continue

                if e.tagName() == "regexp":
                    rX = e.text()
                    no = no.nextSibling()
                    continue

                if e.tagName() == "default":
                    if e.text().find("QT_TRANSLATE_NOOP") > -1:
                        dV = auto_qt_translate_text(e.text())
                    else:
                        dV = e.text()

                    no = no.nextSibling()
                    continue

                if e.tagName() == "outtransaction":
                    oT = (e.text() == "true")
                    no = no.nextSibling()
                    continue

                if e.tagName() == "counter":
                    coun = (e.text() == "true")
                    no = no.nextSibling()
                    continue

                if e.tagName() == "calculated":
                    c = (e.text() == "true")
                    no = no.nextSibling()
                    continue

                if e.tagName() == "fullycalculated":
                    fullCalc = (e.text() == "true")
                    no = no.nextSibling()
                    continue

                if e.tagName() == "trimmed":
                    trimm = (e.text() == "true")
                    no = no.nextSibling()
                    continue

                if e.tagName() == "visible":
                    v = (e.text() == "true")
                    no = no.nextSibling()
                    continue

                if e.tagName() == "visiblegrid":
                    vG = (e.text() == "true")
                    no = no.nextSibling()
                    continue

                if e.tagName() == "editable":
                    ed = (e.text() == "true")
                    no = no.nextSibling()
                    continue

                if e.tagName() == "partI":
                    pI = int(e.text())
                    no = no.nextSibling()
                    continue

                if e.tagName() == "partD":
                    pD = int(e.text())
                    no = no.nextSibling()
                    continue

                if e.tagName() == "index":
                    iNX = (e.text() == "true")
                    no = no.nextSibling()
                    continue

                if e.tagName() == "unique":
                    uNI = (e.text() == "true")
                    no = no.nextSibling()
                    continue

                if e.tagName() == "ck":
                    ck = (e.text() == "true")
                    no = no.nextSibling()
                    continue

                if e.tagName() == "optionslist":
                    ol = e.text()
                    no = no.nextSibling()
                    continue

                if e.tagName() == "searchoptions":
                    so = e.text()
                    no = no.nextSibling()
                    continue

            no = no.nextSibling()

        f = FLFieldMetaData(n, util.translate("Metadata",
                                              a), aN, iPK, t, length, c, v, ed,
                            pI, pD, iNX, uNI, coun, dV, oT, rX, vG, True, ck)
        f.setFullyCalculated(fullCalc)
        f.setTrimed(trimm)

        if ol:
            f.setOptionsList(ol)
        if so is not None:
            f.setSearchOptions(so)

        no = field.firstChild()

        while not no.isNull():
            e = no.toElement()
            if not e.isNull():
                if e.tagName() == "relation":
                    f.addRelationMD(self.metadataRelation(e))
                    no = no.nextSibling()
                    continue

                if e.tagName() == "associated":
                    noas = e.firstChild()
                    while not noas.isNull():
                        eas = noas.toElement()
                        if not eas.isNull():
                            if eas.tagName() == "with":
                                assocWith = eas.text()
                                noas = noas.nextSibling()
                                continue

                            if eas.tagName() == "by":
                                assocBy = eas.text()
                                noas = noas.nextSibling()
                                continue

                        noas = noas.nextSibling()

                    no = no.nextSibling()
                    continue

            no = no.nextSibling()

        if assocWith and assocBy:
            f.setAssociatedField(assocWith, assocBy)

        return f
예제 #2
0
    def metadataField(self, field, v=True, ed=True):
        if not field:
            return None

        util = FLUtil()

        ck = False
        n = None
        a = None
        ol = False
        rX = None
        assocBy = None
        assocWith = None
        so = None

        aN = True
        iPK = True
        c = False
        iNX = False
        uNI = False
        coun = False
        oT = False
        vG = True
        fullCalc = False
        trimm = False

        t = -1
        l = 0
        pI = 4
        pD = 0

        dV = None

        no = field.firstChild()

        while not no.isNull():
            e = no.toElement()
            if not e.isNull():
                if e.tagName() in ("relation", "associated"):
                    no = no.nextSibling()
                    continue

                if e.tagName() == "name":
                    n = e.text()
                    no = no.nextSibling()
                    continue

                if e.tagName() == "alias":
                    a = auto_qt_translate_text(e.text())
                    no = no.nextSibling()
                    continue

                if e.tagName() == "null":
                    aN = (e.text() == "true")
                    no = no.nextSibling()
                    continue

                if e.tagName() == "pk":
                    iPK = (e.text() == "true")
                    no = no.nextSibling()
                    continue

                if e.tagName() == "type":
                    if e.text() == "int":
                        t = "int"
                    elif e.text() == "uint":
                        t = "uint"
                    elif e.text() == "bool":
                        t = "bool"
                    elif e.text() == "double":
                        t = "double"
                    elif e.text() == "time":
                        t = "time"
                    elif e.text() == "date":
                        t = "date"
                    elif e.text() == "pixmap":
                        t = "pixmap"
                    elif e.text() == "bytearray":
                        t = "bytearray"
                    elif e.text() == "string":
                        t = "string"
                    elif e.text() == "stringlist":
                        t = "stringlist"
                    elif e.text() == "unlock":
                        t = "unlock"
                    elif e.text() == "serial":
                        t = "serial"
                    no = no.nextSibling()
                    continue

                if e.tagName() == "length":
                    l = int(e.text())
                    no = no.nextSibling()
                    continue

                if e.tagName() == "regexp":
                    rX = e.text()
                    no = no.nextSibling()
                    continue

                if e.tagName() == "default":
                    if e.text().find("QT_TRANSLATE_NOOP") > -1:
                        dV = auto_qt_translate_text(e.text())
                    else:
                        dV = e.text()

                    no = no.nextSibling()
                    continue

                if e.tagName() == "outtransaction":
                    oT = (e.text() == "true")
                    no = no.nextSibling()
                    continue

                if e.tagName() == "counter":
                    coun = (e.text() == "true")
                    no = no.nextSibling()
                    continue

                if e.tagName() == "calculated":
                    c = (e.text() == "true")
                    no = no.nextSibling()
                    continue

                if e.tagName() == "fullycalculated":
                    fullCalc = (e.text() == "true")
                    no = no.nextSibling()
                    continue

                if e.tagName() == "trimmed":
                    trimm = (e.text() == "true")
                    no = no.nextSibling()
                    continue

                if e.tagName() == "visible":
                    v = (e.text() == "true")
                    no = no.nextSibling()
                    continue

                if e.tagName() == "visiblegrid":
                    vG = (e.text() == "true")
                    no = no.nextSibling()
                    continue

                if e.tagName() == "editable":
                    ed = (e.text() == "true")
                    no = no.nextSibling()
                    continue

                if e.tagName() == "partI":
                    pI = int(e.text())
                    no = no.nextSibling()
                    continue

                if e.tagName() == "partD":
                    pD = int(e.text())
                    no = no.nextSibling()
                    continue

                if e.tagName() == "index":
                    iNX = (e.text() == "true")
                    no = no.nextSibling()
                    continue

                if e.tagName() == "unique":
                    uNI = (e.text() == "true")
                    no = no.nextSibling()
                    continue

                if e.tagName() == "ck":
                    ck = (e.text() == "true")
                    no = no.nextSibling()
                    continue

                if e.tagName() == "optionslist":
                    ol = e.text()
                    no = no.nextSibling()
                    continue

                if e.tagName() == "searchoptions":
                    so = e.text()
                    no = no.nextSibling()
                    continue

            no = no.nextSibling()

        f = FLFieldMetaData(n, util.translate("Metadata",
                                              a), aN, iPK, t, l, c, v, ed, pI,
                            pD, iNX, uNI, coun, dV, oT, rX, vG, True, ck)
        f.setFullyCalculated(fullCalc)
        f.setTrimed(trimm)

        if ol:
            f.setOptionsList(ol)
        if not so == None:
            f.setSearchOptions(so)

        no = field.firstChild()

        while not no.isNull():
            e = no.toElement()
            if not e.isNull():
                if e.tagName() == "relation":
                    f.addRelationMD(self.metadataRelation(e))
                    no = no.nextSibling()
                    continue

                if e.tagName() == "associated":
                    noas = e.firstChild()
                    while not noas.isNull():
                        eas = noas.toElement()
                        if not eas.isNull():
                            if eas.tagName() == "with":
                                assocWith = eas.text()
                                noas = noas.nextSibling()
                                continue

                            if eas.tagName() == "by":
                                assocBy = eas.text()
                                noas = noas.nextSibling()
                                continue

                        noas = noas.nextSibling()

                    no = no.nextSibling()
                    continue

            no = no.nextSibling()

        if assocWith and assocBy:
            f.setAssociatedField(assocWith, assocBy)

        return f