def calcFieldNames(self, path = [], force_prefix = False):
        ''' prefixes the field names with the parent field name '''
        _fields = self.Schema()._fields

        for f in self.Schema().fields():
            if not getattr(f, 'prefixed', False) or force_prefix:
                # calcFieldNames are often called several times for the same
                # field, e.g. when copying a schema. We do not want to perform
                # prefixing everytime this method is called. We only want to
                # prefix field names in two cases:
                # a) The first time we process a field
                # b) If calcFieldNames is called recursively on subfields, to
                # apply the correct parent field names to the prefixing of a
                # subfield. In this case we set the paramter force_prefix.
                if not getattr(f, 'prefixed', False):
                    # only set old_name the first time we prefix a field - old_name
                    # is the original field name, that we want to use in all prefixings of a field.
                    f.old_name =  f.getName()
                    f.prefixed = 1
                f.__name__ = config.COMPOUND_FIELD_SEPERATOR.join(
                    [getattr(field, 'old_name', field.getName()) for field in path + [self] + [f]])
                #del _fields[old_name]
                _fields[f.__name__] = f
                if ICompoundField.providedBy(f):
                    f.calcFieldNames(path = path + [self], force_prefix = True)
    def calcFieldNames(self, path=[], force_prefix=False):
        ''' prefixes the field names with the parent field name '''
        _fields = self.Schema()._fields

        for f in self.Schema().fields():
            if not getattr(f, 'prefixed', False) or force_prefix:
                # calcFieldNames are often called several times for the same
                # field, e.g. when copying a schema. We do not want to perform
                # prefixing everytime this method is called. We only want to
                # prefix field names in two cases:
                # a) The first time we process a field
                # b) If calcFieldNames is called recursively on subfields, to
                # apply the correct parent field names to the prefixing of a
                # subfield. In this case we set the paramter force_prefix.
                if not getattr(f, 'prefixed', False):
                    # only set old_name the first time we prefix a field - old_name
                    # is the original field name, that we want to use in all prefixings of a field.
                    f.old_name = f.getName()
                    f.prefixed = 1
                f.__name__ = config.COMPOUND_FIELD_SEPERATOR.join([
                    getattr(field, 'old_name', field.getName())
                    for field in path + [self] + [f]
                ])
                #del _fields[old_name]
                _fields[f.__name__] = f
                if ICompoundField.providedBy(f):
                    f.calcFieldNames(path=path + [self], force_prefix=True)
Ejemplo n.º 3
0
    def getAttributes(self, instance, exclude_attrs=()):

        # remove fields delegated to other namespaces

        fields = instance.Schema().fields()
        for f in fields:
            if ICompoundField.isImplementedBy(f):
                yield self.getAttributeByName(f.getName())
Ejemplo n.º 4
0
    def getAttributes(self, instance, exclude_attrs=()):

        # remove fields delegated to other namespaces

        fields = instance.Schema().fields()
        for f in fields:
            if ICompoundField.isImplementedBy(f):
                yield self.getAttributeByName(f.getName())