Skip to content

Commit

Permalink
Drop Python 3.2 support
Browse files Browse the repository at this point in the history
Refactor Travis CI configuration

Add flake8 checks, address all complaints
  • Loading branch information
bittner committed Oct 16, 2017
1 parent bec4540 commit c7b14bd
Show file tree
Hide file tree
Showing 42 changed files with 393 additions and 336 deletions.
42 changes: 23 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
language: python
python: "3.5"
python:
- 2.7
- 3.3
- 3.4
- 3.5
# - 3.6
env:
- DJANGO=1.7
- DJANGO=1.8
- DJANGO=1.9
# - DJANGO=1.10
# - DJANGO=1.11
matrix:
exclude:
- python: 3.5
env: DJANGO=1.7
- python: 3.3
env: DJANGO=1.9
include:
- python: 2.7
env: TOXENV=flake8

install:
# continue to support Python 3.2 (see issue #84)
- pip install "virtualenv<14.0.0"
- pip install coveralls tox
- pip install tox-travis
script:
- tox
env:
# NOTE: To generate (update) the env list run
# $ tox -l | sort | xargs -I ITEM echo " - TOXENV="ITEM
- TOXENV=py27-django17
- TOXENV=py27-django18
- TOXENV=py27-django19
- TOXENV=py32-django17
- TOXENV=py32-django18
- TOXENV=py33-django17
- TOXENV=py33-django18
- TOXENV=py34-django17
- TOXENV=py34-django18
- TOXENV=py34-django19
- TOXENV=py35-django18
- TOXENV=py35-django19
7 changes: 2 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
django-analytical |latest-version|
==================================

|travis-ci| |coveralls| |health| |python-support| |downloads| |license| |gitter|
|travis-ci| |coveralls| |health| |python-support| |license| |gitter|

The django-analytical application integrates analytics services into a
Django_ project.
Expand All @@ -26,7 +26,7 @@ an asynchronous version of the Javascript code if possible.
.. |latest-version| image:: https://img.shields.io/pypi/v/django-analytical.svg
:alt: Latest version on PyPI
:target: https://pypi.python.org/pypi/django-analytical
.. |travis-ci| image:: https://travis-ci.org/jcassee/django-analytical.svg
.. |travis-ci| image:: https://img.shields.io/travis/jcassee/django-analytical/master.svg
:alt: Build status
:target: https://travis-ci.org/jcassee/django-analytical
.. |coveralls| image:: https://coveralls.io/repos/jcassee/django-analytical/badge.svg
Expand All @@ -38,9 +38,6 @@ an asynchronous version of the Javascript code if possible.
.. |python-support| image:: https://img.shields.io/pypi/pyversions/django-analytical.svg
:target: https://pypi.python.org/pypi/django-analytical
:alt: Python versions
.. |downloads| image:: https://img.shields.io/pypi/dm/django-analytical.svg
:alt: Monthly downloads from PyPI
:target: https://pypi.python.org/pypi/django-analytical
.. |license| image:: https://img.shields.io/pypi/l/django-analytical.svg
:alt: Software license
:target: https://github.com/jcassee/django-analytical/blob/master/LICENSE.txt
Expand Down
4 changes: 2 additions & 2 deletions analytical/templatetags/chartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
loadChartbeat : function() { oldonload(); loadChartbeat(); };
})();
</script>
"""
""" # noqa
DOMAIN_CONTEXT_KEY = 'chartbeat_domain'


Expand Down Expand Up @@ -80,7 +80,7 @@ def chartbeat_bottom(parser, token):
class ChartbeatBottomNode(Node):
def __init__(self):
self.user_id = get_required_setting('CHARTBEAT_USER_ID', USER_ID_RE,
"must be (a string containing) a number")
"must be (a string containing) a number")

def render(self, context):
config = {'uid': self.user_id}
Expand Down
14 changes: 8 additions & 6 deletions analytical/templatetags/clicky.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
})();
</script>
<noscript><p><img alt="Clicky" width="1" height="1" src="//in.getclicky.com/%(site_id)sns.gif" /></p></noscript>
"""

""" # noqa

register = Library()

Expand All @@ -52,8 +51,9 @@ def clicky(parser, token):

class ClickyNode(Node):
def __init__(self):
self.site_id = get_required_setting('CLICKY_SITE_ID', SITE_ID_RE,
"must be a (string containing) a number")
self.site_id = get_required_setting(
'CLICKY_SITE_ID', SITE_ID_RE,
"must be a (string containing) a number")

