Skip to content

Commit ec0e894

Browse files
committed
Move the jquery path logic into a template tag.
1 parent 404cb11 commit ec0e894

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

django_rq/templates/django_rq/jobs.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% extends "admin/base_site.html" %}
22

3-
{% load admin_static %}
3+
{% load admin_static jquery_path %}
44

55
{% block extrastyle %}
66
{{ block.super }}
@@ -9,7 +9,7 @@
99

1010
{% block extrahead %}
1111
{{ block.super }}
12-
<script type="text/javascript" src="{% static jquery_path %}"></script>
12+
<script type="text/javascript" src="{% get_jquery_path as jquery_path %}{% static jquery_path %}"></script>
1313
<script type="text/javascript" src="{% static "admin/js/jquery.init.js" %}"></script>
1414
<script type="text/javascript" src="{% static "admin/js/actions.js" %}"></script>
1515
<script type="text/javascript">

django_rq/templatetags/__init__.py

Whitespace-only changes.

django_rq/templatetags/jquery_path.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from distutils.version import LooseVersion
2+
from django import template
3+
from django.utils.version import get_version
4+
5+
6+
register = template.Library()
7+
8+
if LooseVersion(get_version()) >= LooseVersion('1.9'):
9+
JQUERY_PATH = 'admin/js/vendor/jquery/jquery.js'
10+
11+
# `assignment_tag` is deprecated as of 1.9, `simple_tag` should be used
12+
tag_decorator = register.simple_tag
13+
else:
14+
JQUERY_PATH = 'admin/js/jquery.js'
15+
tag_decorator = register.assignment_tag
16+
17+
18+
@register.assignment_tag
19+
def get_jquery_path():
20+
return JQUERY_PATH

django_rq/views.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
from __future__ import division
22

3-
from distutils.version import StrictVersion
43
from math import ceil
54

65
from django.contrib import messages
76
from django.contrib.admin.views.decorators import staff_member_required
87
from django.http import Http404
98
from django.shortcuts import redirect, render
10-
from django.utils.version import get_main_version
119

1210
from redis.exceptions import ResponseError
1311
from rq import requeue_job, Worker
@@ -20,12 +18,6 @@
2018
from .settings import QUEUES_LIST
2119

2220

23-
if StrictVersion(get_main_version()) >= StrictVersion('1.9'):
24-
JQUERY_PATH = 'admin/js/vendor/jquery/jquery.js'
25-
else:
26-
JQUERY_PATH = 'admin/js/jquery.js'
27-
28-
2921
@staff_member_required
3022
def stats(request):
3123
queues = []
@@ -92,7 +84,6 @@ def jobs(request, queue_index):
9284
'page': page,
9385
'page_range': page_range,
9486
'job_status': 'Queued',
95-
'jquery_path': JQUERY_PATH,
9687
}
9788
return render(request, 'django_rq/jobs.html', context_data)
9889

@@ -132,7 +123,6 @@ def finished_jobs(request, queue_index):
132123
'page': page,
133124
'page_range': page_range,
134125
'job_status': 'Finished',
135-
'jquery_path': JQUERY_PATH,
136126
}
137127
return render(request, 'django_rq/jobs.html', context_data)
138128

@@ -172,7 +162,6 @@ def started_jobs(request, queue_index):
172162
'page': page,
173163
'page_range': page_range,
174164
'job_status': 'Started',
175-
'jquery_path': JQUERY_PATH,
176165
}
177166
return render(request, 'django_rq/jobs.html', context_data)
178167

@@ -212,7 +201,6 @@ def deferred_jobs(request, queue_index):
212201
'page': page,
213202
'page_range': page_range,
214203
'job_status': 'Deferred',
215-
'jquery_path': JQUERY_PATH,
216204
}
217205
return render(request, 'django_rq/jobs.html', context_data)
218206

0 commit comments

Comments
 (0)