コード例 #1
0
ファイル: test_fti.py プロジェクト: polyester/plone.dexterity
    def test_fires_modified_event_on_change_props_per_changed_property(self):
        fti = DexterityFTI('testtype')
        fti.title = 'Old title'
        fti.allow_discussion = False
        fti.global_allow = True

        notify_mock = self.mocker.replace('zope.event.notify')
        self.expect(
            notify_mock(
                mocker.MATCH(
                    lambda x: IObjectModifiedEvent.providedBy(x) and len(
                        x.descriptions) == 1 and x.descriptions[0].attribute ==
                    'title' and x.descriptions[0].oldValue == 'Old title')))

        self.expect(
            notify_mock(
                mocker.MATCH(
                    lambda x: IObjectModifiedEvent.providedBy(x) and len(
                        x.descriptions) == 1 and x.descriptions[0].attribute ==
                    'global_allow' and x.descriptions[0].oldValue is True)))
        self.replay()

        fti.manage_changeProperties(title='New title',
                                    allow_discussion=False,
                                    global_allow=False)
コード例 #2
0
ファイル: test_fti.py プロジェクト: Vinsurya/Plone
    def test_fires_modified_event_on_change_props_per_changed_property(self):
        fti = DexterityFTI(u"testtype")
        fti.title = "Old title"
        fti.allow_discussion = False
        fti.global_allow = True

        notify_mock = self.mocker.replace('zope.event.notify')
        self.expect(
            notify_mock(
                mocker.MATCH(
                    lambda x: IObjectModifiedEvent.providedBy(x)
                    and len(x.descriptions) == 1
                    and x.descriptions[0].attribute == 'title'
                    and x.descriptions[0].oldValue == "Old title"
                )
            )
        )

        self.expect(
            notify_mock(
                mocker.MATCH(
                    lambda x: IObjectModifiedEvent.providedBy(x)
                    and len(x.descriptions) == 1
                    and x.descriptions[0].attribute == 'global_allow'
                    and x.descriptions[0].oldValue is True
                )
            )
        )
        self.replay()

        fti.manage_changeProperties(
            title="New title",
            allow_discussion=False,
            global_allow=False
        )
コード例 #3
0
    def create(self, data):
        id = data.pop('id')

        fti = DexterityFTI(id)
        fti.id = id
        data['title'] = data['title'].encode('utf8')
        if data['description']:
            data['description'] = data['description'].encode('utf8')
        data['i18n_domain'] = 'plone'
        data['behaviors'] = '\n'.join([
            'plone.dublincore',
            'plone.namefromtitle',
        ])
        data['model_source'] = """
<model xmlns="http://namespaces.plone.org/supermodel/schema">
    <schema>
    </schema>
</model>
"""

        data['klass'] = 'plone.dexterity.content.Container'
        data['filter_content_types'] = True
        data['icon_expr'] = 'string:${portal_url}/document_icon.png'
        fti.manage_changeProperties(**data)
        return fti
コード例 #4
0
    def create(self, data):
        id = data.pop('id')

        fti = DexterityFTI(id)
        fti.id = id
        data['title'] = data['title'].encode('utf8')
        if data['description']:
            data['description'] = data['description'].encode('utf8')
        data['i18n_domain'] = 'plone'
        data['behaviors'] = "\n".join([
            'plone.app.dexterity.behaviors.metadata.IDublinCore',
            'plone.app.content.interfaces.INameFromTitle',
        ])
        data['model_source'] = """
<model xmlns="http://namespaces.plone.org/supermodel/schema">
    <schema>
    </schema>
</model>
"""

        data['klass'] = 'plone.dexterity.content.Container'
        data['filter_content_types'] = True
        data['icon_expr'] = 'string:${portal_url}/document_icon.png'
        fti.manage_changeProperties(**data)
        return fti
コード例 #5
0
    def create(self, data):
        id = data.pop('id')

        fti = DexterityFTI(id)
        fti.id = id
        data['title'] = data['title'].encode('utf8')
        if data['description']:
            data['description'] = data['description'].encode('utf8')
        data['i18n_domain'] = 'plone'
        data['behaviors'] = "\n".join(['plone.app.dexterity.behaviors.metadata.IDublinCore',
                                       'plone.app.content.interfaces.INameFromTitle',
                                       ])
        data['model_source'] = """
<model xmlns="http://namespaces.plone.org/supermodel/schema">
    <schema>
    </schema>
</model>
"""
        if data['container']:
            data['klass'] = 'plone.dexterity.content.Container'
            data['filter_content_types'] = False
            del data['container']
            icon = 'folder_icon'
        else:
            icon = 'document_icon'
        data['icon_expr'] = 'string:${portal_url}/' + icon + '.png'
        fti.manage_changeProperties(**data)
        return fti
コード例 #6
0
ファイル: tools.py プロジェクト: seantis/seantis.plonetools
def add_new_dexterity_type(name, **kwargs):
    """ Adds a new dexterity type the same way Dexterity does it internally,
    when using the form. The difference is that this function does not
    assume any defaults and creates the types with the parameters given.

    Behaviors may be given as a list (Dexterity needs a multiline string).
    """
    new_type = DexterityFTI(name)

    if not 'klass' in kwargs:
        kwargs['klass'] = 'plone.dexterity.content.Container'

    if 'behaviors' in kwargs:
        if isinstance(kwargs['behaviors'], list):
            kwargs['behaviors'] = '\n'.join(kwargs['behaviors'])

    new_type.manage_changeProperties(
        **kwargs
    )

    types = api.portal.get_tool('portal_types')
    types._setObject(new_type.id, new_type)

    register_dexterity_type(new_type)

    return new_type
コード例 #7
0
ファイル: test_fti.py プロジェクト: vedantc98/Plone-test
    def test_fires_modified_event_on_change_props_per_changed_property(self):
        fti = DexterityFTI(u"testtype")
        fti.title = "Old title"
        fti.allow_discussion = False
        fti.global_allow = True

        from zope.event import notify
        notify_mock = self.patch_global(notify)

        fti.manage_changeProperties(title="New title",
                                    allow_discussion=False,
                                    global_allow=False)

        self.assertEqual(len(notify_mock.call_args_list), 2)
コード例 #8
0
ファイル: test_fti.py プロジェクト: plone/plone.dexterity
    def test_fires_modified_event_on_change_props_per_changed_property(self):
        fti = DexterityFTI(u"testtype")
        fti.title = "Old title"
        fti.allow_discussion = False
        fti.global_allow = True

        from zope.event import notify
        notify_mock = self.patch_global(notify)

        fti.manage_changeProperties(
            title="New title",
            allow_discussion=False,
            global_allow=False
        )

        self.assertEqual(len(notify_mock.call_args_list), 2)