def render(self, context):
custom = {}
Expand All @@ -66,8 +66,10 @@ def render(self, context):
if identity is not None:
custom.setdefault('session', {})['username'] = identity

html = TRACKING_CODE % {'site_id': self.site_id,
'custom': json.dumps(custom, sort_keys=True)}
html = TRACKING_CODE % {
'site_id': self.site_id,
'custom': json.dumps(custom, sort_keys=True),
}
if is_internal_ip(context, 'CLICKY'):
html = disable_html(html, 'Clicky')
return html
Expand Down
16 changes: 9 additions & 7 deletions analytical/templatetags/google_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ def render(self, context):
source = DISPLAY_ADVERTISING_SOURCE
else:
source = DEFAULT_SOURCE
html = SETUP_CODE % {'property_id': self.property_id,
'commands': " ".join(commands),
'source_scheme': source[0],
'source_url': source[1]}
html = SETUP_CODE % {
'property_id': self.property_id,
'commands': " ".join(commands),
'source_scheme': source[0],
'source_url': source[1],
}
if is_internal_ip(context, 'GOOGLE_ANALYTICS'):
html = disable_html(html, 'Google Analytics')
return html
Expand All @@ -109,8 +111,7 @@ def _get_domain_commands(self, context):
domain = get_domain(context, 'google_analytics')
if domain is None:
raise AnalyticalException(
"tracking multiple domains with Google Analytics"
" requires a domain name")
"tracking multiple domains with Google Analytics requires a domain name")
commands.append(DOMAIN_CODE % domain)
commands.append(NO_ALLOW_HASH_CODE)
if tracking_type == TRACK_MULTIPLE_DOMAINS:
Expand Down Expand Up @@ -157,7 +158,8 @@ def _get_other_commands(self, context):
if siteSpeedSampleRate is not False:
value = decimal.Decimal(siteSpeedSampleRate)
if not 0 <= value <= 100:
raise AnalyticalException("'GOOGLE_ANALYTICS_SITE_SPEED_SAMPLE_RATE' must be >= 0 and <= 100")
raise AnalyticalException(
"'GOOGLE_ANALYTICS_SITE_SPEED_SAMPLE_RATE' must be >= 0 and <= 100")
commands.append(SITE_SPEED_SAMPLE_RATE_CODE % value.quantize(TWOPLACES))

sessionCookieTimeout = getattr(settings, 'GOOGLE_ANALYTICS_SESSION_COOKIE_TIMEOUT', False)
Expand Down
2 changes: 1 addition & 1 deletion analytical/templatetags/gosquared.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
w.addEventListener?w.addEventListener("load",gs,false):w.attachEvent("onload",gs);
})(window);
</script>
"""
""" # noqa
TOKEN_CODE = 'GoSquared.acct = "%s";'
IDENTIFY_CODE = 'GoSquared.UserName = "%s";'

Expand Down
6 changes: 3 additions & 3 deletions analytical/templatetags/hubspot.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
})(document,"script","hs-analytics",300000);
</script>
<!-- End of Async HubSpot Analytics Code -->
"""
""" # noqa

register = Library()

Expand All @@ -44,8 +44,8 @@ def hubspot(parser, token):

class HubSpotNode(Node):
def __init__(self):
self.portal_id = get_required_setting('HUBSPOT_PORTAL_ID',
PORTAL_ID_RE, "must be a (string containing a) number")
self.portal_id = get_required_setting('HUBSPOT_PORTAL_ID', PORTAL_ID_RE,
"must be a (string containing a) number")

