Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Private Attributes
plone.app.controlpanel.widgets.LanguageTableWidget Class Reference
Inheritance diagram for plone.app.controlpanel.widgets.LanguageTableWidget:
Inheritance graph
[legend]
Collaboration diagram for plone.app.controlpanel.widgets.LanguageTableWidget:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def associateLabelWithInputControl
def __init__
def renderValue
def renderItemsWithValues
def renderItem
def renderSelectedItem
def textForValue

Public Attributes

 languages
 territories

Static Private Attributes

string _joinButtonToMessageTemplate = u""
string _table_start_template = u""
string _table_end_template = u""

Detailed Description

Definition at line 124 of file widgets.py.


Constructor & Destructor Documentation

def plone.app.controlpanel.widgets.LanguageTableWidget.__init__ (   self,
  field,
  request 
)
Initialize the widget.

Definition at line 151 of file widgets.py.

00151 
00152     def __init__(self, field, request):
00153         """Initialize the widget."""
00154         super(LanguageTableWidget, self).__init__(field,
00155             field.value_type.vocabulary, request)
00156         # TODO: This is a bit hairy, but seems to work fine.
00157         context = self.context.context.context
00158         portal_state = queryMultiAdapter((context, request),
00159                                          name=u'plone_portal_state')
00160         self.languages = portal_state.locale().displayNames.languages
00161         self.territories = portal_state.locale().displayNames.territories

Here is the caller graph for this function:


Member Function Documentation

Definition at line 148 of file widgets.py.

00148 
00149     def associateLabelWithInputControl(self):
00150         return None
    
def plone.app.controlpanel.widgets.LanguageTableWidget.renderItem (   self,
  index,
  text,
  value,
  name,
  cssClass 
)

Definition at line 236 of file widgets.py.

00236 
00237     def renderItem(self, index, text, value, name, cssClass):
00238         id = '%s.%s' % (name, index)
00239         elem = renderElement('input',
00240                              type="checkbox",
00241                              cssClass=cssClass,
00242                              name=name,
00243                              id=id,
00244                              value=value)
00245         return self._joinButtonToMessageTemplate % (cssClass, elem, text, value)
    

Here is the caller graph for this function:

Render the list of possible values, with those found in
`values` being marked as selected.

This code is mostly taken from from zope.app.form.browser.itemswidgets
import ItemsEditWidgetBase licensed under the ZPL 2.1.

Definition at line 165 of file widgets.py.

00165 
00166     def renderItemsWithValues(self, values):
00167         """Render the list of possible values, with those found in
00168         `values` being marked as selected.
00169 
00170         This code is mostly taken from from zope.app.form.browser.itemswidgets
00171         import ItemsEditWidgetBase licensed under the ZPL 2.1.
00172         """
00173 
00174         cssClass = self.cssClass
00175 
00176         # multiple items with the same value are not allowed from a
00177         # vocabulary, so that need not be considered here
00178         rendered_items = []
00179         count = 0
00180 
00181         rendered_items.append(self._table_start_template % (
00182             self.translate(_(u'heading_allowed_languages',
00183                              default=u'Allowed languages')),
00184             self.translate(_(u'heading_language_allowed',
00185                              default=u'Allowed?')),
00186             self.translate(_(u'heading_language',
00187                              default=u'Language')),
00188             self.translate(_(u'heading_language_code',
00189                              default=u'Code'))
00190             ))
00191 
00192         # Handle case of missing value
00193         missing = self._toFormValue(self.context.missing_value)
00194 
00195         if self._displayItemForMissingValue and not self.context.required:
00196             if missing in values:
00197                 render = self.renderSelectedItem
00198             else:
00199                 render = self.renderItem
00200 
00201             missing_item = render(count,
00202                 self.translate(self._messageNoValue),
00203                 missing,
00204                 self.name,
00205                 cssClass)
00206             rendered_items.append(missing_item)
00207             count += 1
00208 
00209         # Render normal values
00210         vocabulary = [(self.textForValue(term), term) for
00211                       term in self.vocabulary]
00212 
00213         # Sort by translated name, this is lame and needs proper collation
00214         # support, but we don't have that yet.
00215         vocabulary.sort()
00216 
00217         for item_text, term in vocabulary:
00218             if term.value in values:
00219                 render = self.renderSelectedItem
00220             else:
00221                 render = self.renderItem
00222 
00223             css = count % 2 and cssClass + 'even' or cssClass + 'odd'
00224             rendered_item = render(count,
00225                 item_text,
00226                 term.token,
00227                 self.name,
00228                 css)
00229 
00230             rendered_items.append(rendered_item)
00231             count += 1
00232 
00233         rendered_items.append(self._table_end_template)
00234 
00235         return rendered_items

Here is the call graph for this function:

def plone.app.controlpanel.widgets.LanguageTableWidget.renderSelectedItem (   self,
  index,
  text,
  value,
  name,
  cssClass 
)

Definition at line 246 of file widgets.py.

00246 
00247     def renderSelectedItem(self, index, text, value, name, cssClass):
00248         id = '%s.%s' % (name, index)
00249         elem = renderElement('input',
00250                              type="checkbox",
00251                              cssClass=cssClass,
00252                              name=name,
00253                              id=id,
00254                              value=value,
00255                              checked="checked")
00256         return self._joinButtonToMessageTemplate % (cssClass, elem, text, value)

Here is the caller graph for this function:

Definition at line 162 of file widgets.py.

00162 
00163     def renderValue(self, value):
00164         return ''.join(self.renderItems(value))

Extract a string from the `term`.

The `term` must be a vocabulary tokenized term.

Definition at line 257 of file widgets.py.

00257 
00258     def textForValue(self, term):
00259         """Extract a string from the `term`.
00260 
00261         The `term` must be a vocabulary tokenized term.
00262         """
00263         if ITitledTokenizedTerm.providedBy(term):
00264             if '-' in term.value:
00265                 code, territory = term.value.split('-')
00266                 territory = territory.upper()
00267                 result = self.languages.get(code, None)
00268                 # If we don't have a translation for the language, return the
00269                 # English one and don't bother with the country name
00270                 if result is None or result == code:
00271                     return term.title
00272                 territory = self.territories.get(territory, territory)
00273                 result = "%s (%s)" % (result, territory)
00274             else:
00275                 result = self.languages.get(term.value, None)
00276                 # If we don't have a translation for the language, return the
00277                 # default English text, rather than the language code
00278                 if result is None or result == term.value:
00279                     return term.title
00280             return result
00281         return term.token
00282 

Here is the caller graph for this function:


Member Data Documentation

Definition at line 127 of file widgets.py.

Definition at line 146 of file widgets.py.

Definition at line 131 of file widgets.py.

Definition at line 159 of file widgets.py.

Definition at line 160 of file widgets.py.


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