Skip to content

Commit

Permalink
Merge pull request #64 from bittner/feature/flake8-blank-lines
Browse files Browse the repository at this point in the history
Fix flake8 complaints (whitespace), add another badge
  • Loading branch information
jcassee committed Sep 16, 2015
2 parents cfdc330 + 3e93cc5 commit c6de68c
Show file tree
Hide file tree
Showing 23 changed files with 36 additions and 10 deletions.
5 changes: 4 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
django-analytical |latest-version|
==================================

|travis-ci| |coveralls| |downloads| |license|
|travis-ci| |coveralls| |health| |downloads| |license|

The django-analytical application integrates analytics services into a
Django_ project.
Expand Down Expand Up @@ -32,6 +32,9 @@ an asynchronous version of the Javascript code if possible.
.. |coveralls| image:: https://coveralls.io/repos/jcassee/django-analytical/badge.svg
:alt: Test coverage
:target: https://coveralls.io/r/jcassee/django-analytical
.. |health| image:: https://landscape.io/github/jcassee/django-analytical/master/landscape.svg?style=flat
:target: https://landscape.io/github/jcassee/django-analytical/master
:alt: Code health
.. |downloads| image:: https://img.shields.io/pypi/dm/django-analytical.svg
:alt: Monthly downloads from PyPI
:target: https://pypi.python.org/pypi/django-analytical
Expand Down
4 changes: 3 additions & 1 deletion analytical/templatetags/chartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def chartbeat_top(parser, token):
raise TemplateSyntaxError("'%s' takes no arguments" % bits[0])
return ChartbeatTopNode()


class ChartbeatTopNode(Node):
def render(self, context):
if is_internal_ip(context):
Expand All @@ -76,6 +77,7 @@ def chartbeat_bottom(parser, token):
raise TemplateSyntaxError("'%s' takes no arguments" % bits[0])
return ChartbeatBottomNode()


