From e1983ad8a933506f8974c502d1618cf1d4da6582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Gait=C3=A1n?= Date: Tue, 26 Nov 2013 13:55:46 -0300 Subject: [PATCH] flatten confiuration. update doc --- analytical/templatetags/uservoice.py | 19 +++++++------------ docs/services/uservoice.rst | 26 ++++++++++++++++---------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/analytical/templatetags/uservoice.py b/analytical/templatetags/uservoice.py index 7f87a75..540e488 100644 --- a/analytical/templatetags/uservoice.py +++ b/analytical/templatetags/uservoice.py @@ -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 """ -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 diff --git a/docs/services/uservoice.rst b/docs/services/uservoice.rst index 8f0cff8..6a9e089 100644 --- a/docs/services/uservoice.rst +++ b/docs/services/uservoice.rst @@ -97,21 +97,31 @@ with UserVoice's options. See the `JS SDK Overview `_ and the `reference `_ 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