Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes | Private Member Functions
archetypes.kss.fields.FieldsView Class Reference
Inheritance diagram for archetypes.kss.fields.FieldsView:
Inheritance graph
[legend]
Collaboration diagram for archetypes.kss.fields.FieldsView:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def renderViewField
def getTemplate
def renderEditField
def replaceField
def replaceWithView
def saveField
def macroContent
def issueAllPortalMessages

Static Public Attributes

tuple view_field_wrapper = ZopeTwoPageTemplateFile('browser/view_field_wrapper.pt')
 KSS methods.
tuple edit_field_wrapper = ZopeTwoPageTemplateFile('browser/edit_field_wrapper.pt')
tuple header_macros = ZopeTwoPageTemplateFile('browser/macro_wrapper.pt')

Private Member Functions

def _getFieldContext

Detailed Description

Definition at line 53 of file fields.py.


Member Function Documentation

def archetypes.kss.fields.FieldsView._getFieldContext (   self,
  uid 
) [private]

Definition at line 214 of file fields.py.

00214 
00215     def _getFieldContext(self, uid):
00216         if uid is not None:
00217             rc = getToolByName(aq_inner(self.context), 'reference_catalog')
00218             return rc.lookupObject(uid)
00219         else:
00220             deprecated(FieldsView, missing_uid_deprecation)
00221             return aq_inner(self.context)
        

Here is the call graph for this function:

Here is the caller graph for this function:

def archetypes.kss.fields.FieldsView.getTemplate (   self,
  templateId,
  context = None 
)
traverse/search template

Definition at line 77 of file fields.py.

00077 
00078     def getTemplate(self, templateId, context=None):
00079         """
00080         traverse/search template
00081         """
00082 
00083         if not context:
00084             context = self.context
00085 
00086         template = context.restrictedTraverse(templateId)
00087         
00088         if IBrowserView.providedBy(template):
00089             view = template
00090             for attr in ('index', 'template', '__call__'):
00091                 template = getattr(view, attr, None)
00092                 if template is not None and hasattr(template, 'macros'):
00093                     break
00094             if template is None:
00095                 raise KeyError("Unable to find template for view %s" % templateId)
00096         return template
00097 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 45 of file plonekssview.py.

00045 
00046     def issueAllPortalMessages(self):
00047         if hasattr(self.request.RESPONSE, 'cookies'):
00048             cookie = self.request.RESPONSE.cookies.get(STATUSMESSAGEKEY)
00049             if cookie:
00050                 encodedstatusmessages = cookie['value']
00051                 statusmessages = _decodeCookieValue(encodedstatusmessages)
00052             else:
00053                 statusmessages = []
00054             for msg in statusmessages:
00055                 self.getCommandSet('plone').issuePortalMessage(msg)
00056             self.request.RESPONSE.expireCookie(STATUSMESSAGEKEY, path='/')

Here is the call graph for this function:

Here is the caller graph for this function:

def plone.app.kss.plonekssview.PloneKSSView.macroContent (   self,
  macropath,
  kw 
) [inherited]

Definition at line 24 of file plonekssview.py.

00024 
00025     def macroContent(self, macropath, **kw):
00026         'Renders a macro and returns its text'
00027         path = macropath.split('/')
00028         if len(path) < 2 or path[-2] != 'macros':
00029             raise RuntimeError, 'Path must end with macros/name_of_macro (%s)' % (repr(macropath), )
00030         # needs string, do not tolerate unicode (causes but at traverse)
00031         jointpath = '/'.join(path[:-2]).encode('ascii')
00032         macroobj = self.context.restrictedTraverse(jointpath)
00033         try:
00034             the_macro = macroobj.macros[path[-1]]
00035         except AttributeError, IndexError:
00036             raise RuntimeError, 'Macro not found'
00037         #  
00038         # put parameters on the request, by saving the original context
00039         self.request.form, orig_form = kw, self.request.form
00040         content = self.header_macros.__of__(macroobj.aq_parent)(the_macro=the_macro)
00041         self.request.form = orig_form
00042         # Always encoded as utf-8
00043         content = force_unicode(content, 'utf')
00044         return content

Here is the call graph for this function:

Here is the caller graph for this function:

def archetypes.kss.fields.FieldsView.renderEditField (   self,
  fieldname,
  templateId,
  macro,
  uid = None 
)
renders the edit widget inside the macro coming from the view template

Definition at line 98 of file fields.py.

00098 
00099     def renderEditField(self, fieldname, templateId, macro, uid=None):
00100         """
00101         renders the edit widget inside the macro coming from the view template
00102         """
00103 
00104         context = self._getFieldContext(uid)
00105         template = self.getTemplate(templateId, context)
00106         containingMacro = template.macros[macro]
00107         fieldname = fieldname.split('archetypes-fieldname-')[-1]
00108         field = context.getField(fieldname)
00109         widget = field.widget
00110         widgetMacro = widget('edit', context)
00111         
00112         res = self.edit_field_wrapper(containingMacro=containingMacro,
00113                                       widgetMacro=widgetMacro,
00114                                       field=field, instance=context,
00115                                       mode='edit',
00116                                       templateId=templateId)
00117 
00118         return res
00119 

Here is the call graph for this function:

Here is the caller graph for this function:

def archetypes.kss.fields.FieldsView.renderViewField (   self,
  fieldname,
  templateId,
  macro,
  uid = None 
)
renders the macro coming from the view template

Definition at line 62 of file fields.py.

