Beispiel #1
0
    def test_on_save_tile_data_is_cleaned(self):
        self.behavior.customContentLayout = """
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html data-layout="./@@default-site-layout">
<body>
  <div data-tile="./@@faketile/foobar-1"></div>
  <div data-tile="./@@faketile/foobar-2"></div>
  <div data-tile="./@@faketile/foobar-3"></div>
  <div data-tile="./@@faketile/foobar-4"></div>
</body>
</html>"""

        obj = self.portal['f1']['d1']
        annotations = IAnnotations(obj)
        annotations.update({
            ANNOTATIONS_KEY_PREFIX + '.foobar-1': {
                'foo': 'bar'
            },
            ANNOTATIONS_KEY_PREFIX + '.foobar-2': {
                'foo': 'bar'
            },
            ANNOTATIONS_KEY_PREFIX + '.foobar-3': {
                'foo': 'bar'
            },
            ANNOTATIONS_KEY_PREFIX + '.foobar-4': {
                'foo': 'bar'
            },
            ANNOTATIONS_KEY_PREFIX + '.bad-1': {
                'foo': 'bar'
            },
            ANNOTATIONS_KEY_PREFIX + '.bad-2': {
                'foo': 'bar'
            },
            ANNOTATIONS_KEY_PREFIX + '.bad-3': {
                'foo': 'bar'
            },
        })

        from plone.app.blocks.subscribers import onLayoutEdited
        onLayoutEdited(obj, None)
        annotations = IAnnotations(obj)
        self.assertTrue(ANNOTATIONS_KEY_PREFIX + '.foobar-1' in annotations)
        self.assertTrue(ANNOTATIONS_KEY_PREFIX + '.foobar-2' in annotations)
        self.assertTrue(ANNOTATIONS_KEY_PREFIX + '.foobar-3' in annotations)
        self.assertTrue(ANNOTATIONS_KEY_PREFIX + '.foobar-4' in annotations)
        self.assertFalse(ANNOTATIONS_KEY_PREFIX + '.bad-1' in annotations)
        self.assertFalse(ANNOTATIONS_KEY_PREFIX + '.bad-2' in annotations)
        self.assertFalse(ANNOTATIONS_KEY_PREFIX + '.bad-3' in annotations)
Beispiel #2
0
    def _replaceBaseline( self, baseline ):
        wc_id = self.context.getId()
        wc_container = aq_parent( self.context )

        # copy all field values from the working copy to the baseline
        for schema in iterSchemata( baseline ):
            for name, field in getFieldsInOrder( schema ):
                # Skip read-only fields
                if field.readonly:
                    continue
                if field.__name__ == 'id':
                    continue
                try:
                    value = field.get( schema( self.context ) )
                except:
                    value = None

                # TODO: We need a way to identify the DCFieldProperty
                # fields and use the appropriate set_name/get_name
                if name == 'effective':
                    baseline.effective_date = self.context.effective()
                elif name == 'expires':
                    baseline.expiration_date = self.context.expires()
                elif name == 'subjects':
                    baseline.setSubject(self.context.Subject())
                else:
                    field.set( baseline, value )

        baseline.reindexObject()

        # copy annotations
        wc_annotations = IAnnotations(self.context)
        baseline_annotations = IAnnotations(baseline)

        baseline_annotations.clear()
        baseline_annotations.update(wc_annotations)

        # delete the working copy
        wc_container._delObject( wc_id )

        return baseline