Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Static Private Attributes
Archetypes.Field.ReferenceField Class Reference
Inheritance diagram for Archetypes.Field.ReferenceField:
Inheritance graph
[legend]
Collaboration diagram for Archetypes.Field.ReferenceField:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def get
def set
def getRaw
def Vocabulary
def get_size
def get
def getRaw
def unset
def setStorage
def getStorage
def getStorageName
def getStorageType
def setContentType
def getContentType
def copy
def __repr__
def validate
def validate_validators
def validate_required
def validate_vocabulary
def checkPermission
def writeable
def checkExternalEditor
def getWidgetName
def getName
def getType
def getDefault
def getAccessor
def getEditAccessor
def getMutator
def getIndexAccessor
def getIndexAccessorName
def toString
def isLanguageIndependent
def getI18nDomain

Public Attributes

 storage
 widget
 validators
 index_method

Static Public Attributes

tuple security = ClassSecurityInfo()

Private Member Functions

def _brains_title_or_id
def _Vocabulary

Static Private Attributes

 __implements__ = ObjectField.__implements__
tuple _properties = Field._properties.copy()

Detailed Description

A field for creating references between objects.

get() returns the list of objects referenced under the relationship
set() converts a list of target UIDs into references under the
relationship associated with this field.

If no vocabulary is provided by you, one will be assembled based on
allowed_types.

Definition at line 1635 of file Field.py.


Member Function Documentation

def Archetypes.Field.Field.__repr__ (   self) [inherited]
Return a string representation consisting of name, type and permissions.

Definition at line 236 of file Field.py.

00236 
00237     def __repr__(self):
00238         """
00239         Return a string representation consisting of name, type and permissions.
00240         """
00241         return "<Field %s(%s:%s)>" % (self.getName(), self.type, self.mode)

Here is the call graph for this function:

def Archetypes.Field.ReferenceField._brains_title_or_id (   self,
  brain,
  instance 
) [private]
ensure the brain has a title or an id and return it as unicode

Definition at line 1815 of file Field.py.

01815 
01816     def _brains_title_or_id(self, brain, instance):
01817         """ ensure the brain has a title or an id and return it as unicode"""
01818         title = None
01819         if shasattr(brain, 'getId'):
01820             title = brain.getId
01821         if shasattr(brain, 'Title') and brain.Title != '':
01822             title = brain.Title
01823 
01824         if title is not None and isinstance(title, basestring):
01825             return decode(title, instance)
01826         
01827         raise AttributeError, "Brain has no title or id"

Here is the call graph for this function:

def Archetypes.Field.ReferenceField._Vocabulary (   self,
  content_instance 
) [private]

Definition at line 1828 of file Field.py.

