Skip to content

make compatible with Django 1.9 #7

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 7 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
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ 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>
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
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
10 changes: 5 additions & 5 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 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
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