Ticket #7550 (new Feature Request)

Opened 4 years ago

Last modified 3 years ago

default_method ignored for ReferenceField

Reported by: rochecompaan Owned by:
Priority: major Milestone: Future
Component: Archetypes Keywords:
Cc:

Description

(Moved from http://dev.plone.org/archetypes/ticket/650)

If a 'default_method' is specified for a ReferenceField it is completely ignored. There is no place in the code that actually calls 'getDefault' for ReferenceFields.

Change History

comment:1 Changed 4 years ago by davethewebb

  • Reporter changed from davethewebb to rochecompaan

03/20/06 22:58:43 changed by yenzenz ¶

  • owner set to yenzenz.
  • status changed from new to assigned.
  • milestone set to 1.4.0.

06/17/06 04:04:59 changed by hannosch ¶

  • milestone changed from 1.4.0 to 1.4.x.

comment:2 Changed 4 years ago by hannosch

  • Type changed from Bug to Enhancement
  • Milestone set to Future

comment:3 Changed 4 years ago by jensens

  • Owner yenzenz deleted

comment:4 Changed 3 years ago by ldr

This works for me:

from zope.interface import implements
from AccessControl import ClassSecurityInfo
from Products.CMFCore.utils import getToolByName
from Products.Archetypes.Field import ReferenceField
from Products.Archetypes.interfaces import IObjectField
from Products.Archetypes.config import REFERENCE_CATALOG

class DefaultReferenceField(ReferenceField):

    implements(IObjectField)
    security = ClassSecurityInfo()
    
    security.declarePrivate('getRaw')
    def getRaw(self, instance, aslist=False, **kwargs):
        """Return the list of UIDs referenced under this fields
        relationship.
        
        During creation look for a default value. This will only work for
        user edited forms, not programmatically generated content.
        """
        if instance._at_creation_flag:
            return self.getDefault(instance)
        else:
            return ReferenceField.getRaw(self, instance, aslist, **kwargs)

I can then set a default = ["some uid"] on the field

The DefaultReferenceField from this posting did not work for me:  http://article.gmane.org/gmane.comp.web.zope.plone.archetypes.general/4576

Note: See TracTickets for help on using tickets.