01828 
01829     def _Vocabulary(self, content_instance):
01830         pairs = []
01831         pc = getToolByName(content_instance, 'portal_catalog')
01832         uc = getToolByName(content_instance, config.UID_CATALOG)
01833         purl = getToolByName(content_instance, 'portal_url')
01834 
01835         allowed_types = self.allowed_types
01836         allowed_types_method = getattr(self, 'allowed_types_method', None)
01837         if allowed_types_method:
01838             meth = getattr(content_instance,allowed_types_method)
01839             allowed_types = meth(self)
01840 
01841         skw = allowed_types and {'portal_type':allowed_types} or {}
01842         brains = uc.searchResults(**skw)
01843 
01844         if self.vocabulary_custom_label is not None:
01845             label = lambda b:eval(self.vocabulary_custom_label, {'b': b})
01846         elif self.vocabulary_display_path_bound != -1 and len(brains) > self.vocabulary_display_path_bound:
01847             at = _(u'label_at', default=u'at')
01848             label = lambda b:u'%s %s %s' % (self._brains_title_or_id(b, content_instance),
01849                                              at, b.getPath())
01850         else:
01851             label = lambda b:self._brains_title_or_id(b, content_instance)
01852 
01853         # The UID catalog is the correct catalog to pull this
01854         # information from, however the workflow and perms are not accounted
01855         # for there. We thus check each object in the portal catalog
01856         # to ensure it validity for this user.
01857         portal_base = purl.getPortalPath()
01858         path_offset = len(portal_base) + 1
01859 
01860         abs_paths = {}
01861         abs_path = lambda b, p=portal_base: '%s/%s' % (p, b.getPath())
01862         [abs_paths.update({abs_path(b):b}) for b in brains]
01863 
01864         pc_brains = pc(path=abs_paths.keys(), **skw)
01865 
01866         for b in pc_brains:
01867             b_path = b.getPath()
01868             # translate abs path to rel path since uid_cat stores
01869             # paths relative now
01870             path = b_path[path_offset:]
01871             # The reference field will not expose Refrerences by
01872             # default, this is a complex use-case and makes things too hard to
01873             # understand for normal users. Because of reference class
01874             # we don't know portal type but we can look for the annotation key in
01875             # the path
01876             if self.referenceReferences is False and \
01877                path.find(config.REFERENCE_ANNOTATION) != -1:
01878                 continue
01879 
01880             # now check if the results from the pc is the same as in uc.
01881             # so we verify that b is a result that was also returned by uc,
01882             # hence the check in abs_paths.
01883             if abs_paths.has_key(b_path):
01884                 uid = abs_paths[b_path].UID
01885                 if uid is None:
01886                     # the brain doesn't have an uid because the catalog has a
01887                     # staled object. THAT IS BAD!
01888                     raise ReferenceException("Brain for the object at %s "\
01889                         "doesn't have an UID assigned with. Please update your"\
01890                         " reference catalog!" % b_path)
01891                 pairs.append((uid, label(b)))
01892 
01893         if not self.required and not self.multiValued:
01894             no_reference = _(u'label_no_reference',
01895                              default=u'<no reference>')
01896             pairs.insert(0, ('', no_reference))
01897 
01898         __traceback_info__ = (content_instance, self.getName(), pairs)
01899         return DisplayList(pairs)

Here is the call graph for this function:

def Archetypes.Field.Field.checkExternalEditor (   self,
  instance 
) [inherited]
Checks if the user may edit this field and if
external editor is enabled on this instance 

Definition at line 550 of file Field.py.

00550 
00551     def checkExternalEditor(self, instance):
00552         """ Checks if the user may edit this field and if
00553         external editor is enabled on this instance """
00554 
00555         pp = getToolByName(instance, 'portal_properties')
00556         sp = getattr(pp, 'site_properties', None)
00557         if sp is not None:
00558             if getattr(sp, 'ext_editor', None) \
00559                    and self.checkPermission(mode='edit', instance=instance):
00560                 return True
00561         return None

Here is the call graph for this function:

def Archetypes.Field.Field.checkPermission (   self,
  mode,
  instance 
) [inherited]
Check whether the security context allows the given permission on
the given object.

Arguments:

mode -- 'w' for write or 'r' for read
instance -- The object being accessed according to the permission

Definition at line 507 of file Field.py.

00507 
00508     def checkPermission(self, mode, instance):
00509         """
00510         Check whether the security context allows the given permission on
00511         the given object.
00512 
00513         Arguments:
00514 
00515         mode -- 'w' for write or 'r' for read
00516         instance -- The object being accessed according to the permission
00517         """
00518         if mode in ('w', 'write', 'edit', 'set'):
00519             perm = self.write_permission
00520         elif mode in ('r', 'read', 'view', 'get'):
00521             perm = self.read_permission
00522         else:
00523             return None
00524         return getSecurityManager().checkPermission( perm, instance )
00525 

Here is the caller graph for this function:

def Archetypes.Field.Field.copy (   self,
  name = None 
) [inherited]
Return a copy of field instance, consisting of field name and
properties dictionary. field name can be changed to given name.

Definition at line 220 of file Field.py.

00220 
00221     def copy(self, name=None):
00222         """
00223         Return a copy of field instance, consisting of field name and
00224         properties dictionary. field name can be changed to given name.
00225         """
00226         cdict = dict(vars(self))
00227         cdict.pop('__name__')
00228         # Widget must be copied separatedly
00229         widget = cdict['widget']
00230         del cdict['widget']
00231         properties = deepcopy(cdict)
00232         properties['widget'] = widget.copy()
00233         name = name is not None and name or self.getName()
00234         return self.__class__(name, **properties)
00235 
    

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Field.ObjectField.get (   self,
  instance,
  kwargs 
) [inherited]

Reimplemented in Archetypes.Field.CMFObjectField, Archetypes.Field.BooleanField, Archetypes.Field.FixedPointField, Archetypes.Field.LinesField, Archetypes.Field.FileField, and Archetypes.Field.StringField.

