Skip to content
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

Adds compatibility to (at least) Django 3.2 #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 6 additions & 5 deletions fancytree/widgets.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections import ChainMap
from itertools import chain

from django import forms
Expand All @@ -6,7 +7,7 @@
from django.utils.encoding import force_text
from django.utils.html import conditional_escape
from django.utils.safestring import mark_safe
from django.utils.datastructures import MultiValueDict, MergeDict
from django.utils.datastructures import MultiValueDict
from mptt.templatetags.mptt_tags import cache_tree_children

try:
Expand All @@ -21,7 +22,7 @@ def get_doc(node, values):
if hasattr(node, "name"):
name = node.name
else:
name = unicode(node)
name = str(node)
doc = {"title": name, "key": node.pk}
if str(node.pk) in values:
doc['selected'] = True
Expand Down Expand Up @@ -51,17 +52,17 @@ def __init__(self, attrs=None, choices=(), queryset=None, select_mode=2):
self.choices = list(choices)

def value_from_datadict(self, data, files, name):
if isinstance(data, (MultiValueDict, MergeDict)) and self.select_mode != 1:
if isinstance(data, (MultiValueDict, ChainMap)) and self.select_mode != 1:
return data.getlist(name)
return data.get(name, None)

def render(self, name, value, attrs=None, choices=()):
def render(self, name, value, attrs=None, choices=(), renderer=None):
if value is None:
value = []
if not isinstance(value, (list, tuple)):
value = [value]
has_id = attrs and 'id' in attrs
final_attrs = self.build_attrs(attrs, name=name)
final_attrs = self.build_attrs(attrs, {"name": name})
if has_id:
output = [u'<div id="%s"></div>' % attrs['id']]
id_attr = u' id="%s_checkboxes"' % (attrs['id'])
Expand Down
4 changes: 2 additions & 2 deletions treewidget/apps/categories/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=50)),
('slug', django_extensions.db.fields.AutoSlugField(editable=False, populate_from=b'name', blank=True, overwrite=True)),
('slug', django_extensions.db.fields.AutoSlugField(editable=False, populate_from='name', blank=True, overwrite=True)),
('url', models.TextField(editable=False)),
('lft', models.PositiveIntegerField(editable=False, db_index=True)),
('rght', models.PositiveIntegerField(editable=False, db_index=True)),
('tree_id', models.PositiveIntegerField(editable=False, db_index=True)),
('level', models.PositiveIntegerField(editable=False, db_index=True)),
('parent', models.ForeignKey(related_name='children', blank=True, to='categories.Category', null=True)),
('parent', models.ForeignKey(related_name='children', blank=True, to='categories.Category', null=True, on_delete=models.CASCADE)),
],
options={
'ordering': ('tree_id', 'lft'),
Expand Down
7 changes: 4 additions & 3 deletions treewidget/apps/categories/models.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from django.db import models
from django.core.urlresolvers import reverse
from django.urls import reverse
from django_extensions.db.fields import AutoSlugField
import mptt

from urlparse import urljoin
from urllib.parse import urljoin

class Category(models.Model):
parent = models.ForeignKey('self',
null=True,
blank=True,
related_name='children')
related_name='children',
on_delete=models.CASCADE)
name = models.CharField(max_length=50)
slug = AutoSlugField(max_length=50,
overwrite=True,
Expand Down
25 changes: 18 additions & 7 deletions treewidget/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
# 'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
MIDDLEWARE = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
Expand All @@ -116,12 +116,23 @@

ROOT_URLCONF = 'urls'

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.
os.path.join(PROJECT_ROOT, 'templates'),
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(PROJECT_ROOT, 'templates'),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

INSTALLED_APPS = (
'django.contrib.auth',
Expand Down
28 changes: 8 additions & 20 deletions treewidget/urls.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
from django.conf.urls import patterns, include, url

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
url(r'^$', 'views.home', name='home'),
url(r'^selection/(?P<pk>\d)$', 'views.selection', name='selection'),
from django.urls import path

url(r'^admin/', include(admin.site.urls)),
)
from treewidget.views import home, selection

from django.conf import settings
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

urlpatterns += staticfiles_urlpatterns()
admin.autodiscover()

if settings.DEBUG:
urlpatterns += patterns('', (
r'^site_media/media/(?P<path>.*)$',
'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT}
),
)
urlpatterns = [
path("", home, name='home'),
path("selection/<pk>", selection, name='selection'),
path("admin/", admin.site.urls),
]