Back to index

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

List of all members.

Public Member Functions

def __init__
def getValue
def __repr__
def __str__
def __call__
def fromList
def __len__
def __add__
def index_sort
def add
def getKey
def getMsgId
def keys
def values
def items
def sortedByValue
def sortedByKey
def __cmp__
def __getitem__
def __getslice__

Public Attributes

 index

Static Public Attributes

tuple security = ClassSecurityInfo()

Private Attributes

 _keys
 _i18n_msgids
 _values
 _itor
 _instance
 _i18n_domain

Detailed Description

Wrap DisplayList class and add internationalisation

Definition at line 616 of file utils.py.


Constructor & Destructor Documentation

def Archetypes.utils.Vocabulary.__init__ (   self,
  display_list,
  instance,
  i18n_domain 
)

Definition at line 624 of file utils.py.

00624 
00625     def __init__(self, display_list, instance, i18n_domain):
00626         self._keys = display_list._keys
00627         self._i18n_msgids = display_list._i18n_msgids
00628         self._values = display_list._values
00629         self._itor   = display_list._itor
00630         self.index = display_list.index
00631         self._instance = instance
00632         self._i18n_domain = i18n_domain


Member Function Documentation

def Archetypes.utils.DisplayList.__add__ (   self,
  other 
) [inherited]

Definition at line 363 of file utils.py.

00363 
00364     def __add__(self, other):
00365         a = tuple(self.items())
00366         if hasattr(other, 'items'):
00367             b = other.items()
00368         else: #assume a seq
00369             b = tuple(zip(other, other))
00370 
00371         msgids = self._i18n_msgids
00372         msgids.update(getattr(other, '_i18n_msgids', {}))
00373 
00374         v = DisplayList(a + b)
00375         v._i18n_msgids = msgids
00376         return v

Here is the call graph for this function:

def Archetypes.utils.DisplayList.__call__ (   self) [inherited]

Definition at line 351 of file utils.py.

00351 
00352     def __call__(self):
00353         return self

Here is the caller graph for this function:

def Archetypes.utils.DisplayList.__cmp__ (   self,
  dest 
) [inherited]

Definition at line 475 of file utils.py.

00475 
00476     def __cmp__(self, dest):
00477         if not isinstance(dest, DisplayList):
00478             raise TypeError, 'Cant compare DisplayList to %s' % (type(dest))
00479 
00480         return cmp(self.sortedByKey()[:], dest.sortedByKey()[:])

Here is the call graph for this function:

def Archetypes.utils.DisplayList.__getitem__ (   self,
  key 
) [inherited]

Definition at line 481 of file utils.py.

00481 
00482     def __getitem__(self, key):
00483         #Ok, this is going to pass a number
00484         #which is index but not easy to get at
00485         #with the data-struct, fix when we get real
00486         #itor/generators
00487         return self._itor[key]

Here is the caller graph for this function:

def Archetypes.utils.DisplayList.__getslice__ (   self,
  i1,
  i2 
) [inherited]

Definition at line 488 of file utils.py.

00488 
00489     def __getslice__(self,i1,i2):
00490         r=[]
00491         for i in xrange(i1,i2):
00492             try: r.append((self._itor[i], self.getValue(self._itor[i]),))
00493             except IndexError: return r
00494         return DisplayList(r)

Here is the call graph for this function:

def Archetypes.utils.DisplayList.__len__ (   self) [inherited]

Definition at line 360 of file utils.py.

00360 
00361     def __len__(self):
00362         return self.index

def Archetypes.utils.DisplayList.__repr__ (   self) [inherited]

Definition at line 345 of file utils.py.

00345 
00346     def __repr__(self):
00347         return '<DisplayList %s at %s>' % (self[:], id(self))

def Archetypes.utils.DisplayList.__str__ (   self) [inherited]

Definition at line 348 of file utils.py.

00348 
00349     def __str__(self):
00350         return str(self[:])

def Archetypes.utils.DisplayList.add (   self,
  key,
  value,
  msgid = None 
) [inherited]

Reimplemented in Archetypes.utils.IntDisplayList.

Definition at line 380 of file utils.py.

00380 
00381     def add(self, key, value, msgid=None):
00382         if isinstance(key, int):
00383             deprecated('Using ints as DisplayList keys is deprecated (add)')
00384         if not isinstance(key, basestring) and not isinstance(key, int):
00385             raise TypeError('DisplayList keys must be strings or ints, got %s' %
00386                             type(key))
00387         if not isinstance(value, basestring) and not isinstance(value, int):
00388             raise TypeError('DisplayList values must be strings or ints, got %s' %
00389                             type(value))
00390         if msgid is not None:
00391             deprecated('Using explicit msgids for DisplayLists is deprecated. '
00392                         'Store Zope3 Messages as values directly.')
00393             if not isinstance(msgid, basestring):
00394                 raise TypeError('DisplayList msg ids must be strings, got %s' %
00395                                 type(msgid))
00396         self.index +=1
00397         k = (self.index, key)
00398         v = (self.index, value)
00399 
00400         self._keys[key] = v
00401         self._values[value] = k
00402         self._itor.append(key)
00403         if msgid is not None:
00404             self._i18n_msgids[key] = msgid

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.utils.DisplayList.fromList (   self,
  lst 
) [inherited]

Definition at line 354 of file utils.py.