def render(self, context):
html = TRACKING_CODE % {'portal_id': self.portal_id}
Expand Down
2 changes: 1 addition & 1 deletion analytical/templatetags/intercom.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
window.intercomSettings = %(settings_json)s;
</script>
<script>(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://static.intercomcdn.com/intercom.v1.js';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})()</script>
"""
""" # noqa

register = Library()

Expand Down
21 changes: 12 additions & 9 deletions analytical/templatetags/kiss_insights.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
SETUP_CODE = """
<script type="text/javascript">var _kiq = _kiq || []; %(commands)s</script>
<script type="text/javascript" src="//s3.amazonaws.com/ki.js/%(account_number)s/%(site_code)s.js" async="true"></script>
"""
""" # noqa
IDENTIFY_CODE = "_kiq.push(['identify', '%s']);"
SHOW_SURVEY_CODE = "_kiq.push(['showSurvey', %s]);"
SHOW_SURVEY_CONTEXT_KEY = 'kiss_insights_show_survey'
Expand Down Expand Up @@ -44,23 +44,26 @@ def kiss_insights(parser, token):
class KissInsightsNode(Node):
def __init__(self):
self.account_number = get_required_setting(
'KISS_INSIGHTS_ACCOUNT_NUMBER', ACCOUNT_NUMBER_RE,
"must be (a string containing) a number")
self.site_code = get_required_setting('KISS_INSIGHTS_SITE_CODE',
SITE_CODE_RE, "must be a string containing three characters")
'KISS_INSIGHTS_ACCOUNT_NUMBER', ACCOUNT_NUMBER_RE,
"must be (a string containing) a number")
self.site_code = get_required_setting(
'KISS_INSIGHTS_SITE_CODE', SITE_CODE_RE,
"must be a string containing three characters")

def render(self, context):
commands = []
identity = get_identity(context, 'kiss_insights')
if identity is not None:
commands.append(IDENTIFY_CODE % identity)
try:
commands.append(SHOW_SURVEY_CODE
% context[SHOW_SURVEY_CONTEXT_KEY])
commands.append(SHOW_SURVEY_CODE % context[SHOW_SURVEY_CONTEXT_KEY])
except KeyError:
pass
html = SETUP_CODE % {'account_number': self.account_number,
'site_code': self.site_code, 'commands': " ".join(commands)}
html = SETUP_CODE % {
'account_number': self.account_number,
'site_code': self.site_code,
'commands': " ".join(commands),
}
return html


Expand Down
21 changes: 13 additions & 8 deletions analytical/templatetags/kiss_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ def kiss_metrics(parser, token):

class KissMetricsNode(Node):
def __init__(self):
self.api_key = get_required_setting('KISS_METRICS_API_KEY',
API_KEY_RE,
"must be a string containing a 40-digit hexadecimal number")
self.api_key = get_required_setting(
'KISS_METRICS_API_KEY', API_KEY_RE,
"must be a string containing a 40-digit hexadecimal number")

def render(self, context):
commands = []
Expand All @@ -78,18 +78,23 @@ def render(self, context):
pass
try:
name, properties = context[EVENT_CONTEXT_KEY]
commands.append(EVENT_CODE % {'name': name,
'properties': json.dumps(properties, sort_keys=True)})
commands.append(EVENT_CODE % {
'name': name,
'properties': json.dumps(properties, sort_keys=True),
})
except KeyError:
pass
try:
properties = context[PROPERTY_CONTEXT_KEY]
commands.append(PROPERTY_CODE % {
'properties': json.dumps(properties, sort_keys=True)})
'properties': json.dumps(properties, sort_keys=True),
})
except KeyError:
pass
html = TRACKING_CODE % {'api_key': self.api_key,
'commands': " ".join(commands)}
html = TRACKING_CODE % {
'api_key': self.api_key,
'commands': " ".join(commands),
}
if is_internal_ip(context, 'KISS_METRICS'):
html = disable_html(html, 'KISSmetrics')
return html
Expand Down
14 changes: 9 additions & 5 deletions analytical/templatetags/mixpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
mixpanel.init('%(token)s');
%(commands)s
</script>
"""
""" # noqa
IDENTIFY_CODE = "mixpanel.identify('%s');"
IDENTIFY_PROPERTIES = "mixpanel.people.set(%s);"
EVENT_CODE = "mixpanel.track('%(name)s', %(properties)s);"
Expand Down Expand Up @@ -62,12 +62,16 @@ def render(self, context):
commands.append(IDENTIFY_CODE % identity)
try:
name, properties = context[EVENT_CONTEXT_KEY]
commands.append(EVENT_CODE % {'name': name,
'properties': json.dumps(properties, sort_keys=True)})
commands.append(EVENT_CODE % {
'name': name,
'properties': json.dumps(properties, sort_keys=True),
})
except KeyError:
pass
html = TRACKING_CODE % {'token': self._token,
'commands': " ".join(commands)}
html = TRACKING_CODE % {
'token': self._token,
'commands': " ".join(commands),
}
if is_internal_ip(context, 'MIXPANEL'):
html = disable_html(html, 'Mixpanel')
return mark_safe(html)
Expand Down
35 changes: 20 additions & 15 deletions analytical/templatetags/olark.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/*{literal}<![CDATA[*/ window.olark||(function(k){var g=window,j=document,a=g.location.protocol=="https:"?"https:":"http:",i=k.name,b="load",h="addEventListener";(function(){g[i]=function(){(c.s=c.s||[]).push(arguments)};var c=g[i]._={},f=k.methods.length;while(f--){(function(l){g[i][l]=function(){g[i]("call",l,arguments)}})(k.methods[f])}c.l=k.loader;c.i=arguments.callee;c.p={0:+new Date};c.P=function(l){c.p[l]=new Date-c.p[0]};function e(){c.P(b);g[i](b)}g[h]?g[h](b,e,false):g.attachEvent("on"+b,e);c.P(1);var d=j.createElement("script"),m=document.getElementsByTagName("script")[0];d.type="text/javascript";d.async=true;d.src=a+"//"+c.l;m.parentNode.insertBefore(d,m);c.P(2)})()})({loader:(function(a){return "static.olark.com/jsclient/loader1.js?ts="+(a?a[1]:(+new Date))})(document.cookie.match(/olarkld=([0-9]+)/)),name:"olark",methods:["configure","extend","declare","identify"]}); olark.identify('%(site_id)s');/*]]>{/literal}*/
%(extra_code)s
</script>
"""
""" # noqa
NICKNAME_CODE = "olark('api.chat.updateVisitorNickname', {snippet: '%s'});"
NICKNAME_CONTEXT_KEY = 'olark_nickname'
FULLNAME_CODE = "olark('api.visitor.updateFullName', {{fullName: '{0}'}});"
Expand All @@ -28,14 +28,16 @@
STATUS_CODE = "olark('api.chat.updateVisitorStatus', {snippet: %s});"
STATUS_CONTEXT_KEY = 'olark_status'
MESSAGE_CODE = "olark.configure('locale.%(key)s', \"%(msg)s\");"
MESSAGE_KEYS = set(["welcome_title", "chatting_title", "unavailable_title",
"busy_title", "away_message", "loading_title", "welcome_message",
"busy_message", "chat_input_text", "name_input_text",
"email_input_text", "offline_note_message", "send_button_text",
"offline_note_thankyou_text", "offline_note_error_text",
"offline_note_sending_text", "operator_is_typing_text",
"operator_has_stopped_typing_text", "introduction_error_text",
"introduction_messages", "introduction_submit_button_text"])
MESSAGE_KEYS = {
"welcome_title", "chatting_title", "unavailable_title",
"busy_title", "away_message", "loading_title", "welcome_message",
"busy_message", "chat_input_text", "name_input_text",
"email_input_text", "offline_note_message", "send_button_text",
"offline_note_thankyou_text", "offline_note_error_text",
"offline_note_sending_text", "operator_is_typing_text",
"operator_has_stopped_typing_text", "introduction_error_text",
"introduction_messages", "introduction_submit_button_text",
}

register = Library()

Expand All @@ -56,8 +58,9 @@ def olark(parser, token):

class OlarkNode(Node):
def __init__(self):
self.site_id = get_required_setting('OLARK_SITE_ID', SITE_ID_RE,
"must be a string looking like 'XXXX-XXX-XX-XXXX'")
self.site_id = get_required_setting(
'OLARK_SITE_ID', SITE_ID_RE,
"must be a string looking like 'XXXX-XXX-XX-XXXX'")

def render(self, context):
extra_code = []
Expand All @@ -76,13 +79,15 @@ def render(self, context):
except KeyError:
pass
try:
extra_code.append(STATUS_CODE %
json.dumps(context[STATUS_CONTEXT_KEY], sort_keys=True))
extra_code.append(STATUS_CODE % json.dumps(context[STATUS_CONTEXT_KEY],
sort_keys=True))
except KeyError:
pass
extra_code.extend(self._get_configuration(context))
html = SETUP_CODE % {'site_id': self.site_id,
'extra_code': " ".join(extra_code)}
html = SETUP_CODE % {
'site_id': self.site_id,
'extra_code': " ".join(extra_code),
}
return html

def _get_nickname(self, user):
Expand Down

0 comments on commit c7b14bd

Please sign in to comment.