Skip to content

Fix for Python 3 #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
include = *django_js_error_hook*
20 changes: 20 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
sudo: false
language: python
env:
- DJANGO_VERSION="Django>=1.8,<1.9"
- DJANGO_VERSION="Django>=1.9,<1.10"
- DJANGO_VERSION='https://github.com/django/django/archive/master.tar.gz'
python:
- "2.7"
- "3.4"
before_script:
- pip install coverage coveralls
- pip install -q "$DJANGO_VERSION"
- python setup.py install
script:
- coverage run manage.py test --settings=settings
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When trying to run this locally I get a No file to run: 'manage.py' error.

Would you mind also adding a tox.ini file?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind it just works:

$ coverage run manage.py test --settings=settings
Creating test database for alias 'default'...
ERROR Got error: 
    details: Description of the error by the browser javascript engine.
    user: <UNAUTHENTICATED>
..
----------------------------------------------------------------------
Ran 2 tests in 0.030s

OK
Destroying test database for alias 'default'...

after_script:
- coveralls
matrix:
allow_failures:
- env: DJANGO_VERSION='https://github.com/django/django/archive/master.tar.gz'
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ Authors & contributors
* Rémy Hubscher <remy.hubscher@novapost.fr>
* Ionel Cristian Mărieș <contact@ionelmc.ro>
* Keryn Knight <keryn@kerynknight.com>
* Johannes Wilm <johannes@fiduswriter.org>
* Petr Dlouhý <petr.dlouhy@email.cz>
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Changelog
0.4 (unreleased)
----------------

- Nothing changed yet.
- Made usable with Django 1.9.


0.3 (2014-01-11)
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Then install the urls::

In your template, simply add the js_error_hook script::

<script type="text/javascript" src="{% url js-error-handler-js %}"></script>
<script type="text/javascript" src="{% url 'js-error-handler-js' %}"></script>

Now every Javascript error will be logged in your logging error stream. (Mail, Sentry, ...)

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.dev0
0.4.dev1
22 changes: 7 additions & 15 deletions demo/demoproject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
demoproject_dir = dirname(abspath(__file__))

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
# ('Your Name', 'your_email@example.com'),
Expand Down Expand Up @@ -82,12 +81,12 @@
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'k9i055*z@6@9$7xvyw(8y4sk_w0@1ltf2$y-^zu^&amp;wnlt1oez5'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': True,
},
]

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
Expand All @@ -99,18 +98,11 @@
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'demoproject.urls'
ROOT_URLCONF = 'urls'

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'demoproject.wsgi.application'

TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
join(demoproject_dir, 'templates'),
)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
Expand Down
3 changes: 1 addition & 2 deletions demo/demoproject/templates/error_test.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{% load url from future %}
<!DOCTYPE html>
<html lang="en">
<head>
Expand All @@ -9,7 +8,7 @@
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript" src="{% url 'js-error-handler-js' %}"></script>
</head>

<body>
A simple Page which voluntary triggers a Js error (Ctrl+U to see the script causing the error)
<script type="text/javascript">
Expand Down
10 changes: 5 additions & 5 deletions demo/demoproject/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.conf.urls import patterns, include, url
from django.conf.urls import include, url
from django.views.generic import TemplateView

urlpatterns = patterns('',
url(r'^$', TemplateView.as_view(template_name = "error_test.html")),
url(r'^error_hook/', include('django_js_error_hook.urls')),
)
urlpatterns = [
url('^$', TemplateView.as_view(template_name = "error_test.html")),
url('^error_hook/', include('django_js_error_hook.urls')),
]
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{% load url from future %}
(function() {
function getCookie(name) {
var nameEQ = name + "=";
Expand Down
12 changes: 6 additions & 6 deletions django_js_error_hook/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.conf.urls import patterns, url
from views import js_error_view, utils_js
from django.conf.urls import url
from .views import js_error_view, utils_js


urlpatterns = patterns("",
url(r"^$", js_error_view, name="js-error-handler"),
url(r"^utils.js$", utils_js, name="js-error-handler-js"),
)
urlpatterns = [
url("^$", js_error_view, name="js-error-handler"),
url("^utils.js$", utils_js, name="js-error-handler-js"),
]
17 changes: 15 additions & 2 deletions django_js_error_hook/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from distutils.version import StrictVersion

from django import get_version
from django.conf import settings
from django.http import HttpResponse
from django.views.decorators.cache import cache_page
Expand Down Expand Up @@ -29,8 +32,18 @@ class MimetypeTemplateView(TemplateView):
mimetype = "text/javascript"

def render_to_response(self, context, **response_kwargs):
"""Use self.mimetype to return the right mimetype"""
response_kwargs['mimetype'] = self.mimetype
"""
Before django 1.5 : 'mimetype'
From django 1.5 : 'content_type'

Add the parameter to return the right mimetype
"""
if StrictVersion(get_version()) < StrictVersion('1.5'):
mimetype_parameter = 'mimetype'
else:
mimetype_parameter = 'content_type'

response_kwargs[mimetype_parameter] = self.mimetype
return super(MimetypeTemplateView, self).render_to_response(context, **response_kwargs)

utils_js = cache_page(2 * 31 * 24 * 60 * 60)(MimetypeTemplateView.as_view()) #: Cache 2 months
Expand Down
13 changes: 13 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env python
import os
import sys

from django.core.management import execute_from_command_line

def main():
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "%s.settings" % __package__)
execute_from_command_line(sys.argv)


if __name__ == "__main__":
main()
165 changes: 165 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
# Django settings for demoproject project.
from os.path import abspath, dirname, join
demoproject_dir = dirname(abspath(__file__))

DEBUG = True

ADMINS = (
# ('Your Name', 'your_email@example.com'),
)

MANAGERS = ADMINS

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'test.sqlite3', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'America/Chicago'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True

# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = ''

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = ''

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = ''

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'

# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = 'k9i055*z@6@9$7xvyw(8y4sk_w0@1ltf2$y-^zu^&amp;wnlt1oez5'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': True,
},
]

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'django_js_error_hook.urls'

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'demoproject.wsgi.application'

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_js_error_hook',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)

# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
'simple': {
'format': '\033[22;32m%(levelname)s\033[0;0m %(message)s'
},
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'simple'
},
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
'javascript_error': {
'handlers': ['mail_admins', 'console'],
'level': 'ERROR',
'propagate': True,
},
}
}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def read_relative_file(filename):
README = read_relative_file('README.rst')
VERSION = read_relative_file('VERSION').strip()
PACKAGES = ['django_js_error_hook']
REQUIRES = ['django>=1.4']
REQUIRES = ['django>=1.9']


setup(name=NAME,
Expand Down