Definition at line 702 of file Field.py.

00702 
00703     def get(self, instance, **kwargs):
00704         __traceback_info__ = (self.getName(), instance, kwargs)
00705         try:
00706             kwargs['field'] = self
00707             return self.getStorage(instance).get(self.getName(), instance, **kwargs)
00708         except AttributeError:
00709             # happens if new Atts are added and not yet stored in the instance
00710             # @@ and at every other possible occurence of an AttributeError?!!
00711             default = self.getDefault(instance)
00712             if not kwargs.get('_initializing_', False):
00713                 self.set(instance, default, _initializing_=True, **kwargs)
00714             return default

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Field.ReferenceField.get (   self,
  instance,
  aslist = False,
  kwargs 
)
get() returns the list of objects referenced under the relationship

Definition at line 1672 of file Field.py.

01672 
01673     def get(self, instance, aslist=False, **kwargs):
01674         """get() returns the list of objects referenced under the relationship
01675         """
01676         res = instance.getRefs(relationship=self.relationship)
01677 
01678         # singlevalued ref fields return only the object, not a list,
01679         # unless explicitely specified by the aslist option
01680    
01681         if not self.multiValued:
01682             if len(res) > 1:
01683                 log("%s references for non multivalued field %s of %s" % (len(res),
01684                                                                           self.getName(),
01685                                                                           instance))
01686             if not aslist:
01687                 if res:
01688                     res = res[0]
01689                 else:
01690                     res = None
01691 
01692         return res

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Field.ReferenceField.get_size (   self,
  instance 
)
Get size of the stored data used for get_size in BaseObject

Reimplemented from Archetypes.Field.ObjectField.

Definition at line 1901 of file Field.py.

01901 
01902     def get_size(self, instance):
01903         """Get size of the stored data used for get_size in BaseObject
01904         """
01905         return 0
01906 

Here is the caller graph for this function:

def Archetypes.Field.Field.getAccessor (   self,
  instance 
) [inherited]
Return the accessor method for getting data out of this
field

Definition at line 602 of file Field.py.

00602 
00603     def getAccessor(self, instance):
00604         """Return the accessor method for getting data out of this
00605         field"""
00606         if self.accessor:
00607             return getattr(instance, self.accessor, None)
00608         return None

Here is the caller graph for this function:

def Archetypes.Field.ObjectField.getContentType (   self,
  instance,
  fromBaseUnit = True 
) [inherited]
Return the mime type of object if known or can be guessed;
otherwise, return default_content_type value or fallback to
'application/octet-stream'.

Reimplemented in Archetypes.Field.FileField.

Definition at line 779 of file Field.py.

00779 
00780     def getContentType(self, instance, fromBaseUnit=True):
00781         """Return the mime type of object if known or can be guessed;
00782         otherwise, return default_content_type value or fallback to
00783         'application/octet-stream'.
00784         """
00785         value = ''
00786         if fromBaseUnit and shasattr(self, 'getBaseUnit'):
00787             bu = self.getBaseUnit(instance)
00788             if IBaseUnit.isImplementedBy(bu):
00789                 return str(bu.getContentType())
00790         raw = self.getRaw(instance)
00791         mimetype = getattr(aq_base(raw), 'mimetype', None)
00792         # some instances like OFS.Image have a getContentType method
00793         if mimetype is None:
00794             getCT = getattr(raw, 'getContentType', None)
00795             if callable(getCT):
00796                 mimetype = getCT()
00797         # try to guess
00798         if mimetype is None:
00799             mimetype, enc = guess_content_type('', str(raw), None)
00800         else:
00801             # mimetype may be an mimetype object
00802             mimetype = str(mimetype)
00803         # failed
00804         if mimetype is None:
00805             mimetype = getattr(self, 'default_content_type',
00806                                'application/octet-stream')
00807         return mimetype

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Field.Field.getDefault (   self,
  instance 
) [inherited]
Return the default value to be used for initializing this
field

Definition at line 579 of file Field.py.