class ChartbeatBottomNode(Node):
def __init__(self):
self.user_id = get_required_setting('CHARTBEAT_USER_ID', USER_ID_RE,
Expand Down Expand Up @@ -109,5 +111,5 @@ def _get_domain(context):
elif getattr(settings, 'CHARTBEAT_AUTO_DOMAIN', True):
try:
return Site.objects.get_current().domain
except (ImproperlyConfigured, Site.DoesNotExist): #pylint: disable=E1101
except (ImproperlyConfigured, Site.DoesNotExist): # pylint: disable=E1101
return
1 change: 1 addition & 0 deletions analytical/templatetags/clicky.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def clicky(parser, token):
raise TemplateSyntaxError("'%s' takes no arguments" % bits[0])
return ClickyNode()


class ClickyNode(Node):
def __init__(self):
self.site_id = get_required_setting('CLICKY_SITE_ID', SITE_ID_RE,
Expand Down
1 change: 1 addition & 0 deletions analytical/templatetags/crazy_egg.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def crazy_egg(parser, token):
raise TemplateSyntaxError("'%s' takes no arguments" % bits[0])
return CrazyEggNode()


class CrazyEggNode(Node):
def __init__(self):
self.account_nr = get_required_setting('CRAZY_EGG_ACCOUNT_NUMBER',
Expand Down
4 changes: 4 additions & 0 deletions analytical/templatetags/google_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from analytical.utils import is_internal_ip, disable_html, \
get_required_setting, get_domain, AnalyticalException


def enumerate(sequence, start=0):
"""Copy of the Python 2.6 `enumerate` builtin for compatibility."""
n = start
Expand Down Expand Up @@ -56,6 +57,7 @@ def enumerate(sequence, start=0):

register = Library()


@register.tag
def google_analytics(parser, token):
"""
Expand All @@ -70,6 +72,7 @@ def google_analytics(parser, token):
raise TemplateSyntaxError("'%s' takes no arguments" % bits[0])
return GoogleAnalyticsNode()


class GoogleAnalyticsNode(Node):
def __init__(self):
self.property_id = get_required_setting(
Expand Down Expand Up @@ -132,6 +135,7 @@ def _get_other_commands(self, context):
commands.append(ANONYMIZE_IP_CODE)
return commands


def contribute_to_analytical(add_node):
GoogleAnalyticsNode() # ensure properly configured
add_node('head_bottom', GoogleAnalyticsNode)
1 change: 1 addition & 0 deletions analytical/templatetags/gosquared.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def gosquared(parser, token):
raise TemplateSyntaxError("'%s' takes no arguments" % bits[0])
return GoSquaredNode()


class GoSquaredNode(Node):
def __init__(self):
self.site_token = get_required_setting('GOSQUARED_SITE_TOKEN', TOKEN_RE,
Expand Down
2 changes: 1 addition & 1 deletion analytical/templatetags/intercom.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def render(self, context):
vars = self._get_custom_attrs(context)
vars["app_id"] = self.app_id
html = TRACKING_CODE % {"settings_json": json.dumps(vars, sort_keys=True)}

if is_internal_ip(context, 'INTERCOM') or not user or not user.is_authenticated():
# Intercom is disabled for non-logged in users.
html = disable_html(html, 'Intercom')
Expand Down
1 change: 1 addition & 0 deletions analytical/templatetags/kiss_insights.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def kiss_insights(parser, token):
raise TemplateSyntaxError("'%s' takes no arguments" % bits[0])
return KissInsightsNode()


class KissInsightsNode(Node):
def __init__(self):
self.account_number = get_required_setting(
Expand Down
5 changes: 3 additions & 2 deletions analytical/templatetags/kiss_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def kiss_metrics(parser, token):
raise TemplateSyntaxError("'%s' takes no arguments" % bits[0])
return KissMetricsNode()


class KissMetricsNode(Node):
def __init__(self):
self.api_key = get_required_setting('KISS_METRICS_API_KEY',
Expand All @@ -72,9 +73,9 @@ def render(self, context):
try:
properties = context[ALIAS_CONTEXT_KEY]
key, value = properties.popitem()
commands.append(ALIAS_CODE % (key,value))
commands.append(ALIAS_CODE % (key, value))
except KeyError:
pass
pass
try:
name, properties = context[EVENT_CONTEXT_KEY]
commands.append(EVENT_CODE % {'name': name,
Expand Down
1 change: 1 addition & 0 deletions analytical/templatetags/olark.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def olark(parser, token):
raise TemplateSyntaxError("'%s' takes no arguments" % bits[0])
return OlarkNode()


class OlarkNode(Node):
def __init__(self):
self.site_id = get_required_setting('OLARK_SITE_ID', SITE_ID_RE,
Expand Down
1 change: 1 addition & 0 deletions analytical/templatetags/performable.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def performable(parser, token):
raise TemplateSyntaxError("'%s' takes no arguments" % bits[0])
return PerformableNode()


class PerformableNode(Node):
def __init__(self):
self.api_key = get_required_setting('PERFORMABLE_API_KEY', API_KEY_RE,
Expand Down
1 change: 1 addition & 0 deletions analytical/templatetags/reinvigorate.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def reinvigorate(parser, token):
raise TemplateSyntaxError("'%s' takes no arguments" % bits[0])
return ReinvigorateNode()


class ReinvigorateNode(Node):
def __init__(self):
self.tracking_id = get_required_setting('REINVIGORATE_TRACKING_ID',
Expand Down
1 change: 1 addition & 0 deletions analytical/templatetags/snapengage.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def snapengage(parser, token):
raise TemplateSyntaxError("'%s' takes no arguments" % bits[0])
return SnapEngageNode()


class SnapEngageNode(Node):
def __init__(self):
self.widget_id = get_required_setting('SNAPENGAGE_WIDGET_ID',
Expand Down
1 change: 1 addition & 0 deletions analytical/templatetags/spring_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def spring_metrics(parser, token):
raise TemplateSyntaxError("'%s' takes no arguments" % bits[0])
return SpringMetricsNode()


class SpringMetricsNode(Node):
def __init__(self):
self.tracking_id = get_required_setting('SPRING_METRICS_TRACKING_ID',
Expand Down
1 change: 1 addition & 0 deletions analytical/templatetags/uservoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def _identify(self, user):
name = user.username
return {'name': name, 'email': user.email}


def contribute_to_analytical(add_node):
UserVoiceNode() # ensure properly configured
add_node('body_bottom', UserVoiceNode)
1 change: 1 addition & 0 deletions analytical/templatetags/woopra.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def woopra(parser, token):
raise TemplateSyntaxError("'%s' takes no arguments" % bits[0])
return WoopraNode()


class WoopraNode(Node):
def __init__(self):
self.domain = get_required_setting('WOOPRA_DOMAIN', DOMAIN_RE,
Expand Down
1 change: 1 addition & 0 deletions analytical/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Tests for django-analytical.
"""
# flake8: noqa

from analytical.tests.test_tag_analytical import *
from analytical.tests.test_tag_chartbeat import *
Expand Down
6 changes: 4 additions & 2 deletions analytical/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@

SECRET_KEY = 'testing'

MIDDLEWARE_CLASSES=('django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware'),
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
)
1 change: 1 addition & 0 deletions analytical/tests/test_tag_google_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def test_anonymize_ip_not_present(self):
r = GoogleAnalyticsNode().render(Context())
self.assertFalse("_gaq.push (['_gat._anonymizeIp']);" in r, r)


@override_settings(GOOGLE_ANALYTICS_PROPERTY_ID='UA-123456-7',
GOOGLE_ANALYTICS_TRACKING_STYLE=TRACK_MULTIPLE_DOMAINS,
GOOGLE_ANALYTICS_DOMAIN=None,
Expand Down
3 changes: 1 addition & 2 deletions analytical/tests/test_tag_kiss_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ def test_property(self):
def test_alias(self):
r = KissMetricsNode().render(Context({'kiss_metrics_alias':
{'test': 'test_alias'}}))
self.assertTrue("_kmq.push(['alias', 'test', 'test_alias']);" in r,r)

self.assertTrue("_kmq.push(['alias', 'test', 'test_alias']);" in r, r)

@override_settings(ANALYTICAL_INTERNAL_IPS=['1.1.1.1'])
def test_render_internal_ip(self):
Expand Down
2 changes: 1 addition & 1 deletion analytical/tests/test_tag_uservoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ def test_auto_trigger(self):
@override_settings(USERVOICE_ADD_TRIGGER=False)
def test_auto_trigger_custom_win(self):
r = UserVoiceNode().render(Context({'uservoice_add_trigger': True}))
self.assertTrue("UserVoice.push(['addTrigger', {}]);" in r, r)
self.assertTrue("UserVoice.push(['addTrigger', {}]);" in r, r)
1 change: 1 addition & 0 deletions analytical/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def test_get_required_setting(self):
self.assertRaises(AnalyticalException,
get_required_setting, "USER_ID", "\d+", "invalid USER_ID")


@override_settings(ANALYTICAL_DOMAIN="example.org")
class GetDomainTestCase(TestCase):
def test_get_service_domain_from_context(self):
Expand Down
1 change: 1 addition & 0 deletions analytical/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.template import Template, Context, RequestContext
from django.test.testcases import TestCase


def run_tests():
"""
Use the Django test runner to run the tests.
Expand Down

0 comments on commit c6de68c

Please sign in to comment.