Back to index

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

List of all members.

Public Member Functions

def lookupDestinationsFor
def addableTypes
def getName
def getType
def bootstrap
def populateProps
def isVisible
def setCondition
def getCondition
def testCondition
def process_form
def copy

Public Attributes

 label
 condition

Static Public Attributes

tuple security = ClassSecurityInfo()

Static Private Attributes

tuple _properties = TypesWidget._properties.copy()

Detailed Description

Definition at line 177 of file Widget.py.


Member Function Documentation

def Archetypes.Widget.ReferenceWidget.addableTypes (   self,
  instance,
  field 
)
Returns a list of dictionaries which maps portal_type
    to a human readable form.

Definition at line 233 of file Widget.py.

00233 
00234     def addableTypes(self, instance, field):
00235         """ Returns a list of dictionaries which maps portal_type
00236             to a human readable form.
00237         """
00238         tool = getToolByName(instance, 'portal_types')
00239         purl = getToolByName(instance, 'portal_url')
00240 
00241         lookupDestinationsFor = self.lookupDestinationsFor
00242         getRelativeContentURL = purl.getRelativeContentURL
00243 
00244         # if destination_types is None (by default) it will do
00245         # N-portal_types queries to the catalog which is horribly inefficient
00246 
00247         destination_types = getattr(self, 'destination_types', None)
00248         destination = self.destination
00249         types = []
00250 
00251         options = {}
00252         for typeid in field.allowed_types:
00253             _info = tool.getTypeInfo(typeid)
00254             if _info is None:
00255                 # The portal_type asked for was not
00256                 # installed/has been removed.
00257                 log("Warning: in Archetypes.Widget.lookupDestinationsFor: " \
00258                     "portal type %s not found" % typeid )
00259                 continue
00260 
00261             if destination == None:
00262                 options[typeid]=[None]
00263             elif isinstance(destination, DictType):
00264                 options[typeid]=destination.get(typeid, [None])
00265                 if not isinstance(options[typeid], ListType):
00266                     options[typeid] = [options[typeid]]
00267             elif isinstance(destination, ListType):
00268                 options[typeid]=destination
00269             else:
00270                 place = getattr(aq_base(instance), destination, destination)
00271                 if callable(place):
00272                     #restore acq.wrapper
00273                     place = getattr(instance, destination)
00274                     place = place()
00275                 if isinstance(place, ListType):
00276                     options[typeid] = place
00277                 else:
00278                     options[typeid] = [place]
00279 
00280             value = {}
00281             value['id'] = typeid
00282             value['name'] = _info.Title()
00283             value['destinations'] = []
00284 
00285             for option in options.get(typeid):
00286                 if option == None:
00287                     value['destinations'] = value['destinations'] + \
00288                         lookupDestinationsFor(_info, tool, purl,
00289                                           destination_types=destination_types)
00290                 elif option == '.':
00291                     value['destinations'].append(getRelativeContentURL(instance))
00292                 else:
00293                     try:
00294                         place = getattr(aq_base(instance), option, option)
00295                     except TypeError:
00296                         place = option
00297                     if callable(place):
00298                         #restore acq.wrapper
00299                         place = getattr(instance, option)
00300                         place = place()
00301                     if isinstance(place, ListType):
00302                         value['destinations'] = place + value['destinations']
00303                     else:
00304                         #TODO Might as well check for type, doing it everywhere else
00305                         value['destinations'].append(place)
00306 
00307             if value['destinations']:
00308                 types.append(value)
00309 
00310         return types

Here is the call graph for this function:

def Archetypes.Widget.TypesWidget.bootstrap (   self,
  instance 
) [inherited]
Override if your widget needs data from the instance.

Definition at line 49 of file Widget.py.

00049 
00050     def bootstrap(self, instance):
00051         """Override if your widget needs data from the instance."""
00052         return

def Archetypes.Widget.TypesWidget.copy (   self) [inherited]
Return a copy of widget instance, consisting of field name and
properties dictionary.

Definition at line 130 of file Widget.py.

00130 
00131     def copy(self):
00132         """
00133         Return a copy of widget instance, consisting of field name and
00134         properties dictionary.
00135         """
00136         cdict = dict(vars(self))
00137         properties = deepcopy(cdict)
00138         return self.__class__(**properties)
00139 
00140 InitializeClass(TypesWidget)

Here is the call graph for this function:

def Archetypes.Widget.TypesWidget.getCondition (   self) [inherited]
Return the widget text condition.

Definition at line 101 of file Widget.py.

00101 
00102     def getCondition(self):
00103         """Return the widget text condition."""
00104         return self.condition

def Archetypes.Widget.TypesWidget.getName (   self) [inherited]

Definition at line 40 of file Widget.py.

00040 
00041     def getName(self):
00042         return self.__class__.__name__

Here is the caller graph for this function:

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

Definition at line 44 of file Widget.py.

00044 
00045     def getType(self):
00046         """Return the type of this field as a string"""
00047         return className(self)

Here is the call graph for this function:

def Archetypes.Widget.TypesWidget.isVisible (   self,
  instance,
  mode = 'view' 
) [inherited]
decide if a field is visible in a given mode -> 'state'

Return values are visible, hidden, invisible

The value for the attribute on the field may either be a dict with a
mapping for edit and view::

    visible = { 'edit' :'hidden', 'view' : 'invisible' }

Or a single value for all modes::

    True/1:  'visible'
    False/0: 'invisible'
    -1:      'hidden'
    
visible: The field is shown in the view/edit screen
invisible: The field is skipped when rendering the view/edit screen
hidden: The field is added as <input type="hidden" />

