Skip to content
This repository was archived by the owner on Oct 2, 2024. It is now read-only.

Commit d3e9486

Browse files
committed
updated taxonomy to comply with new panel classes
1 parent 9a5ac69 commit d3e9486

File tree

5 files changed

+87
-29
lines changed

5 files changed

+87
-29
lines changed

.dockerignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
**/__pycache__
2+
**/.venv
3+
**/.classpath
4+
**/.dockerignore
5+
**/.git
6+
**/.gitignore
7+
**/.project
8+
**/.settings
9+
**/.toolstarget
10+
**/.vs
11+
**/.vscode
12+
**/*.*proj.user
13+
**/*.dbmdl
14+
**/*.jfm
15+
**/bin
16+
**/charts
17+
**/docker-compose*
18+
**/compose*
19+
**/Dockerfile*
20+
**/node_modules
21+
**/npm-debug.log
22+
**/obj
23+
**/secrets.dev.yaml
24+
**/values.dev.yaml
25+
LICENSE
26+
README.md

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ description = "Add React Taxonomy component to a wagtail page and store it as a
1414
classifiers = [
1515
"Environment :: Web Environment",
1616
"Framework :: Django",
17-
"Framework :: Django :: 2.2",
17+
"Framework :: Django :: 4.0",
1818
"Framework :: Wagtail",
19-
"Framework :: Wagtail :: 2",
19+
"Framework :: Wagtail :: 3",
2020
"Intended Audience :: Developers",
2121
"License :: OSI Approved :: MIT License",
2222
"Operating System :: OS Independent",

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Django~=4.0
2-
wagtail~=3.0
2+
wagtail~=3.0.3
33
psycopg2-binary>=<2.9.6
44
python-crontab>=2.5,<2.6
55
django-cors-headers>=3.5,<3.6

test_page/management/commands/load_test_data_fixtures.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ def handle(self, *args, **options):
3838
except Page.DoesNotExist:
3939
pass
4040
self.stdout.write(self.style.SUCCESS('DONE'))
41+
self.stdout.write(self.style.NOTICE('run python3 ./manage.py fixtree'))

wagtailreacttaxonomy/panels.py

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,15 @@
22

33
from django.template.loader import render_to_string
44
from django.utils.safestring import mark_safe
5+
from django.core.exceptions import ImproperlyConfigured
56

6-
from wagtail.admin.panels import FieldPanel
7+
from wagtail.admin.panels import FieldPanel,EditHandler
78

89
from .models import TaxonomyTerms
910

1011

1112
class TaxonomyPanel(FieldPanel):
12-
object_template = "wagtailadmin/panels/taxonomy_panel.html"
13-
field_template = "wagtailadmin/panels/taxonomy_panel.html"
1413

15-
def render_as_object(self):
16-
return mark_safe(render_to_string(self.object_template, {
17-
'self': self,
18-
self.TEMPLATE_VAR: self,
19-
'field': self.bound_field,
20-
'taxonomy_terms_json': self.load_taxonomy_terms(),
21-
'taxonomy_terms_error_message': self.taxonomy_terms_error_message,
22-
}))
23-
24-
def load_taxonomy_terms(self):
25-
taxonomy_terms_json = None
26-
try:
27-
data = TaxonomyTerms.objects.get(taxonomy_id=self.taxonomy_terms_id)
28-
try:
29-
json.loads(data.terms_json)
30-
except json.decoder.JSONDecodeError:
31-
self.taxonomy_terms_error_message = '"Taxonomy Terms" json wrong format'
32-
taxonomy_terms_json = data.terms_json
33-
except TaxonomyTerms.DoesNotExist:
34-
self.taxonomy_terms_error_message = 'No "Taxonomy Terms" for this id: "{}"'.format(
35-
self.taxonomy_terms_id
36-
)
37-
return taxonomy_terms_json
3814

3915
def __init__(self, field_name, taxonomy_terms_id, *args, **kwargs):
4016
super().__init__(field_name, *args, **kwargs)
@@ -49,6 +25,61 @@ def clone_kwargs(self):
4925
widget=self.widget if hasattr(self, 'widget') else None,
5026
)
5127
return kwargs
28+
29+
def get_bound_panel(self, instance=None, request=None, form=None ):
30+
31+
if self.model is None:
32+
raise ImproperlyConfigured(
33+
"%s.bind_to_model(model) must be called before get_bound_panel"
34+
% type(self).__name__
35+
)
36+
37+
if not issubclass(self.BoundPanel, EditHandler.BoundPanel):
38+
raise ImproperlyConfigured(
39+
"%s.BoundPanel must be a subclass of EditHandler.BoundPanel"
40+
% type(self).__name__
41+
)
42+
43+
44+
return self.BoundPanel(
45+
panel=self, instance=instance, request=request, form=form, taxonomy_terms_id=self.taxonomy_terms_id
46+
)
47+
48+
class BoundPanel(FieldPanel.BoundPanel):
49+
50+
object_template = "wagtailadmin/panels/taxonomy_panel.html"
51+
field_template = "wagtailadmin/panels/taxonomy_panel.html"
52+
53+
def load_taxonomy_terms(self):
54+
taxonomy_terms_json = None
55+
try:
56+
data = TaxonomyTerms.objects.get(taxonomy_id=self.taxonomy_terms_id)
57+
try:
58+
json.loads(data.terms_json)
59+
except json.decoder.JSONDecodeError:
60+
self.taxonomy_terms_error_message = '"Taxonomy Terms" json wrong format'
61+
taxonomy_terms_json = data.terms_json
62+
except TaxonomyTerms.DoesNotExist:
63+
self.taxonomy_terms_error_message = 'No "Taxonomy Terms" for this id: "{}"'.format(
64+
self.taxonomy_terms_id
65+
)
66+
return taxonomy_terms_json
67+
68+
def __init__(self, panel, instance, request, form, taxonomy_terms_id):
69+
super().__init__(panel=panel, instance=instance, request=request, form=form)
70+
self.taxonomy_terms_id = taxonomy_terms_id
71+
self.taxonomy_terms_error_message = None
72+
73+
def render_as_object(self):
74+
return mark_safe(
75+
render_to_string(
76+
self.object_template, {
77+
'self': self,
78+
self.panel.TEMPLATE_VAR: self,
79+
'field': self.bound_field,
80+
'taxonomy_terms_json': self.load_taxonomy_terms(),
81+
'taxonomy_terms_error_message': self.taxonomy_terms_error_message,
82+
}))
5283

5384

5485
class PermissionsPanel(FieldPanel):

0 commit comments

Comments
 (0)