00579 
00580     def getDefault(self, instance):
00581         """Return the default value to be used for initializing this
00582         field"""
00583         dm = self.default_method
00584         if dm:
00585             if isinstance(dm, basestring) and shasattr(instance, dm):
00586                 method = getattr(instance, dm)
00587                 return method()
00588             elif callable(dm):
00589                 return dm()
00590             else:
00591                 raise ValueError('%s.default_method is neither a method of %s'
00592                                  ' nor a callable' % (self.getName(),
00593                                                       instance.__class__))
00594         
00595         if not self.default:
00596             default_adapter = component.queryAdapter(instance, IFieldDefaultProvider, name=self.__name__)
00597             if default_adapter is not None:
00598                 return default_adapter()
00599                 
00600         return self.default

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Field.Field.getEditAccessor (   self,
  instance 
) [inherited]
Return the accessor method for getting raw data out of this
field e.g.: for editing

Definition at line 610 of file Field.py.

00610 
00611     def getEditAccessor(self, instance):
00612         """Return the accessor method for getting raw data out of this
00613         field e.g.: for editing
00614         """
00615         if self.edit_accessor:
00616             return getattr(instance, self.edit_accessor, None)
00617         return None

def Archetypes.Field.Field.getI18nDomain (   self) [inherited]
returns the internationalization domain for translation 

Definition at line 678 of file Field.py.

00678 
00679     def getI18nDomain(self):
00680         """ returns the internationalization domain for translation """
00681         pass
00682 
00683 #InitializeClass(Field)
00684 setSecurity(Field)

def Archetypes.Field.Field.getIndexAccessor (   self,
  instance 
) [inherited]
Return the index accessor, i.e. the getter for an indexable
value.

Reimplemented in Archetypes.Field.FileField.

Definition at line 627 of file Field.py.

00627 
00628     def getIndexAccessor(self, instance):
00629         """Return the index accessor, i.e. the getter for an indexable
00630         value."""
00631         return getattr(instance, self.getIndexAccessorName())

Here is the call graph for this function:

def Archetypes.Field.Field.getIndexAccessorName (   self) [inherited]
Return the index accessor's name defined by the
'index_method' field property.

Definition at line 633 of file Field.py.

00633 
00634     def getIndexAccessorName(self):
00635         """Return the index accessor's name defined by the
00636         'index_method' field property."""
00637         if not hasattr(self, 'index_method'):
00638             return self.accessor
00639         elif self.index_method == '_at_accessor':
00640             return self.accessor
00641         elif self.index_method == '_at_edit_accessor':
00642             return self.edit_accessor or self.accessor
00643 
00644         # If index_method is not a string, we raise ValueError (this
00645         # is actually tested for in test_extensions_utils):
00646         elif not isinstance(self.index_method, (str, unicode)):
00647             raise ValueError("Bad index accessor value : %r"
00648                              % self.index_method)
00649         else:
00650             return self.index_method

Here is the caller graph for this function:

def Archetypes.Field.Field.getMutator (   self,
  instance 
) [inherited]
Return the mutator method used for changing the value
of this field

Definition at line 619 of file Field.py.

00619 
00620     def getMutator(self, instance):
00621         """Return the mutator method used for changing the value
00622         of this field"""
00623         if self.mutator:
00624             return getattr(instance, self.mutator, None)
00625         return None

Here is the caller graph for this function:

def Archetypes.Field.Field.getName (   self) [inherited]
Return the name of this field as a string

Definition at line 569 of file Field.py.

00569 
00570     def getName(self):
00571         """Return the name of this field as a string"""
00572         return self.__name__

def Archetypes.Field.ObjectField.getRaw (   self,
  instance,
  kwargs 
) [inherited]

Reimplemented in Archetypes.Field.BooleanField, and Archetypes.Field.LinesField.

Definition at line 716 of file Field.py.

00716 
00717     def getRaw(self, instance, **kwargs):
00718         if self.accessor is not None:
00719             accessor = self.getAccessor(instance)
00720         else:
00721             # self.accessor is None for fields wrapped by an I18NMixIn
00722             accessor = None
00723         kwargs.update({'field': self,
00724                        'encoding':kwargs.get('encoding', None),
00725                      })
00726         if accessor is None:
00727             args = [instance,]
00728             return mapply(self.get, *args, **kwargs)
00729         return mapply(accessor, **kwargs)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Field.ReferenceField.getRaw (   self,
  instance,
  aslist = False,
  kwargs 
)
Return the list of UIDs referenced under this fields
relationship

Definition at line 1792 of file Field.py.

