[Zope-CMF] Re: Overriding title from DefaultDublinCoreImpl
Florent Guillaume
fg@nuxeo.com
Wed, 24 Jul 2002 18:04:12 +0200
Hmmm, ok.
If you want DublinCore's title to be your localized title, then you have
to override Title and setTitle to go to the localized version using
LocalPropertyManager's API.
If you want other standard metadata to be multilingual, you'll have to
do the same thing for those.
And to answer your last question: python is not C++, you can't have two
version of a method with a different number of arguments. In python the
last defined or first inherited function with the correct name wins.
Florent
In article <1303342208.20020722222627@gmx.de> you write:
> Florent,
>
> Florent Guillaume wrote:
>
> >Your whole description of what you do is not very clear. Show us some
> >precise code.
>
> of course you're right. I was not sure if i could post long code into
> the list. I try to specify my problem:
>
> I have a product with several classes, all derived from
> LocalPropertyManager, PortalFolder, PortalContent and
> DefaultDublinCoreImpl.
> These classes have a folderish behaviour and support Metadata and all
> the typical CMF-stuff. Localizer is used to have multilingual
> properties, where the number of languages is fixed. Only german and
> english will be used, so there is no need to provide a method to add a
> language by the user. I use the default metadata_edit_form and my own
> edit form for the properties which is shown below.
> The localizer stuff works fine, except for the 'title' property,
> because it is already defined and used in DefaultDublinCoreImpl.
>
> Here a snippet of the class definition for the class 'Kolloquium'
>
> def addKolloquium(self,
> id,
> title='Titel des Vortrags',
> Abstract='Kurze Zusammenfassung',
> languages=('de','en')
> ):
> """ Create an empty Kolloquium """
> kolloquium_object = Kolloquium(id,
> title,
> Abstract,
> tuple(languages)
> )
> self._setObject(id, kolloquium_object)
>
> class Kolloquium(LocalPropertyManager, PortalFolder, PortalContent,
> DefaultDublinCoreImpl):
>
> meta_type = 'Kolloquium'
>
> security = ClassSecurityInfo()
> security.declareObjectPublic()
>
> title = LocalProperty('title')
> Abstract = LocalProperty('Abstract')
> # LocalPropertyManager needs some metadata,
> # this is similar to the PropertyManager mixin class.
> _local_properties_metadata = ({'id': 'title', 'type': 'string'},
> {'id': 'Abstract', 'type': 'text'}
> )
>
> def __init__(self,
> id,
> title='',
> Abstract='',
> languages=''
> ):
>
> ## parents constructors
> DefaultDublinCoreImpl.__init__(self)
>
> ## set infos
> self.id = id
> for language in languages:
> self.manage_addLanguage(language)
> self._setLocalPropValue('title', language, title)
> self._setLocalPropValue('Abstract', language, Abstract)
>
> security.declarePrivate( '_edit' )
> def _edit( self,
> title=None,
> Abstract=None,
> language=None,
> ):
>
> if title is not None:
> self._setLocalPropValue('title', language, title)
> if Abstract is not None:
> self._setLocalPropValue('Abstract', language, Abstract)
>
> security.declareProtected( CMFCorePermissions.ModifyPortalContent, 'edit' )
> edit = WorkflowAction( _edit )
>
> # Override some methods to be sure that Kolloquium objects are
> # reindexed when changed.
> def _setLocalPropValue(self, id, lang, value):
> Kolloquium.inheritedAttribute('_setLocalPropValue')(self, id, lang,
> value)
> self.reindexObject()
>
> # Override setTitle from DefaultDublinCoreImpl and let it do nothin
> # otherwise _editMetadata would call setTitle and override the
> LocalProperty('title')
> def setTitle( self, title ):
> "Dublin Core element - resource name"
> return
>
> --- end snippet ---
>
> I left some things out, like the other properties, which are not
> multilingual and code like manage_afterAdd etc. which seem to have no
> influence here.
>
> The property-edit form looks like this:
>
> <form action="Kolloquium_edit" method="post"
> tal:attributes="action string:${here/absolute_url}/Kolloquium_edit">
> <table class="FormLayout">
> <input type="hidden" name="language" value="de"
> tal:attributes="value request/cookies/LOCALIZER_LANGUAGE">
>
> <tr valign="top">
> <th align="right"> title </th>
> <td colspan="3">
> <input type="text" name="title" value="" size="65"
> tal:attributes="value here/title">
> </td>
> </tr>
> ...
>
> So the problem is, that the title which i defined in my class and
> which uses LocalPropertyManager and is multilingual is overridden by
> the _editMetadata method of DefaultDublinCoreImpl, when the standard
> metadata_edit_form is used or by the
> DefaultDublinCoreImpl.__init__(self).
>
> So i try to override the setTitle method as you can see above. But
> then of course, the title can't be edited in in the
> metadata_edit_form.
>
> I think i also have to override Title(), because it just delivers
> self.title instead of the localized property.
>
> The next step would be to make the metadata multilingual. I think it
> would be necessary to override all methods like Subject, Description,
> etc. from DublinCore.py. Seems to be a lot of work ...
>
> I should provide a language selection box in the metadata_edit_form
> and need to tell setTitle the current language. But can i override the
> method and pass an additional parameter (language) like this:
>
> def setTitle( self, title, language ):
> if title is not None:
> self._setLocalPropValue('title', language, title)
>
> I think this wouldn't override the original function from
> DefaultDublinCoreImpl but create a new one with one more argument to
> pass?!?
--
Florent Guillaume, Nuxeo (Paris, France)
+33 1 40 33 79 87 http://nuxeo.com mailto:fg@nuxeo.com