Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Attributes
plone.app.kss.content_replacer.ContentView Class Reference
Inheritance diagram for plone.app.kss.content_replacer.ContentView:
Inheritance graph
[legend]
Collaboration diagram for plone.app.kss.content_replacer.ContentView:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def replaceContentRegion

Static Public Attributes

tuple main_template2 = ZopeTwoPageTemplateFile('browser/main_template_standalone.pt')

Private Member Functions

def _filter_action

Static Private Attributes

tuple _filter_action = staticmethod(_filter_action)

Detailed Description

Definition at line 45 of file content_replacer.py.


Member Function Documentation

def plone.app.kss.content_replacer.ContentView._filter_action (   actions,
  id,
  found = None 
) [private]

Definition at line 57 of file content_replacer.py.

00057 
00058     def _filter_action(actions, id, found=None):
00059         if found is not None:
00060             return found
00061         for action in actions:
00062             if action['id'] == id:
                return action
def plone.app.kss.content_replacer.ContentView.replaceContentRegion (   self,
  url,
  tabid = '' 
)
Replace content region by tab id

Usage::
    ul.contentViews li a:click {
    evt-click-preventdefault: True;
    action-server: replaceContentRegion;
    replaceContentRegion-tabid: nodeAttr(id, true);
    replaceContentRegion-url: nodeAttr(href);
    }

REMARK:

We use the acquisition context hack to replace the main template
with one that only renders the content region. This means that if
the target template reuses main_template we win. Otherwise we loose
and we get a full page of which we have to take out the required
part with BeautifulSoup.

Warning ("Do you want to...") when we leave the page is not implemented.

Definition at line 66 of file content_replacer.py.

00066 
00067     def replaceContentRegion(self, url, tabid=''):
00068         '''Replace content region by tab id
00069 
00070         Usage::
00071             ul.contentViews li a:click {
00072             evt-click-preventdefault: True;
00073             action-server: replaceContentRegion;
00074             replaceContentRegion-tabid: nodeAttr(id, true);
00075             replaceContentRegion-url: nodeAttr(href);
00076             }
00077 
00078         REMARK:
00079 
00080         We use the acquisition context hack to replace the main template
00081         with one that only renders the content region. This means that if
00082         the target template reuses main_template we win. Otherwise we loose
00083         and we get a full page of which we have to take out the required
00084         part with BeautifulSoup.
00085 
00086         Warning ("Do you want to...") when we leave the page is not implemented.
00087 
00088         '''
00089         # REMARK on error handling: 
00090         # If KSSExplicitError is raised, the control will be passed
00091         # to the error handler defined on the client. I.e. for this rule,
00092         # the static plone-followLink should be activated. This means that
00093         # if this method decides it cannot handle the situation, it
00094         # raises this exception and we fallback to the non-AJAX behaviour.
00095         #
00096         # XXX The next checks could be left out - but we won't be able to change the tabs.
00097         # This could be solved with not using the tabs or doing server side quirks.
00098         # This affect management screens, for example, that are not real actions.
00099         # and unlock XXX
00100         context = aq_inner(self.context)
00101         lock = getMultiAdapter((context,self.request), name='plone_lock_operations')
00102         lock.safe_unlock()
00103 
00104         if not tabid or tabid == 'content':
00105             raise KSSExplicitError, 'No tabid on the tab'
00106         if not tabid.startswith('contentview-'):
00107             raise RuntimeError, 'Not a valid contentview id "%s"' % tabid
00108         # Split the url into it's components
00109         (proto, host, path, query, anchor) = urlsplit(url)
00110         # if the url doesn't use http(s) or has a query string or anchor
00111         # specification, don't bother
00112         if query or anchor or proto not in ('http', 'https'):
00113             raise KSSExplicitError, 'Unhandled protocol on the tab'
00114         # make the wrapping for the context, to overwrite main_template
00115         # note we have to use aq_chain[0] *not* aq_base.
00116         # XXX however just context would be good too? Hmmm
00117         wrapping = acquirerFactory(context)
00118         # Figure out the template to render.
00119         # We need the physical path which we can obtain from the url
00120         path = list(self.request.physicalPathFromURL(url))
00121         obj_path = list(context.getPhysicalPath())
00122         if path == obj_path:
00123             # target is the default view of the method.
00124             # url is like: ['http:', '', 'localhost:9777', 'kukitportlets', 'prefs_users_overview']
00125             # physical path is like: ('', 'kukitportlets')
00126             # We lookup the default view for the object, which may be
00127             # another object, if so we give up, otherwise we use the
00128             # appropriate template
00129             utils = getToolByName(context, 'plone_utils')
00130             if utils.getDefaultPage(context) is not None:
00131                 raise KSSExplicitError, 'no default page on the tab'
00132             viewobj, viewpath = utils.browserDefault(context)
00133             if len(viewpath) == 1:
00134                 viewpath = viewpath[0]
00135             template = viewobj.restrictedTraverse(viewpath)
00136         else:
00137             # see if it is a method on the same context object...
00138             # url is like: ['http:', '', 'localhost:9777', 'kukitportlets', 'prefs_users_overview']
00139             # physical path is like: ('', 'kukitportlets')
00140             if path[:-1] != obj_path:
00141                 raise KSSExplicitError, 'cannot reload since the tab visits a different context'
00142             method = path[-1]
00143             # Action method may be a method alias: Attempt to resolve to a template.
00144             try:
00145                 method = context.getTypeInfo().queryMethodID(method, default=method)
00146             except AttributeError:
00147                 # Don't raise if we don't have a CMF 1.5 FTI
00148                 pass
00149             template = wrapping.restrictedTraverse(method)
00150         # We render it
00151         content = template()
00152         # Now. We take out the required node from it!
00153         # We need this in any way, as we don't know if the template
00154         # actually used main_template! In that case we would have
00155         # the *whole* html which is wrong.
00156         soup = BeautifulSoup(content)
00157         replace_id = 'region-content'
00158         tag = soup.find('div', id=replace_id)
00159         if tag is None:
00160             raise RuntimeError, 'Result content did not contain <div id="%s">' % replace_id
00161         # now we send it back to the client
00162         result = unicode(tag)
00163         ksscore = self.getCommandSet('core')
00164         ksscore.replaceHTML(ksscore.getHtmlIdSelector(replace_id), result)
00165         # to remove old tab highlight,...
00166         ksscore.setAttribute(ksscore.getCssSelector("ul.contentViews li"), name='class', value='plain');
00167         # ... and put the highlight to the newly selected tab
00168         ksscore.setAttribute(ksscore.getHtmlIdSelector(tabid), name='class', value='selected');
00169         # Update the content menu to show them only in the "view"
00170         if tabid.endswith('view'):
00171             alsoProvides(self, IViewView)
00172         self.getCommandSet('plone').refreshContentMenu()
00173 

Here is the call graph for this function:


Member Data Documentation

Definition at line 63 of file content_replacer.py.

tuple plone.app.kss.content_replacer.ContentView.main_template2 = ZopeTwoPageTemplateFile('browser/main_template_standalone.pt') [static]

Definition at line 54 of file content_replacer.py.


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