01792 
01793     def getRaw(self, instance, aslist=False, **kwargs):
01794         """Return the list of UIDs referenced under this fields
01795         relationship
01796         """
01797         rc = getToolByName(instance, REFERENCE_CATALOG)
01798         brains = rc(sourceUID=instance.UID(),
01799                     relationship=self.relationship)
01800         res = [b.targetUID for b in brains]
01801         if not self.multiValued and not aslist:
01802             if res:
01803                 res = res[0]
01804             else:
01805                 res = None
01806         return res

Here is the call graph for this function:

def Archetypes.Field.ObjectField.getStorage (   self,
  instance = None 
) [inherited]

Definition at line 758 of file Field.py.

00758 
00759     def getStorage(self, instance=None):
00760         return self.storage

Here is the caller graph for this function:

def Archetypes.Field.ObjectField.getStorageName (   self,
  instance = None 
) [inherited]
Return the storage name that is configured for this field
as a string

Definition at line 762 of file Field.py.

00762 
00763     def getStorageName(self, instance=None):
00764         """Return the storage name that is configured for this field
00765         as a string"""
00766         return self.getStorage(instance).getName()

Here is the call graph for this function:

def Archetypes.Field.ObjectField.getStorageType (   self,
  instance = None 
) [inherited]
Return the type of the storage of this field as a string

Definition at line 768 of file Field.py.

00768 
00769     def getStorageType(self, instance=None):
00770         """Return the type of the storage of this field as a string"""
00771         return className(self.getStorage(instance))

Here is the call graph for this function:

def Archetypes.Field.Field.getType (   self) [inherited]
Return the type of this field as a string

Definition at line 574 of file Field.py.

00574 
00575     def getType(self):
00576         """Return the type of this field as a string"""
00577         return className(self)

Here is the call graph for this function:

def Archetypes.Field.Field.getWidgetName (   self) [inherited]
Return the widget name that is configured for this field as
a string

Definition at line 563 of file Field.py.

00563 
00564     def getWidgetName(self):
00565         """Return the widget name that is configured for this field as
00566         a string"""
00567         return self.widget.getName()

def Archetypes.Field.Field.isLanguageIndependent (   self,
  instance 
) [inherited]
Get the language independed flag for i18n content

Definition at line 672 of file Field.py.

00672 
00673     def isLanguageIndependent(self, instance):
00674         """Get the language independed flag for i18n content
00675         """
00676         return self.languageIndependent

def Archetypes.Field.ReferenceField.set (   self,
  instance,
  value,
  kwargs 
)
Mutator.

``value`` is a either a list of UIDs or one UID string, or a
list of objects or one object to which I will add a reference
to. None and [] are equal.

>>> for node in range(3):
...     _ = self.folder.invokeFactory('Refnode', 'n%s' % node)

Use set with a list of objects:

>>> nodes = self.folder.n0, self.folder.n1, self.folder.n2
>>> nodes[0].setLinks(nodes[1:])
>>> nodes[0].getLinks()
[<Refnode...>, <Refnode...>]

Use it with None or () to delete references:

>>> nodes[0].setLinks(None)
>>> nodes[0].getLinks()
[]

Use a list of UIDs to set:

>>> nodes[0].setLinks([n.UID() for n in nodes[1:]])
>>> nodes[0].getLinks()
[<Refnode...>, <Refnode...>]
>>> nodes[0].setLinks(())
>>> nodes[0].getLinks()
[]

Setting multiple values for a non multivalued field will fail:

>>> nodes[1].setLink(nodes)
Traceback (most recent call last):
...
ValueError: Multiple values ...

Keyword arguments may be passed directly to addReference(),
thereby creating properties on the reference objects:

>>> nodes[1].setLink(nodes[0].UID(), foo='bar', spam=1)
>>> ref = nodes[1].getReferenceImpl()[0]
>>> ref.foo, ref.spam
('bar', 1)

Empty BTreeFolders work as values (#1212048):

>>> _ = self.folder.invokeFactory('SimpleBTreeFolder', 'btf')
>>> nodes[2].setLink(self.folder.btf)
>>> nodes[2].getLink()
<SimpleBTreeFolder...>

Reimplemented from Archetypes.Field.ObjectField.

Definition at line 1694 of file Field.py.

01694 
01695     def set(self, instance, value, **kwargs):
01696         """Mutator.
01697 
01698         ``value`` is a either a list of UIDs or one UID string, or a
01699         list of objects or one object to which I will add a reference
01700         to. None and [] are equal.
01701 
01702         >>> for node in range(3):
01703         ...     _ = self.folder.invokeFactory('Refnode', 'n%s' % node)
01704 
01705         Use set with a list of objects:
01706 
01707         >>> nodes = self.folder.n0, self.folder.n1, self.folder.n2
01708         >>> nodes[0].setLinks(nodes[1:])
01709         >>> nodes[0].getLinks()
01710         [<Refnode...>, <Refnode...>]
01711 
01712         Use it with None or () to delete references:
01713 
01714         >>> nodes[0].setLinks(None)
01715         >>> nodes[0].getLinks()
01716         []
01717 
01718         Use a list of UIDs to set:
01719         
01720         >>> nodes[0].setLinks([n.UID() for n in nodes[1:]])
01721         >>> nodes[0].getLinks()
01722         [<Refnode...>, <Refnode...>]
01723         >>> nodes[0].setLinks(())
01724         >>> nodes[0].getLinks()
01725         []
01726 
01727         Setting multiple values for a non multivalued field will fail:
01728         
01729         >>> nodes[1].setLink(nodes)
01730         Traceback (most recent call last):
01731         ...
01732         ValueError: Multiple values ...
01733 
01734         Keyword arguments may be passed directly to addReference(),
01735         thereby creating properties on the reference objects:
01736         
01737         >>> nodes[1].setLink(nodes[0].UID(), foo='bar', spam=1)
01738         >>> ref = nodes[1].getReferenceImpl()[0]
01739         >>> ref.foo, ref.spam
01740         ('bar', 1)
01741 
01742         Empty BTreeFolders work as values (#1212048):
01743 
01744         >>> _ = self.folder.invokeFactory('SimpleBTreeFolder', 'btf')
01745         >>> nodes[2].setLink(self.folder.btf)
01746         >>> nodes[2].getLink()
01747         <SimpleBTreeFolder...>
01748         """
01749         tool = getToolByName(instance, REFERENCE_CATALOG)
01750         targetUIDs = [ref.targetUID for ref in
01751                       tool.getReferences(instance, self.relationship)]
01752 
01753         if value is None:
01754             value = ()
01755 
01756         if not isinstance(value, (ListType, TupleType)):
01757             value = value,
01758         elif not self.multiValued and len(value) > 1:
01759             raise ValueError, \
01760                   "Multiple values given for single valued field %r" % self
01761 
01762         #convert objects to uids if necessary
01763         uids = []
01764         for v in value:
01765             if type(v) in STRING_TYPES:
01766                 uids.append(v)
01767             else:
01768                 uids.append(v.UID())
01769 
01770         add = [v for v in uids if v and v not in targetUIDs]
01771         sub = [t for t in targetUIDs if t not in uids]
01772 
01773         # tweak keyword arguments for addReference
01774         addRef_kw = kwargs.copy()
01775         addRef_kw.setdefault('referenceClass', self.referenceClass)
01776         if addRef_kw.has_key('schema'): del addRef_kw['schema']
01777 
01778         for uid in add:
01779             __traceback_info__ = (instance, uid, value, targetUIDs)
01780             # throws IndexError if uid is invalid
01781             tool.addReference(instance, uid, self.relationship, **addRef_kw)
01782 
01783         for uid in sub:
01784             tool.deleteReference(instance, uid, self.relationship)
01785 
01786         if self.callStorageOnSet:
01787             #if this option is set the reference fields's values get written
01788             #to the storage even if the reference field never use the storage
01789             #e.g. if i want to store the reference UIDs into an SQL field
01790             ObjectField.set(self, instance, self.getRaw(instance), **kwargs)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Field.ObjectField.setContentType (   self,
  instance,
  value 
) [inherited]
Set mimetype in the base unit.

Reimplemented in Archetypes.Field.TextField, and Archetypes.Field.FileField.

Definition at line 773 of file Field.py.

00773 
00774     def setContentType(self, instance, value):
00775         """Set mimetype in the base unit.
00776         """
00777         pass

Here is the caller graph for this function:

def Archetypes.Field.ObjectField.setStorage (   self,
  instance,
  storage 
) [inherited]

Definition at line 746 of file Field.py.

00746 
00747     def setStorage(self, instance, storage):
00748         if not IStorage.isImplementedBy(storage):
00749             raise ObjectFieldException, "Not a valid Storage method"
00750         # raw=1 is required for TextField
00751         value = self.get(instance, raw=True)
00752         self.unset(instance)
00753         self.storage = storage
00754         if shasattr(self.storage, 'initializeInstance'):
00755             self.storage.initializeInstance(instance)
00756         self.set(instance, value)

Here is the call graph for this function:

def Archetypes.Field.Field.toString (   self) [inherited]
Utility method for converting a Field to a string for the
purpose of comparing fields.  This comparison is used for
determining whether a schema has changed in the auto update
function. Right now it's pretty crude.

Definition at line 652 of file Field.py.

00652 
00653     def toString(self):
00654         """Utility method for converting a Field to a string for the
00655         purpose of comparing fields.  This comparison is used for
00656         determining whether a schema has changed in the auto update
00657         function. Right now it's pretty crude."""
00658         # TODO fixme
00659         s = '%s(%s): {' % ( self.__class__.__name__, self.__name__ )
00660         sorted_keys = self._properties.keys()
00661         sorted_keys.sort()
00662         for k in sorted_keys:
00663             value = getattr( self, k, self._properties[k] )
00664             if k == 'widget':
00665                 value = value.__class__.__name__
00666             if type(value) is UnicodeType:
00667                 value = value.encode('utf-8')
00668             s = s + '%s:%s,' % (k, value )
00669         s = s + '}'
00670         return s

Here is the caller graph for this function:

def Archetypes.Field.ObjectField.unset (   self,
  instance,
  kwargs 
) [inherited]

Definition at line 740 of file Field.py.

00740 
00741     def unset(self, instance, **kwargs):
00742         #kwargs['field'] = self
00743         __traceback_info__ = (self.getName(), instance, kwargs)
00744         self.getStorage(instance).unset(self.getName(), instance, **kwargs)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Field.Field.validate (   self,
  value,
  instance,
  errors = None,
  kwargs 
) [inherited]
Validate passed-in value using all field validators.
Return None if all validations pass; otherwise, return failed
result returned by validator

Definition at line 299 of file Field.py.

00299 
00300     def validate(self, value, instance, errors=None, **kwargs):
00301         """
00302         Validate passed-in value using all field validators.
00303         Return None if all validations pass; otherwise, return failed
00304         result returned by validator
00305         """
00306         if errors is None:
00307             errors = {}
00308         name = self.getName()
00309         if errors and errors.has_key(name):
00310             return True
00311 
00312         if self.required:
00313             res = self.validate_required(instance, value, errors)
00314             if res is not None:
00315                 return res
00316 
00317         if self.enforceVocabulary:
00318             res = self.validate_vocabulary(instance, value, errors)
00319             if res is not None:
00320                 return res
00321 
00322         res = instance.validate_field(name, value, errors)
00323         if res is not None:
00324             return res
00325 
00326         if self.validators:
00327             res = self.validate_validators(value, instance, errors, **kwargs)
00328             if res is not True:
00329                 return res
00330 
00331         # all ok
00332         return None

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Field.Field.validate_required (   self,
  instance,
  value,
  errors 
) [inherited]

Reimplemented in Archetypes.Field.PhotoField, Archetypes.Field.FixedPointField, Archetypes.Field.FloatField, Archetypes.Field.IntegerField, Archetypes.Field.DateTimeField, and Archetypes.Field.FileField.

Definition at line 347 of file Field.py.

00347 
00348     def validate_required(self, instance, value, errors):
00349         if not value:
00350             request = aq_get(instance, 'REQUEST')
00351             label = self.widget.Label(instance)
00352             name = self.getName()
00353             if isinstance(label, Message):
00354                 label = translate(label, context=request)
00355             error = _(u'error_required',
00356                       default=u'${name} is required, please correct.',
00357                       mapping={'name': label})
00358             error = translate(error, context=request)
00359             errors[name] = error
00360             return error
00361         return None

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Field.Field.validate_validators (   self,
  value,
  instance,
  errors,
  kwargs 
) [inherited]

Definition at line 334 of file Field.py.

00334 
00335     def validate_validators(self, value, instance, errors, **kwargs):
00336         """
00337         """
00338         if self.validators:
00339             result = self.validators(value, instance=instance, errors=errors,
00340                                      field=self, **kwargs)
00341         else:
00342             result = True
00343 
00344         if result is not True:
00345             return result

Here is the caller graph for this function:

def Archetypes.Field.Field.validate_vocabulary (   self,
  instance,
  value,
  errors 
) [inherited]
Make sure value is inside the allowed values
for a given vocabulary

Definition at line 363 of file Field.py.

00363 
00364     def validate_vocabulary(self, instance, value, errors):
00365         """Make sure value is inside the allowed values
00366         for a given vocabulary"""
00367         badvalues = []
00368         if value:
00369             # coerce value into a list called values
00370             values = value
00371             if type(value) in STRING_TYPES:
00372                 values = [value]
00373             elif type(value) == BooleanType:
00374                 values = [str(value)]
00375             elif type(value) not in (TupleType, ListType):
00376                 raise TypeError("Field value type error: %s" % type(value))
00377             vocab = self.Vocabulary(instance)
00378             # filter empty
00379             values = [instance.unicodeEncode(v)
00380                       for v in values if v.strip()]
00381             # extract valid values from vocabulary
00382             valids = []
00383             for v in vocab:
00384                 if type(v) in (TupleType, ListType):
00385                     v = v[0]
00386                 if not type(v) in STRING_TYPES:
00387                     v = str(v)
00388                 valids.append(instance.unicodeEncode(v))
00389             # check field values
00390             badvalues = [val for val in values if not val in valids]
00391 
00392         error = None
00393         if badvalues:
00394             request = aq_get(instance, 'REQUEST')
00395             label = self.widget.Label(instance)
00396             if isinstance(label, Message):
00397                 label = translate(label, context=request)
00398             if isinstance(val, Message):
00399                 val = translate(val, context=request)
00400             error = _( u'error_vocabulary',
00401                 default=u'Values ${val} is not allowed for vocabulary of element ${label}.',
00402                 mapping={'val': unicode(badvalues), 'name': label})
00403             error = translate(error, context=request)
00404             errors[self.getName()] = error
00405         return error

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Field.ReferenceField.Vocabulary (   self,
  content_instance = None 
)
Use vocabulary property if it's been defined.

Reimplemented from Archetypes.Field.Field.

Definition at line 1808 of file Field.py.

01808 
01809     def Vocabulary(self, content_instance=None):
01810         """Use vocabulary property if it's been defined."""
01811         if self.vocabulary or getattr(self, 'vocabulary_factory', None):
01812             return ObjectField.Vocabulary(self, content_instance)
01813         else:
01814             return self._Vocabulary(content_instance).sortedByValue()

Here is the call graph for this function:

def Archetypes.Field.Field.writeable (   self,
  instance,
  debug = False 
) [inherited]

Definition at line 527 of file Field.py.

00527 
00528     def writeable(self, instance, debug=False):
00529         if 'w' not in self.mode:
00530             if debug:
00531                 log("Tried to update %s:%s but field is not writeable." % \
00532                     (instance.portal_type, self.getName()))
00533             return False
00534 
00535         method = self.getMutator(instance)
00536         if not method:
00537             if debug:
00538                 log("No method %s on %s." % (self.mutator, instance))
00539             return False
00540 
00541         if not self.checkPermission('edit', instance):
00542             if debug:
00543                 log("User %s tried to update %s:%s but "
00544                     "doesn't have enough permissions." %
00545                     (_getAuthenticatedUser(instance).getId(),
00546                      instance.portal_type, self.getName()))
00547             return False
00548         return True

Here is the call graph for this function:


Member Data Documentation

Reimplemented from Archetypes.Field.ObjectField.

Definition at line 1646 of file Field.py.

tuple Archetypes.Field.ReferenceField._properties = Field._properties.copy() [static, private]

Reimplemented from Archetypes.Field.ObjectField.

Definition at line 1648 of file Field.py.

Definition at line 638 of file Field.py.

tuple Archetypes.Field.ReferenceField.security = ClassSecurityInfo() [static]

Reimplemented from Archetypes.Field.ObjectField.

Definition at line 1669 of file Field.py.

Definition at line 752 of file Field.py.

Definition at line 296 of file Field.py.

Definition at line 249 of file Field.py.


The documentation for this class was generated from the following file: