On 05/20/2015 11:07 AM, Jo G wrote:
> I have created a new content_type called Person (based on persistent). I
> want to make the name used for traversal unique and non editable by the
> admin users so for now I was going to use the OID assigned to my person
> object. Trouble is I can't see where the oid is set so I can't workout
> where to set name using set_oid.
The '__oid__' is normally set by the "object map" when the content object
is being added to it: at that point, the object must already be "seated"
in its folder, and therefore must have its initial '__name__' already assigned.
Generally, the OID is an implementation detail of the map, and probably
shouldn't be exposed to the user (even via the URL).
> I know it is set because a dump of the database shows me an OID. Where does
> this happen?
>
> Is it possible to set the name to be the OID?
>
> I will also want to do the same with other content types (eg personalname)
> which are created when person is created.
>
> I am new to python and dynamic languages so I may be barking up the wrong
> tree, if so please tell me!
For your usecase, I would likely use a different container than the
standard 'substanced.folder.Folder'. E.g., the
'substanced.folder.AutoNamingFolder' type generates random IDs for its
sub-objects. If you then want to prohibit renames, you would need to
derive from it and override the 'rename' or 'move' methods (inherited from
'substanced.folder.Folder').
Rather than overriding those methods, another option would be to add a
subscriber for the 'substanced.events.IObjectWillBeRemoved' event and block
removal if its 'moving' flag is True. E.g.:
from substanced.events import subscribe_will_be_removed
@subscribe_will_be_removed(Person)
def person_will_be_removed(event):
if event.moving:
raise ValueError('cannot move/rename Person')
Tres.
--
===================================================================
Tres Seaver
+1 540-429-0999 tse...@palladion.com
Palladion Software "Excellence by Design"
http://palladion.com