00062 
00063     def renderViewField(self, fieldname, templateId, macro, uid=None):
00064         """
00065         renders the macro coming from the view template
00066         """
00067 
00068         context = self._getFieldContext(uid)
00069         template = self.getTemplate(templateId, context)
00070 
00071         viewMacro = template.macros[macro]
00072         res = self.view_field_wrapper(viewMacro=viewMacro,
00073                                       context=context,
00074                                       templateId=templateId,
00075                                       fieldName=fieldname)
00076         return res

Here is the call graph for this function:

Here is the caller graph for this function:

def archetypes.kss.fields.FieldsView.replaceField (   self,
  fieldname,
  templateId,
  macro,
  uid = None,
  target = None,
  edit = False 
)
kss commands to replace the field value by the edit widget

The edit parameter may be used if we are coming from something else
than an edit view.

Reimplemented in archetypes.kss.fields.ATDocumentFieldsView.

Definition at line 122 of file fields.py.

00122 
00123     def replaceField(self, fieldname, templateId, macro, uid=None, target=None, edit=False):
00124         """
00125         kss commands to replace the field value by the edit widget
00126 
00127         The edit parameter may be used if we are coming from something else
00128         than an edit view.
00129         """
00130         ksscore = self.getCommandSet('core')
00131         zopecommands = self.getCommandSet('zope')
00132         plonecommands = self.getCommandSet('plone')
00133 
00134         instance = self._getFieldContext(uid)        
00135 
00136         if edit:
00137             locking = ILockable(instance, None)
00138             if locking:
00139                 if not locking.can_safely_unlock():
00140                     selector = ksscore.getHtmlIdSelector('plone-lock-status')
00141                     zopecommands.refreshViewlet(selector,
00142                                                 'plone.abovecontent',
00143                                                 'plone.lockinfo')
00144                     plonecommands.refreshContentMenu()
00145 
00146                     return self.render()
00147                 else: # were are locking the content
00148                     locking.lock()
00149 
00150         plonecommands.issuePortalMessage('')
00151 
00152         html = self.renderEditField(fieldname, templateId, macro, uid)
00153         html = html.strip()
00154 
00155         field_id = target or "parent-fieldname-%s" % fieldname
00156         ksscore.replaceHTML(ksscore.getHtmlIdSelector(field_id), html)
00157         ksscore.focus("#%s .firstToFocus" % field_id)
00158 
00159         return self.render()

def archetypes.kss.fields.FieldsView.replaceWithView (   self,
  fieldname,
  templateId,
  macro,
  uid = None,
  target = None,
  edit = False 
)
kss commands to replace the edit widget by the field view

Reimplemented in archetypes.kss.fields.ATDocumentFieldsView.

Definition at line 160 of file fields.py.

00160 
00161     def replaceWithView(self, fieldname, templateId, macro, uid=None, target=None, edit=False):
00162         """
00163         kss commands to replace the edit widget by the field view
00164         """
00165 
00166         ksscore = self.getCommandSet('core')
00167         
00168         instance = self._getFieldContext(uid)        
00169         locking = ILockable(instance, None)
00170         if locking and locking.can_safely_unlock():
00171             locking.unlock()
00172 
00173         html = self.renderViewField(fieldname, templateId, macro, uid)
00174         html = html.strip()
00175 
00176         field_id = target or "parent-fieldname-%s" % fieldname
00177         ksscore.replaceHTML(ksscore.getHtmlIdSelector(field_id), html)
00178 
00179         return self.render()

Here is the caller graph for this function:

def archetypes.kss.fields.FieldsView.saveField (   self,
  fieldname,
  value = None,
  templateId = None,
  macro = None,
  uid = None,
  target = None 
)
This method saves the current value to the field. and returns the rendered
view macro.

Reimplemented in archetypes.kss.fields.ATDocumentFieldsView.

Definition at line 180 of file fields.py.

00180 
00181     def saveField(self, fieldname, value=None, templateId=None, macro=None, uid=None, target=None):
00182         """
00183         This method saves the current value to the field. and returns the rendered
00184         view macro.
00185         """
00186         # We receive a dict or nothing in value.
00187         #
00188         if value is None:
00189             value = self.request.form.copy()
00190         instance = self._getFieldContext(uid)        
00191         field = instance.getField(fieldname)
00192         value, kwargs = field.widget.process_form(instance, field, value)
00193         error = field.validate(value, instance, {}, REQUEST=self.request)
00194         if not error and field.writeable(instance):
00195             setField = field.getMutator(instance)
00196             setField(value, **kwargs)
00197 
00198             # send event that will invoke versioning
00199             events.fieldsModified(instance, fieldname)
00200 
00201             instance.reindexObject() #XXX: Temp workaround, should be gone in AT 1.5
00202 
00203             descriptor = lifecycleevent.Attributes(IPortalObject, fieldname)
00204             event.notify(ObjectEditedEvent(instance, descriptor))
00205             
00206             return self.replaceWithView(fieldname, templateId, macro, uid, target)
00207         else:
00208             if not error:
00209                 # XXX This should not actually happen...
00210                 error = 'Field is not writeable.'
00211             # Send back the validation error
00212             self.getCommandSet('atvalidation').issueFieldError(fieldname, error)
00213             return self.render()


Member Data Documentation

tuple archetypes.kss.fields.FieldsView.edit_field_wrapper = ZopeTwoPageTemplateFile('browser/edit_field_wrapper.pt') [static]

Definition at line 60 of file fields.py.

tuple plone.app.kss.plonekssview.PloneKSSView.header_macros = ZopeTwoPageTemplateFile('browser/macro_wrapper.pt') [static, inherited]

Definition at line 22 of file plonekssview.py.

tuple archetypes.kss.fields.FieldsView.view_field_wrapper = ZopeTwoPageTemplateFile('browser/view_field_wrapper.pt') [static]

KSS methods.

Definition at line 59 of file fields.py.


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