TAL Expression widget
=====================
This widget allows you to define dynamic faceted criteria using tal expressions

The following contexts can be used within tal expressions:

    - context -- faceted navigable context
    - referer -- request.HTTP_REFERER object. Use this if you load faceted from another place (like: portal_relations)
    - request -- faceted navigable REQUEST object
    - widget -- Tal Expression Widget instance
    - criterion -- Tal Expression Criterion instance

    >>> from eea.facetednavigation.widgets.tal.widget import Widget
    >>> from eea.facetednavigation.widgets.storage import Criterion

Setup
-----

    >>> portal = layer['portal']
    >>> request = layer['request']
    >>> sandbox = portal['sandbox']
    >>> criterion = Criterion(index='path', title='A Title')
    >>> sandbox.setLanguage('en')

    >>> widget = Widget(sandbox, request, criterion)


Simple expressions
-------------------

String
~~~~~~

    >>> widget.data.update(default=u'string:a/path')
    >>> query = widget.query(form={})
    >>> 'path' in query
    True

    >>> print(query['path'])
    a/path


Python
~~~~~~

  Integer

    >>> widget.data.update(default=u'python: (100+10)//2')
    >>> widget.query(form={})
    {'path': 55}

    >>> widget.data.update(default=u'python: 10 - 10')
    >>> widget.query(form={})
    {'path': 0}

  Boolean

    >>> widget.data.update(default=u'python:False')
    >>> widget.query(form={})
    {'path': False}

    >>> widget.data.update(default=u'python:True')
    >>> widget.query(form={})
    {'path': True}

  String

    >>> widget.data.update(default=u"python:'ex'.replace('ex', '')")
    >>> widget.query(form={})
    {'path': ''}

    >>> widget.data.update(default=u"python: ' y '.strip()")
    >>> widget.query(form={})
    {'path': 'y'}

  Tuple

    >>> widget.data.update(default=u"python:()")
    >>> widget.query(form={})
    {'path': ()}

    >>> widget.data.update(default=u"python:(1,)")
    >>> widget.query(form={})
    {'path': (1,)}

  List

    >>> widget.data.update(default=u"python:[x for x in range(0, 0)]")
    >>> widget.query(form={})
    {'path': []}

    >>> widget.data.update(default=u"python:[x for x in range(0, 1)]")
    >>> widget.query(form={})
    {'path': [0]}

  Dictionary

    >>> widget.data.update(default=u"python:{1: 2}")
    >>> widget.query(form={})
    {'path': {1: 2}}

    >>> widget.data.update(default=u"python:{}")
    >>> widget.query(form={})
    {'path': {}}


FACET-EMPTY string
--------------------

You can force this facet to send no query to catalog. This is useful when you
want to bypass this facet for empty values

    >>> widget.data.update(default=u"python:(10 - 10) or 'FACET-EMPTY' ")
    >>> widget.query(form={})
    {}

    >>> widget.data.update(default=u"python:(10 - 9) or 'FACET-EMPTY' ")
    >>> widget.query(form={})
    {'path': 1}


Dynamic expressions using available contexts
---------------------------------------------

context
~~~~~~~

    >>> widget.data.update(default=u'string:${context/absolute_url}')
    >>> query = widget.query(form={})
    >>> 'path' in query
    True

    >>> print(query['path'])
    http://nohost/plone/sandbox

    >>> widget.data.update(default=u'python:context.absolute_url(1)')
    >>> query = widget.query(form={})
    >>> 'path' in query
    True

    >>> print(query['path'])
    plone/sandbox

referer
~~~~~~~

    >>> widget.data.update(default=u'string:${referer/absolute_url}')
    >>> query = widget.query(form={})
    >>> 'path' in query
    True

    >>> print(query['path'])
    http://nohost/plone/sandbox

    >>> widget.data.update(default=u'python:referer.absolute_url(1)')
    >>> query = widget.query(form={})
    >>> 'path' in query
    True

    >>> print(query['path'])
    plone/sandbox

    This is the same as context, let's see what happends if faceted is loaded
    from another place

    >>> request.HTTP_REFERER = sandbox.absolute_url()
    >>> widget = Widget(sandbox, request, criterion)

    >>> widget.data.update(default=u'string:${referer/absolute_url}')
    >>> query = widget.query(form={})
    >>> 'path' in query
    True

    >>> print(query['path'])
    http://nohost/plone/sandbox

    >>> widget.data.update(default=u'python:referer.absolute_url(1)')
    >>> query = widget.query(form={})
    >>> 'path' in query
    True

    >>> print(query['path'])
    plone/sandbox

request
~~~~~~~

    >>> widget.data.update(default=u'python:request.URL', index='path')
    >>> query = widget.query(form={})
    >>> 'path' in query
    True

    >>> print(query['path'])
    http://nohost

widget
~~~~~~

    >>> widget.data.update(default=u'python:widget.widget_type', index='type')
    >>> query = widget.query(form={})
    >>> 'type' in query
    True

    >>> print(query['type'])
    tal

criterion
~~~~~~~~~

    >>> widget.data.update(default=u'python:criterion.title', index='sortable_title')
    >>> query = widget.query(form={})
    >>> 'sortable_title' in query
    True

    >>> print(query['sortable_title'])
    A Title
