문제

I'm having problems in getting my Dexterity content type to show a custom Add Form. I have already done this in a previous product, but, amazingly, I cannot accomplish this using Plone 4.1 and plone.app.dexterity 1.0.3

My CrmContact content type, living in package.name.types.contact.py, has its schema defined in this way:

from five import grok
from zope import schema
from zope.interface import implements

from plone.directives import form, dexterity


class ICrmContact(form.Schema):
    """A contact item for the CRM"""

    title = schema.TextLine(
            title=_(u"Company name"),
    )

    ...

class CrmContact(dexterity.Container):
    implements(ICrmContact)


class Add(dexterity.AddForm):

    grok.context(ICrmContact)
    grok.name('package.name.contacts.types.contact')
    grok.template('add')

My template lives in package/name/types/contact_templates. It's a typical template. I know it's not being rendered because it has a dummy node that will call a non existing method using tal:content, in order to raise an exception; so I'm sure the template itself is not the issue.

My content type FTI is registered correctly during installation, and the content type is available and addable.

Finally, in profiles/default/types.package.name.types.contact.xml:

<?xml version="1.0"?>
<object name="package.name.types.contact" meta_type="Dexterity FTI"
    i18n:domain="package.name" xmlns:i18n="http://xml.zope.org/namespaces/i18n">

    ...

    <!-- Method aliases -->
    <alias from="(Default)" to="(dynamic view)" />
    <alias from="edit" to="@@edit" />
    <alias from="sharing" to="@@sharing" />
    <alias from="view" to="(selected layout)" />

    <!-- Actions -->
    <action title="View" action_id="view" category="object"
        condition_expr="" url_expr="string:${object_url}" visible="True">
        <permission value="View" />
    </action>
    <action title="Edit" action_id="edit" category="object"
        condition_expr="" url_expr="string:${object_url}/edit" visible="True">
        <permission value="Modify portal content" />
    </action>
</object>

Unrelated, but maybe I have to add something here...

I think I followed the correct procedure, as you may see, but I still cannot get it to work.

I know class Add is getting instanced because if I provide an updateWidgets() method and insert a breakpoint, it gets called; and when I introspect the object, self.template is None; even though:

(Pdb) getattr(self, 'grokcore.view.directive.template')
'add'

How can I provide a custom template to the Add Form of my custom type?

도움이 되었습니까?

해결책

You should remove the line grok.context(ICrmContact).

From http://plone.org/products/dexterity/documentation/manual/developer-manual/advanced/forms:

Also note that we do not specify a context here. Add forms are always registered for any IFolderish context.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top