00354 
00355     def fromList(self, lst):
00356         for item in lst:
00357             if isinstance(item, list):
00358                 item = tuple(item)
00359             self.add(*item)

Here is the call graph for this function:

def Archetypes.utils.DisplayList.getKey (   self,
  value,
  default = None 
) [inherited]
get key

Definition at line 405 of file utils.py.

00405 
00406     def getKey(self, value, default=None):
00407         """get key"""
00408         v = self._values.get(value, None)
00409         if v: return v[1]
00410         for k, v in self._values.items():
00411             if repr(value) == repr(k):
00412                 return v[1]
00413         return default

def Archetypes.utils.DisplayList.getMsgId (   self,
  key 
) [inherited]

Reimplemented in Archetypes.utils.IntDisplayList.

Definition at line 428 of file utils.py.

00428 
00429     def getMsgId(self, key):
00430         "get i18n msgid"
00431         deprecated('DisplayList getMsgId is deprecated. Store Zope3 Messages '
00432                    'as values instead.')
00433         if isinstance(key, int):
00434             deprecated('Using ints as DisplayList keys is deprecated (msgid)')
00435         if not isinstance(key, basestring) and not isinstance(key, int):
00436             raise TypeError('DisplayList keys must be strings or ints, got %s' %
00437                             type(key))
00438         if self._i18n_msgids.has_key(key):
00439             return self._i18n_msgids[key]
00440         else:
00441             return self._keys[key][1]

Here is the call graph for this function:

def Archetypes.utils.Vocabulary.getValue (   self,
  key,
  default = None 
)
Get i18n value

Reimplemented from Archetypes.utils.DisplayList.

Definition at line 633 of file utils.py.

00633 
00634     def getValue(self, key, default=None):
00635         """
00636         Get i18n value
00637         """
00638         if isinstance(key, int):
00639             deprecated('Using ints as DisplayList keys is deprecated (getValue)')
00640         if not isinstance(key, basestring) and not isinstance(key, int):
00641             raise TypeError('DisplayList keys must be strings or ints, got %s' %
00642                             type(key))
00643         v = self._keys.get(key, None)
00644         value = default
00645         if v:
00646             value = v[1]
00647         else:
00648             for k, v in self._keys.items():
00649                 if repr(key) == repr(k):
00650                     value = v[1]
00651                     break
00652 
00653         if self._i18n_domain and self._instance:
00654             msg = self._i18n_msgids.get(key, None) or value
00655 
00656             if isinstance(msg, Message):
00657                 return msg
00658 
00659             if not msg:
00660                 return ''
00661 
00662             return getGTS().translate(self._i18n_domain, msg,
00663                                       context=self._instance, default=value)
00664         else:
00665             return value
00666 
00667 InitializeClass(Vocabulary)

Here is the call graph for this function:

def Archetypes.utils.DisplayList.index_sort (   self,
  a,
  b 
) [inherited]

Definition at line 377 of file utils.py.

00377 
00378     def index_sort(self, a, b):
00379         return  a[0] - b[0]

Here is the caller graph for this function:

def Archetypes.utils.DisplayList.items (   self) [inherited]
items

Definition at line 454 of file utils.py.

00454 
00455     def items(self):
00456         """items"""
00457         keys = self.keys()
00458         return tuple([(key, self.getValue(key)) for key in keys])

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.utils.DisplayList.keys (   self) [inherited]

Definition at line 442 of file utils.py.

00442 
00443     def keys(self):
00444         "keys"
00445         kl = self._values.values()
00446         kl.sort(self.index_sort)
00447         return [k[1] for k in kl]

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.utils.DisplayList.sortedByKey (   self) [inherited]
return a new display list sorted by key

Definition at line 467 of file utils.py.

00467 
00468     def sortedByKey(self):
00469         """return a new display list sorted by key"""
00470         def _cmp(a, b):
00471             return cmp(a[0], b[0])
00472         values = list(self.items())
00473         values.sort(_cmp)
00474         return DisplayList(values)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.utils.DisplayList.sortedByValue (   self) [inherited]
return a new display list sorted by value

Definition at line 459 of file utils.py.

00459 
00460     def sortedByValue(self):
00461         """return a new display list sorted by value"""
00462         def _cmp(a, b):
00463             return cmp(a[1], b[1])
00464         values = list(self.items())
00465         values.sort(_cmp)
00466         return DisplayList(values)

Here is the call graph for this function:

def Archetypes.utils.DisplayList.values (   self) [inherited]

Definition at line 448 of file utils.py.

00448 
00449     def values(self):
00450         "values"
00451         vl = self._keys.values()
00452         vl.sort(self.index_sort)
00453         return [v[1] for v in vl]

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 631 of file utils.py.

Reimplemented from Archetypes.utils.DisplayList.

Definition at line 626 of file utils.py.

Definition at line 630 of file utils.py.

Reimplemented from Archetypes.utils.DisplayList.

Definition at line 628 of file utils.py.

Reimplemented from Archetypes.utils.DisplayList.

Definition at line 625 of file utils.py.

Reimplemented from Archetypes.utils.DisplayList.

Definition at line 627 of file utils.py.

Reimplemented from Archetypes.utils.DisplayList.

Definition at line 629 of file utils.py.

tuple Archetypes.utils.Vocabulary.security = ClassSecurityInfo() [static]

Reimplemented from Archetypes.utils.DisplayList.

Definition at line 621 of file utils.py.


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