Skip to content
This repository was archived by the owner on May 13, 2025. It is now read-only.

Commit af2c9c0

Browse files
committed
Merge branch 'master' into django-rq
2 parents e9d2cf4 + 9cb5269 commit af2c9c0

File tree

8 files changed

+47
-15
lines changed

8 files changed

+47
-15
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
*.egg-info
33
dist/
44
venv/
5+
build/
6+
.vscode/

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
===============
1+
===================
22
wagtail-linkchecker
3-
===============
3+
===================
44

55
A tool/plugin to assist with finding broken links on your wagtail site.
66
This tool works asynchronously using django-rq.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setup(
1212
name='wagtail-linkchecker',
13-
version='0.4.1',
13+
version='0.5.3',
1414
description="A tool to assist with finding broken links on your wagtail site.",
1515
long_description=readme,
1616
author='Samuel Mendes',

wagtaillinkchecker/management/commands/linkcheck.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
from django.core.management.base import BaseCommand
55
from django.template.loader import render_to_string
66

7-
from wagtail import __version__ as WAGTAIL_VERSION
8-
97
from wagtaillinkchecker.scanner import broken_link_scan
108
from wagtaillinkchecker.models import ScanLink
9+
from wagtaillinkchecker import utils
1110

12-
if WAGTAIL_VERSION >= '2.0':
11+
if utils.is_wagtail_version_more_than_equal_to_2_0():
1312
from wagtail.core.models import PageRevision, Site
1413
else:
1514
from wagtail.wagtailcore.models import PageRevision, Site

wagtaillinkchecker/models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
from django.dispatch import receiver
88
from django.template.loader import render_to_string
99
from django.utils.translation import ugettext_lazy as _
10-
from wagtail import __version__ as WAGTAIL_VERSION
1110

12-
if WAGTAIL_VERSION >= '2.0':
11+
from wagtaillinkchecker import utils
12+
13+
if utils.is_wagtail_version_more_than_equal_to_2_0():
1314
from wagtail.core.models import Site
1415
from wagtail.core.models import Page
1516
else:

wagtaillinkchecker/utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import re
2+
from wagtail import __version__ as WAGTAIL_VERSION
3+
4+
5+
def is_wagtail_version_more_than_equal_to_2_5():
6+
expression = '^((2.([5-9]{1,}|([1-9]{1,}[0-9]{1,}))(.\d+)*)|(([3-9]{1,})(.\d+)*))$'
7+
8+
return re.search(expression, WAGTAIL_VERSION)
9+
10+
11+
def is_wagtail_version_more_than_equal_to_2_0():
12+
expression = '^((2.([0-9]{1,}|([1-9]{1,}[0-9]{1,}))(.\d+)*)|(([3-9]{1,})(.\d+)*))$'
13+
14+
return re.search(expression, WAGTAIL_VERSION)
15+

wagtaillinkchecker/views.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@
44

55
from django.shortcuts import get_object_or_404
66
from django.shortcuts import redirect, render
7+
8+
try:
9+
from django.utils.lru_cache import lru_cache
10+
except ModuleNotFoundError:
11+
from functools import lru_cache
12+
713
from django.utils.translation import ugettext_lazy as _
8-
from wagtail import __version__ as WAGTAIL_VERSION
914

1015
from wagtaillinkchecker.forms import SitePreferencesForm
1116
from wagtaillinkchecker.models import SitePreferences, Scan
1217
from wagtaillinkchecker.pagination import paginate
1318
from wagtaillinkchecker.scanner import broken_link_scan
19+
from wagtaillinkchecker import utils
1420

15-
if WAGTAIL_VERSION >= '2.0':
21+
if utils.is_wagtail_version_more_than_equal_to_2_0():
1622
from wagtail.admin import messages
1723
from wagtail.admin.edit_handlers import (ObjectList,
1824
extract_panel_definitions_from_model_class)
@@ -27,7 +33,11 @@
2733
@lru_cache()
2834
def get_edit_handler(model):
2935
panels = extract_panel_definitions_from_model_class(model, ['site'])
30-
return ObjectList(panels).bind_to_model(model)
36+
37+
if utils.is_wagtail_version_more_than_equal_to_2_5():
38+
return ObjectList(panels).bind_to(model=model)
39+
else:
40+
return ObjectList(panels).bind_to_model(model)
3141

3242

3343
def scan(request, scan_pk):
@@ -83,7 +93,12 @@ def settings(request):
8393
messages.error(request, _('The form could not be saved due to validation errors'))
8494
else:
8595
form = SitePreferencesForm(instance=instance)
86-
edit_handler = object_list.bind_to_instance(instance=SitePreferences, form=form, request=request)
96+
if utils.is_wagtail_version_more_than_equal_to_2_5():
97+
edit_handler = object_list.bind_to(
98+
instance=SitePreferences, form=form, request=request)
99+
else:
100+
edit_handler = object_list.bind_to_instance(
101+
instance=SitePreferences, form=form, request=request)
87102

88103
return render(request, 'wagtaillinkchecker/settings.html', {
89104
'form': form,

wagtaillinkchecker/wagtail_hooks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
from django import __version__ as DJANGO_VERSION
44
from django.conf.urls import include, url
55
from django.utils.translation import ugettext_lazy as _
6-
from wagtail import __version__ as WAGTAIL_VERSION
76

87
from wagtaillinkchecker import urls
8+
from wagtaillinkchecker import utils
99

10-
if DJANGO_VERSION >= '2.0':
10+
if utils.is_wagtail_version_more_than_equal_to_2_0():
1111
from django import urls as urlresolvers
1212
else:
1313
from django.core import urlresolvers
1414

15-
if WAGTAIL_VERSION >= '2.0':
15+
if utils.is_wagtail_version_more_than_equal_to_2_0():
1616
from wagtail.admin.menu import MenuItem
1717
from wagtail.core import hooks
1818
else:

0 commit comments

Comments
 (0)