Beispiel #1
0
    def getFields(self, obj1, obj2):
        fields = []
        # Make sure we get the fields ordered by schemata, as in the edit view
        schematas = obj1.Schemata()
        schemata_names = schematas.keys()

        # Put default first and metadata last
        if 'default' in schemata_names and schemata_names[0] != 'default':
            schemata_names.remove('default')
            schemata_names.insert(0, 'default')
        if 'metadata' in schemata_names and schemata_names[-1] != 'metadata':
            schemata_names.remove('metadata')
            schemata_names.insert(-1, 'metadata')

        for schemata_name in schemata_names:
            schema = schematas[schemata_name]
            for field in schema.viewableFields(obj1):
                if (AT_FIELD_MAPPING.has_key(field.type)
                        and field.getName() not in AT_EXCLUDED_FIELDS):
                    is_primary = getattr(field, 'primary', False)
                    label = field.widget.Label(obj1)
                    diff_type = AT_FIELD_MAPPING[field.type]
                    if IDifference.implementedBy(diff_type):
                        fields.append({
                            'name': field.getName(),
                            'accessor': field.accessor,
                            'klass': diff_type,
                            'primary': is_primary,
                            'label': label,
                            'schemata': schemata_name
                        })
                    elif 'raw' in diff_type:
                        #Handle Fields which diff against the edit accessor
                        diff_name = diff_type.split(':')[1]
                        diff_type = globals()[diff_name]
                        fields.append({
                            'name': field.getName(),
                            'accessor': field.edit_accessor,
                            'klass': diff_type,
                            'primary': is_primary,
                            'label': label,
                            'schemata': schemata_name
                        })
                    elif diff_type == 'variable_binary':
                        diff_type = BinaryDiff
                        if 'text/' in field.getContentType(obj1) and \
                        'text/' in \
                            obj2.getField(field.getName()).getContentType(obj2):
                            diff_type = TextDiff
                        fields.append({
                            'name': field.getName(),
                            'accessor': field.accessor,
                            'klass': diff_type,
                            'primary': is_primary,
                            'label': label,
                            'schemata': schemata_name
                        })
                    elif diff_type == 'variable_text':
                        diff_type = TextDiff
                        if 'html' in field.getContentType(obj1) and \
                        'html' in \
                            obj2.getField(field.getName()).getContentType(obj2):
                            diff_type = CMFDTHtmlDiff
                        fields.append({
                            'name': field.getName(),
                            'accessor': field.accessor,
                            'klass': diff_type,
                            'primary': is_primary,
                            'label': label,
                            'schemata': schemata_name
                        })
        return fields
Beispiel #2
0
 def testInterface(self):
     """Ensure that tool instances implement the portal_diff interface"""
     from Products.CMFDiffTool.interfaces.portal_diff import IDifference
     self.failUnless(IDifference.isImplementedByInstancesOf(FieldDiff))
Beispiel #3
0
 def testInterface(self):
     """Ensure that tool instances implement the portal_diff interface"""
     from Products.CMFDiffTool.interfaces.portal_diff import IDifference
     self.assertTrue(IDifference.implementedBy(ListDiff))
    def getFields(self, obj1, obj2):
        fields = []
        # Make sure we get the fields ordered by schemata, as in the edit view
        schematas = obj1.Schemata()
        schemata_names = schematas.keys()

        # Put default first and metadata last
        if 'default' in schemata_names and schemata_names[0] != 'default':
            schemata_names.remove('default')
            schemata_names.insert(0, 'default')
        if 'metadata' in schemata_names and schemata_names[-1] != 'metadata':
            schemata_names.remove('metadata')
            schemata_names.insert(-1, 'metadata')

        for schemata_name in schemata_names:
            schema = schematas[schemata_name]
            for field in schema.viewableFields(obj1):
                if (field.type in AT_FIELD_MAPPING and
                        field.getName() not in AT_EXCLUDED_FIELDS):
                    is_primary = getattr(field, 'primary', False)
                    label = field.widget.Label(obj1)
                    diff_type = AT_FIELD_MAPPING[field.type]
                    if IDifference.implementedBy(diff_type):
                        fields.append({'name': field.getName(),
                                       'accessor': field.accessor,
                                       'klass': diff_type,
                                       'primary': is_primary,
                                       'label': label,
                                       'schemata': schemata_name})
                    elif 'raw' in diff_type:
                        #  Handle Fields which diff against the edit accessor
                        diff_name = diff_type.split(':')[1]
                        diff_type = globals()[diff_name]
                        fields.append({'name': field.getName(),
                                       'accessor': field.edit_accessor,
                                       'klass': diff_type,
                                       'primary': is_primary,
                                       'label': label,
                                       'schemata': schemata_name})
                    elif diff_type == 'variable_binary':
                        diff_type = BinaryDiff
                        if ('text/' in field.getContentType(obj1) and
                                'text/' in (obj2.getField(field.getName())
                                            .getContentType(obj2))):
                            diff_type = TextDiff
                        fields.append({'name': field.getName(),
                                       'accessor': field.accessor,
                                       'klass': diff_type,
                                       'primary': is_primary,
                                       'label': label,
                                       'schemata': schemata_name})
                    elif diff_type == 'variable_text':
                        diff_type = TextDiff
                        if ('html' in field.getContentType(obj1) and
                                'html' in (obj2.getField(field.getName())
                                           .getContentType(obj2))):
                            diff_type = CMFDTHtmlDiff
                        fields.append({'name': field.getName(),
                                       'accessor': field.accessor,
                                       'klass': diff_type,
                                       'primary': is_primary,
                                       'label': label,
                                       'schemata': schemata_name})
        return fields
 def testInterface(self):
     """Ensure that tool instances implement the portal_diff interface"""
     from Products.CMFDiffTool.interfaces.portal_diff import IDifference
     self.assertTrue(IDifference.implementedBy(FieldDiff))
Beispiel #6
0
 def testInterface(self):
     """Ensure that tool instances implement the portal_diff interface"""
     from Products.CMFDiffTool.interfaces.portal_diff import IDifference
     self.failUnless(IDifference.isImplementedByInstancesOf(ListDiff))