Example #1
0
    def exportRecord(self, record):

        node = etree.Element('record')
        node.attrib['name'] = record.__name__

        if IInterfaceAwareRecord.providedBy(record):
            node.attrib['interface'] = record.interfaceName
            node.attrib['field'] = record.fieldName

        # write field

        field = record.field
        if IFieldRef.providedBy(field):
            field_element = etree.Element('field')
            field_element.attrib['ref'] = field.recordName
            node.append(field_element)
        else:
            field_type = IFieldNameExtractor(record.field)()
            handler = queryUtility(IFieldExportImportHandler, name=field_type)
            if handler is None:
                self.logger.warning("Field type %s specified for record %s \
                    cannot be exported" % (field_type, record.__name__))
            else:
                field_element = handler.write(record.field, None, field_type, elementName='field')
                node.append(field_element)

        # write value

        value_element = valueToElement(record.field, record.value, name='value', force=True)
        node.append(value_element)

        return node
Example #2
0
    def exportRecord(self, record):

        node = etree.Element('record')
        node.attrib['name'] = record.__name__

        if IInterfaceAwareRecord.providedBy(record):
            node.attrib['interface'] = record.interfaceName
            node.attrib['field'] = record.fieldName

        # write field

        field = record.field
        if IFieldRef.providedBy(field):
            field_element = etree.Element('field')
            field_element.attrib['ref'] = field.recordName
            node.append(field_element)
        else:
            field_type = IFieldNameExtractor(record.field)()
            handler = queryUtility(IFieldExportImportHandler, name=field_type)
            if handler is None:
                self.logger.warning(
                    'Field type {0} specified for record {1} '
                    'cannot be exported'.format(field_type, record.__name__)
                )
            else:
                field_element = handler.write(
                    record.field,
                    None,
                    field_type,
                    elementName='field'
                )
                node.append(field_element)

        # write value
        value_element = valueToElement(
            record.field,
            record.value,
            name='value',
            force=True
        )
        node.append(value_element)

        return node
Example #3
0
def redispatchInterfaceAwareRecordEvents(event):
    """When an interface-aware record received a record event,
    redispatch the event in a simlar manner to the IObjectEvent redispatcher.

    Note that this means one IRecordModifiedEvent will be fired for each
    change to a record.
    """

    record = event.record

    if not IInterfaceAwareRecord.providedBy(record):
        return

    schema = record.interface
    if schema is None:
        return

    proxy = RecordsProxy(record.__parent__, schema)

    adapters = subscribers((proxy, event), None)
    for adapter in adapters:
        pass # getting them does the work
Example #4
0
def redispatchInterfaceAwareRecordEvents(event):
    """When an interface-aware record received a record event,
    redispatch the event in a simlar manner to the IObjectEvent redispatcher.

    Note that this means one IRecordModifiedEvent will be fired for each
    change to a record.
    """

    record = event.record

    if not IInterfaceAwareRecord.providedBy(record):
        return

    schema = record.interface
    if schema is None:
        return

    proxy = RecordsProxy(record.__parent__, schema)

    adapters = subscribers((proxy, event), None)
    for adapter in adapters:
        pass  # getting them does the work