The default state is 'visible'.

Definition at line 61 of file Widget.py.

00061 
00062     def isVisible(self, instance, mode='view'):
00063         """decide if a field is visible in a given mode -> 'state'
00064 
00065         Return values are visible, hidden, invisible
00066 
00067         The value for the attribute on the field may either be a dict with a
00068         mapping for edit and view::
00069 
00070             visible = { 'edit' :'hidden', 'view' : 'invisible' }
00071 
00072         Or a single value for all modes::
00073 
00074             True/1:  'visible'
00075             False/0: 'invisible'
00076             -1:      'hidden'
00077             
00078         visible: The field is shown in the view/edit screen
00079         invisible: The field is skipped when rendering the view/edit screen
00080         hidden: The field is added as <input type="hidden" />
00081 
00082         The default state is 'visible'.
00083         """
00084         vis_dic = getattr(aq_base(self), 'visible', _marker)
00085         state = 'visible'
00086         if vis_dic is _marker:
00087             return state
00088         if type(vis_dic) is DictType:
00089             state = vis_dic.get(mode, state)
00090         elif not vis_dic:
00091             state = 'invisible'
00092         elif vis_dic < 0:
00093             state = 'hidden'
00094         return state

def Archetypes.Widget.ReferenceWidget.lookupDestinationsFor (   self,
  typeinfo,
  tool,
  purl,
  destination_types = None 
)
search where the user can add a typeid instance

Definition at line 201 of file Widget.py.

00201 
00202     def lookupDestinationsFor(self, typeinfo, tool, purl, destination_types=None):
00203         """
00204         search where the user can add a typeid instance
00205         """
00206         searchFor = []
00207 
00208         # first, discover who can contain the type
00209         if destination_types is not None:
00210             if type(destination_types) in (type(()), type([])):
00211                 searchFor += list(destination_types[:])
00212             else:
00213                 searchFor.append(destination_types)
00214         else:
00215             for regType in tool.listTypeInfo():
00216                 if typeinfo.globalAllow():
00217                     searchFor.append(regType.getId())
00218                 elif regType.filter_content_types and regType.allowed_content_types:
00219                     act_dict = dict([ (act, 0) for act in regType.allowed_content_types ])
00220                     if act_dict.has_key(typeinfo.getId()):
00221                         searchFor.append(regType.getId())
00222 
00223         catalog = getToolByName(purl, 'portal_catalog')
00224         containers = []
00225         portal_path = "/".join(purl.getPortalObject().getPhysicalPath())
00226         for wanted in searchFor:
00227             for brain in catalog(portal_type=wanted):
00228                 relative_path = brain.getPath().replace(portal_path + '/', '')
00229                 containers.append(relative_path)
00230 
00231         return containers

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Widget.TypesWidget.populateProps (   self,
  field 
) [inherited]
This is called when the field is created.

Definition at line 54 of file Widget.py.

00054 
00055     def populateProps(self, field):
00056         """This is called when the field is created."""
00057         name = field.getName()
00058         if not self.label:
00059             self.label = capitalize(name)

def Archetypes.Widget.TypesWidget.process_form (   self,
  instance,
  field,
  form,
  empty_marker = None,
  emptyReturnsMarker = False,
  validating = True 
) [inherited]
Basic impl for form processing in a widget

Reimplemented in Archetypes.Widget.ImageWidget, Archetypes.Widget.RequiredIdWidget, Archetypes.Widget.IdWidget, Archetypes.Widget.RichWidget, Archetypes.Widget.FileWidget, Archetypes.Widget.KeywordWidget, Archetypes.Widget.MultiSelectionWidget, Archetypes.Widget.CalendarWidget, and Archetypes.Widget.TextAreaWidget.

Definition at line 120 of file Widget.py.

00120 
00121                      emptyReturnsMarker=False, validating=True):
00122         """Basic impl for form processing in a widget"""
00123         value = form.get(field.getName(), empty_marker)
00124         if value is empty_marker:
00125             return empty_marker
00126         if emptyReturnsMarker and value == '':
00127             return empty_marker
00128         return value, {}

Here is the caller graph for this function:

def Archetypes.Widget.TypesWidget.setCondition (   self,
  condition 
) [inherited]
Set the widget expression condition.

Definition at line 96 of file Widget.py.

00096 
00097     def setCondition(self, condition):
00098         """Set the widget expression condition."""
00099         self.condition = condition

def Archetypes.Widget.TypesWidget.testCondition (   self,
  folder,
  portal,
  object 
) [inherited]
Test the widget condition.

Definition at line 106 of file Widget.py.

00106 
00107     def testCondition(self, folder, portal, object):
00108         """Test the widget condition."""
00109         try:
00110             if self.condition:
00111                 __traceback_info__ = (folder, portal, object, self.condition)
00112                 ec = createExprContext(folder, portal, object)
00113                 return Expression(self.condition)(ec)
00114             else:
00115                 return True
00116         except AttributeError:
00117             return True

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

tuple Archetypes.Widget.ReferenceWidget._properties = TypesWidget._properties.copy() [static, private]

Reimplemented from Archetypes.Widget.TypesWidget.

Reimplemented in Archetypes.Widget.InAndOutWidget.

Definition at line 178 of file Widget.py.

Definition at line 98 of file Widget.py.

Definition at line 58 of file Widget.py.

tuple Archetypes.Widget.ReferenceWidget.security = ClassSecurityInfo() [static]

Reimplemented from Archetypes.Widget.TypesWidget.

Reimplemented in Archetypes.Widget.InAndOutWidget.

Definition at line 199 of file Widget.py.


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