The local custom portlet
--------------------------

The custom portlet enables the user to format the url used to browse a tag instead to use the plone ``search_form`` as a default.

Tests
~~~~~~~
Adding some content for testing searches
::

    >>> self.setRoles(('Manager', ))
    >>> self.portal['front-page'].edit(subject=['global', 'tags'])
    >>> if1 = self.folder.invokeFactory('Folder', id='f1')
    >>> if2 = self.folder.invokeFactory('Folder', id='f2')
    >>> f1 = self.folder[if1]
    >>> f2 = self.folder[if2]
    >>> d1 = f1.invokeFactory('Document', id='blog-entry1')
    >>> d2 = f1.invokeFactory('Document', id='blog-entry2')
    >>> d3 = f2.invokeFactory('Document', id='blog-entry3')
    >>> d4 = f2.invokeFactory('Document', id='blog-entry4')
    >>> f1[d1].edit(subject=['blog', 'tags'])
    >>> f1[d2].edit(subject=['foo', 'bar'])
    >>> f2[d3].edit(subject=['toto', 'titi'])
    >>> f2[d4].edit(subject=['toto', 'tutu'])

Looking for our adapter to be in place
::

    >>> from collective.portlet.localcumulus.interfaces import ICustomLocalTagsRetriever
    >>> from collective.portlet.localcumulus import catalog
    >>> data = catalog.DummyData()
    >>> data.refreshInterval = 1
    >>> data.path = '/'.join(f1.getPhysicalPath())

This adapter takes a context and an Assigment as 'data' attribute
::

    >>> retriever = ICustomLocalTagsRetriever(f1)
    >>> retriever
    <collective.portlet.localcumulus.catalog.CustomLocalTags object at ...>

Trying to get the local tags of the f1 folder with no url, it will default to the localtag behaviour
::

    >>> data.search_url = ''
    >>> retriever.data = data
    >>> print '\n'.join(['%s %s %s'% i for i in retriever.getTags()])
    blog 1 http://nohost/plone/search?path=/plone/Members/test_user_1_/f1&Subject:list=blog
    foo 1 http://nohost/plone/search?path=/plone/Members/test_user_1_/f1&Subject:list=foo
    bar 1 http://nohost/plone/search?path=/plone/Members/test_user_1_/f1&Subject:list=bar
    tags 1 http://nohost/plone/search?path=/plone/Members/test_user_1_/f1&Subject:list=tags


Customize url with variables
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We can play with some variables in python dict-string formating style.

If we have an url without any parameters inside, it just appends the tag at the end
::

    >>> [bool(catalog.NOT_SIMPLE_URL_RE.match(a)) for a in ['azerty', '()', '%(azerty)s', '%()', '%()s']]
    [False, False, True, False, False]
    >>> data.search_url = 'http://foo'
    >>> retriever.data = data
    >>> print '\n'.join(['%s' % i for i in retriever.getTags()])
    [u'blog', 1, u'http://foo/blog&path=/plone/Members/test_user_1_/f1']
    [u'foo', 1, u'http://foo/foo&path=/plone/Members/test_user_1_/f1']
    [u'bar', 1, u'http://foo/bar&path=/plone/Members/test_user_1_/f1']
    [u'tags', 1, u'http://foo/tags&path=/plone/Members/test_user_1_/f1']

Think that you'll surely have to add at least ``%(tag)s`` somewhere in your url to include the tag information ;).

Variables avaiblable are:

    * *portal_path*: plone site path
    * *portal_url*: plone site url
    * *here_url*: context url
    * *here_path*: context path inside the ZODB
    * *tag*: the tag
    * *tag_weight*: weight of the tag

::

    >>> data.search_url = '%(portal_url)s?path=%(portal_path)s&url=%(here_url)s&hpath=%(here_path)s&tag=%(tag)s&weight=%(tag_weight)s'
    >>> retriever.data = data
    >>> print '\n'.join(['%s' % i for i in retriever.getTags()])
    [u'blog', 1, u'http://nohost/plone?path=/plone&url=http://nohost/plone/Members/test_user_1_/f1&hpath=/plone&tag=blog&weight=1']
    [u'foo', 1, u'http://nohost/plone?path=/plone&url=http://nohost/plone/Members/test_user_1_/f1&hpath=/plone&tag=foo&weight=1']
    [u'bar', 1, u'http://nohost/plone?path=/plone&url=http://nohost/plone/Members/test_user_1_/f1&hpath=/plone&tag=bar&weight=1']
    [u'tags', 1, u'http://nohost/plone?path=/plone&url=http://nohost/plone/Members/test_user_1_/f1&hpath=/plone&tag=tags&weight=1']

.. vim: set ft=rst:
