Back to index

plone3  3.1.7
link.py
Go to the documentation of this file.
00001 from wicked import utils
00002 from wicked.interfaces import IWickedLink, IWickedEvent, WickedContentAddedEvent
00003 from zope.component import handle, adapter
00004 from zope.event import notify
00005 from zope.interface import implements
00006 
00007 _marker=object()
00008 
00009 class WickedAdd(object):
00010 
00011     def __init__(self, context, request):
00012         self._context = (context,)
00013         self.request = request
00014 
00015     def notify_content_added(self, newcontent, title, section):
00016         notify(WickedContentAddedEvent(self.context, newcontent, title, section, self.request))
00017         
00018     @property
00019     def context(self):
00020         return self._context[0]
00021 
00022     def add_content(self, title=None, section=None, type_name=_marker):
00023         raise NotImplementedError
00024 
00025     def addMenu(self):
00026         return 1
00027 
00028 
00029 _marker=object()
00030 
00031 class BasicLink(object):
00032     implements(IWickedLink)
00033     section = _marker
00034     
00035     def __init__(self, context, request):
00036         self._context = (context,)
00037         self.request = request
00038         self.counter=utils.counter()
00039         
00040     @property
00041     def context(self):
00042         return self._context[0]
00043 
00044     @utils.memoizedproperty
00045     def howmany(self):
00046         return len(self.links)
00047 
00048     @utils.memoizedproperty
00049     def multiple(self):
00050         return self.howmany > 1
00051 
00052     @utils.memoizedproperty
00053     def links(self):
00054         """
00055         calculates urls
00056 
00057         abstract zope2ism
00058         """
00059         for link in self._links:
00060             link['url'] = self.request.physicalPathToURL(link['path'], 0)
00061         return self._links
00062 
00063     @property
00064     def singlelink(self):
00065         return self.links[0]
00066 
00067     @property
00068     def count(self):
00069         return self.counter.next()
00070 
00071     @utils.clearbefore
00072     def load(self, links, chunk):
00073         self._links = links
00074         self.chunk = chunk
00075 
00076 
00077 @adapter(IWickedEvent)
00078 def redispatch(event):
00079     handle(event.context, event)
00080 
00081 
00082 def test_suite():
00083     import unittest
00084     from zope.testing import doctest
00085     suite = doctest.DocFileSuite('link.txt',
00086                                  globs=globals(),
00087                                  package='wicked',
00088                                  optionflags=doctest.REPORT_ONLY_FIRST_FAILURE | doctest.ELLIPSIS)
00089     return suite