Skip to content

Commit

Permalink
Update Clickmap id regular expression
Browse files Browse the repository at this point in the history
  • Loading branch information
jcassee committed Apr 19, 2015
1 parent 72b1716 commit e44141b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Development
-----------
* Fix Clickmap tracker id regular expression

Version 0.21.0
--------------
* Added compatibility with Python 3 (Eric Amador)
Expand Down
4 changes: 2 additions & 2 deletions analytical/templatetags/clickmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from analytical.utils import is_internal_ip, disable_html, get_required_setting


CLICKMAP_TRACKER_ID_RE = re.compile(r'^\d+$')
CLICKMAP_TRACKER_ID_RE = re.compile(r'^\w+$')
TRACKING_CODE = """
<script type="text/javascript">
var clickmapConfig = {tracker: '%(tracker_id)s', version:'2'};
Expand Down Expand Up @@ -47,7 +47,7 @@ class ClickmapNode(Node):
def __init__(self):
self.tracker_id = get_required_setting('CLICKMAP_TRACKER_ID',
CLICKMAP_TRACKER_ID_RE,
"must be a (string containing) a number")
"must be an alphanumeric string")

def render(self, context):
html = TRACKING_CODE % {'tracker_id': self.tracker_id}
Expand Down
8 changes: 4 additions & 4 deletions analytical/tests/test_tag_clickmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@
from analytical.utils import AnalyticalException


@override_settings(CLICKMAP_TRACKER_ID='12345')
@override_settings(CLICKMAP_TRACKER_ID='12345ABC')
class ClickmapTagTestCase(TagTestCase):
"""
Tests for the ``clickmap`` template tag.
"""

def test_tag(self):
r = self.render_tag('clickmap', 'clickmap')
self.assertTrue("tracker: '12345', version:'2'};" in r, r)
self.assertTrue("tracker: '12345ABC', version:'2'};" in r, r)

def test_node(self):
r = ClickmapNode().render(Context({}))
self.assertTrue("tracker: '12345', version:'2'};" in r, r)
self.assertTrue("tracker: '12345ABC', version:'2'};" in r, r)

@override_settings(CLICKMAP_TRACKER_ID=None)
def test_no_site_id(self):
self.assertRaises(AnalyticalException, ClickmapNode)

@override_settings(CLICKMAP_TRACKER_ID='abc')
@override_settings(CLICKMAP_TRACKER_ID='ab#c')
def test_wrong_site_id(self):
self.assertRaises(AnalyticalException, ClickmapNode)

Expand Down

0 comments on commit e44141b

Please sign in to comment.