flatten confiuration. update doc

This commit is contained in:
Martín Gaitán 2013-11-26 13:55:46 -03:00
parent d24802b358
commit e1983ad8a9
2 changed files with 23 additions and 22 deletions

View file

@ -23,14 +23,11 @@ TRACKING_CODE = """
var s=document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(uv,s)})();
%(options)s
UserVoice.push(['set', %(options)s]);
%(trigger)s
</script>
"""
OPTION_CODE = """
UserVoice.push(['%s', %s]);
"""
TRIGGER = "UserVoice.push(['addTrigger', {}]);"
register = Library()
@ -61,16 +58,14 @@ class UserVoiceNode(Node):
if not widget_key:
return ''
# default
options = {'addTrigger': {'mode': 'contact',
'trigger_position': 'bottom-right'}}
options = {}
options.update(getattr(settings, 'USERVOICE_WIDGET_OPTIONS', {}))
options.update(context.get('uservoice_widget_options', {}))
options = ''.join([OPTION_CODE % (k, simplejson.dumps(v))
for k, v in options.iteritems()])
trigger = getattr(settings, 'USERVOICE_ADD_TRIGGER', True)
html = TRACKING_CODE % {'widget_key': widget_key,
'options': options}
'options': simplejson.dumps(options),
'trigger': TRIGGER if trigger else ''}
return html

View file

@ -97,21 +97,31 @@ with UserVoice's options.
See the `JS SDK Overview <https://developer.uservoice.com/docs/widgets/overview/>`_ and the `reference <https://developer.uservoice.com/docs/widgets/options/>`_ for the details of available options.
For example, to override the default position of the widget, you could define:
For example, to override the default icon style with a tab and on the left,
you could define:
.. code-block:: python
USERVOICE_WIDGET_OPTIONS = (('addTrigger',
{"trigger_position": "bottom-left",
"mode": "contact"}),)
USERVOICE_WIDGET_OPTIONS = {"trigger_position": "left",
"trigger_style": "tab"}
Per-view widget
...............
The widget key can be set in a view using the ``uservoice_widget_key`` and
``uservoice_widget_options`` template context variables::
The widget configuration can be overriden in a view using
``uservoice_widget_options`` template context variable. For example:
.. code-block:: python
context = RequestContext({'uservoice_widget_options': 'mode': 'satisfaction'})
return some_template.render(context)
It's also possible to set a different widget key for a particular view
with ``uservoice_widget_key``:
.. code-block:: python
context = RequestContext({'uservoice_widget_key': 'XXXXXXXXXXXXXXXXXXXX'})
return some_template.render(context)
@ -138,10 +148,6 @@ The widget key passed in the context variable overrides both the default
and the per-view widget key.
In this case, the default widget tab is not hidden.
----
Thanks go to UserVoice for their support with the development of this