Default names

30 views
Skip to first unread message

Charlie Clark

unread,
Mar 18, 2016, 8:06:29 AM3/18/16
to substanc...@googlegroups.com
Hiya,

when creating and AddView based on FormView it seems it's essential to
have a `name` field. What's the best way to set this up if you don't want
these to be assigned by the user? Ideally, I'd like to have the context's
class name used as default and incremented but it seems like the validator
always expect a non-empty value.

Is the best way to use an AutoNamingFolder? If so, what's the best way to
hook this up as the default folder type?

Charlie
--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Kronenstr. 27a
Düsseldorf
D- 40217
Tel: +49-211-600-3657
Mobile: +49-178-782-6226

Carlos de la Guardia

unread,
Mar 19, 2016, 2:54:55 AM3/19/16
to substanc...@googlegroups.com
Hi,

yes, the best way to not allow the user to assign names is to use an IAutoNamingFolder. It's very easy to hook one up as the default folder type. For the substanced scaffold, simply add this at the top of resources.py:

@content(
    'Folder',
    icon='glyphicon glyphicon-folder-close',
    add_view='add_folder',
)
@implementer(IFolder)
class MyFolder(SequentialAutoNamingFolder):
    """ Override Folder content type """

This will override the folder content type and use the SequentialAutoNamingFolder. To have the name begin with the content type, you would need to subclass this one.

To make this work with the document example in the scaffold, remove the name field from the DocumentSchema and change the add_success method in views.py to:

    def add_success(self, appstruct):
        registry = self.request.registry
        document = registry.content.create('Document', **appstruct)
        self.context.add_next(document)
        return HTTPFound(
            self.request.sdiapi.mgmt_path(self.context, '@@contents')
            )

That's all you need.

Carlos de la Guardia



From: Charlie Clark <charli...@clark-consulting.eu>
To: substanc...@googlegroups.com
Sent: Friday, March 18, 2016 6:06 AM
Subject: Default names
--
You received this message because you are subscribed to the Google Groups "substanced-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to substanced-users+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Charlie Clark

unread,
Mar 19, 2016, 8:52:05 AM3/19/16
to substanc...@googlegroups.com
Am .03.2016, 07:53 Uhr, schrieb 'Carlos de la Guardia' via
substanced-users <substanc...@googlegroups.com>:
Hi Carlos,

Google played merry hell with the formatting but I thought it would be
something like that. I see that a similar question came up recently so
I'll add this to the docs.

Jo G

unread,
Apr 13, 2016, 5:33:12 AM4/13/16
to substanced-users
I didn't use the autonaming folder  but I made the name property a hidden widget. I then updated the value in name field when I created the folder (in the add_success method) and where necessary if the properties were changed by overriding the set method of PropertySheet. I needed to do this as my name was a combination of the other fieldds. So for example, my person object name was a unique string which combines name,gender, birth and death.

   
 name = NameSchemaNode(
           editing=context_is_a_person,
           title=AGENT_CONFIG['PERSON_WIDGET_NAME_TITLE'],
           widget=deform.widget.HiddenWidget(),
           default=AGENT_CONFIG['NAME_WIDGET_NAME_DEFAULT']
           )
Reply all
Reply to author
Forward
0 new messages