Skip to content

Commit

Permalink
Adding support for Django 2.0/2.1 (#1096)
Browse files Browse the repository at this point in the history
* Add support for Django 2.0/2.1
* Fix rendering canonical URL in change form
  • Loading branch information
vthaian authored Nov 15, 2018
1 parent 006a1cf commit 935c213
Show file tree
Hide file tree
Showing 69 changed files with 312 additions and 175 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ testenv1
node_modules/
.python-version
data
local.sqlite
24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ env:
- DJANGO="1.10" SWAP="yes"
- DJANGO="1.11" SWAP="no"
- DJANGO="1.11" SWAP="yes"
- DJANGO="2.0" SWAP="no"
- DJANGO="2.0" SWAP="yes"
- DJANGO="2.1" SWAP="no"
- DJANGO="2.1" SWAP="yes"

matrix:
include:
Expand Down Expand Up @@ -101,6 +105,26 @@ matrix:
python: "3.6"
env: DJANGO="master" SWAP="yes"

- os: linux
python: "3.4"
env: DJANGO="2.0" SWAP="no"
- os: linux
python: "3.5"
env: DJANGO="2.0" SWAP="no"
- os: linux
python: "3.6"
env: DJANGO="2.0" SWAP="no"

- os: linux
python: "3.4"
env: DJANGO="2.1" SWAP="no"
- os: linux
python: "3.5"
env: DJANGO="2.1" SWAP="no"
- os: linux
python: "3.6"
env: DJANGO="2.1" SWAP="no"

- os: linux
python: "3.4"
env: DJANGO="master" SWAP="no"
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
CHANGELOG
=========

1.3.3 (unreleased)
1.4.0 (unreleased)
------------------

* Added support for Django 2.0 and 2.1
* Enabled django-mptt 0.9
* Converted QueryDict to dict before manipulating in admin
* Hide 'Save as new' button in file admin
* Fixed history link for folder and image object
* Fixed rendering canonical URL in change form

1.3.2 (2018-04-23)
------------------
Expand Down
1 change: 0 additions & 1 deletion filer/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-

from django.contrib import admin

from ..models import Clipboard, File, Folder, FolderPermission, ThumbnailOption
Expand Down
6 changes: 3 additions & 3 deletions filer/admin/fileadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from __future__ import absolute_import

from django import forms
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext as _

from .. import settings
from ..models import File
from ..utils.compatibility import unquote
from ..utils.compatibility import reverse, unquote
from .permissions import PrimitivePermissionAwareModelAdmin
from .tools import AdminContext, admin_url_params_encoded, popup_status

Expand Down Expand Up @@ -143,7 +143,7 @@ def get_model_perms(self, request):
def display_canonical(self, instance):
canonical = instance.canonical_url
if canonical:
return '<a href="%s">%s</a>' % (canonical, canonical)
return mark_safe('<a href="%s">%s</a>' % (canonical, canonical))
else:
return '-'
display_canonical.allow_tags = True
Expand Down
5 changes: 3 additions & 2 deletions filer/admin/folderadmin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, unicode_literals

import itertools
Expand All @@ -14,7 +13,6 @@
from django.contrib.admin import helpers
from django.core.exceptions import PermissionDenied, ValidationError
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.core.urlresolvers import reverse
from django.db import models, router
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
Expand Down Expand Up @@ -42,6 +40,7 @@
capfirst,
get_delete_permission,
quote,
reverse,
unquote,
)
from ..utils.filer_easy_thumbnails import FilerActionThumbnailer
Expand Down Expand Up @@ -156,7 +155,9 @@ def response_change(self, request, obj):

def render_change_form(self, request, context, add=False, change=False,
form_url='', obj=None):
info = self.model._meta.app_label, self.model._meta.model_name
extra_context = {'show_delete': True,
'history_url': 'admin:%s_%s_history' % info,
'is_popup': popup_status(request),
'filer_admin_context': AdminContext(request)}
context.update(extra_context)
Expand Down
8 changes: 7 additions & 1 deletion filer/admin/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ def clean_rename_format(self):

class ResizeImagesForm(forms.Form, AsPWithHelpMixin):
if 'cmsplugin_filer_image' in settings.INSTALLED_APPS:
thumbnail_option = models.ForeignKey(ThumbnailOption, null=True, blank=True, verbose_name=_("thumbnail option")).formfield()
thumbnail_option = models.ForeignKey(
ThumbnailOption,
null=True,
blank=True,
verbose_name=_("thumbnail option"),
on_delete=models.CASCADE,
).formfield()
width = models.PositiveIntegerField(_("width"), null=True, blank=True).formfield(widget=widgets.AdminIntegerFieldWidget)
height = models.PositiveIntegerField(_("height"), null=True, blank=True).formfield(widget=widgets.AdminIntegerFieldWidget)
crop = models.BooleanField(_("crop"), default=True).formfield()
Expand Down
2 changes: 1 addition & 1 deletion filer/admin/imageadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from __future__ import absolute_import

from django import forms
from django.utils.translation import string_concat
from django.utils.translation import ugettext as _
from django.utils.translation import ugettext_lazy

from ..settings import FILER_IMAGE_MODEL
from ..thumbnail_processors import normalize_subject_location
from ..utils.compatibility import string_concat
from ..utils.loader import load_model
from .fileadmin import FileAdmin

Expand Down
3 changes: 1 addition & 2 deletions filer/admin/patched/admin_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
from collections import defaultdict

from django.contrib.auth import get_permission_codename
from django.core.urlresolvers import NoReverseMatch, reverse
from django.db import models
from django.db.models.deletion import Collector
from django.utils.html import format_html
from django.utils.text import capfirst

from ...utils.compatibility import quote
from ...utils.compatibility import NoReverseMatch, quote, reverse

try:
from django.utils.encoding import force_text
Expand Down
6 changes: 5 additions & 1 deletion filer/admin/permissionadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ class PermissionAdmin(admin.ModelAdmin):
def formfield_for_foreignkey(self, db_field, request, **kwargs):
db = kwargs.get('using')
if db_field.name == 'folder':
kwargs['widget'] = folder.AdminFolderWidget(db_field.rel, self.admin_site, using=db)
try:
remote = db_field.remote_field
except AttributeError:
remote = db_field.rel
kwargs['widget'] = folder.AdminFolderWidget(remote, self.admin_site, using=db)
return super(PermissionAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)

def get_model_perms(self, request):
Expand Down
3 changes: 2 additions & 1 deletion filer/admin/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from __future__ import absolute_import

from django.contrib import admin
from django.core.urlresolvers import reverse

from ..utils.compatibility import reverse


class PrimitivePermissionAwareModelAdmin(admin.ModelAdmin):
Expand Down
8 changes: 3 additions & 5 deletions filer/contrib/django_cms/cms_toolbars.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# -*- coding: utf-8 -*-

from __future__ import unicode_literals

from django.core.urlresolvers import reverse
from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _

from cms.cms_toolbars import ADMIN_MENU_IDENTIFIER, ADMINISTRATION_BREAK
from cms.toolbar.items import Break
from cms.toolbar_base import CMSToolbar
from cms.toolbar_pool import toolbar_pool
from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _
from filer.utils.compatibility import reverse

SHORTCUTS_BREAK = 'Shortcuts Break'

Expand Down
8 changes: 5 additions & 3 deletions filer/fields/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
from django import forms
from django.contrib.admin.sites import site
from django.contrib.admin.widgets import ForeignKeyRawIdWidget
from django.core.urlresolvers import reverse
from django.db import models
from django.template.loader import render_to_string
from django.utils.http import urlencode
from django.utils.safestring import mark_safe

from .. import settings as filer_settings
from ..models import File
from ..utils.compatibility import LTE_DJANGO_1_8, truncate_words
from ..utils.compatibility import LTE_DJANGO_1_8, reverse, truncate_words
from ..utils.model_label import get_model_label

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -134,7 +133,10 @@ def formfield(self, **kwargs):
# while letting the caller override them.
defaults = {
'form_class': self.default_form_class,
'rel': self.rel,
}
try:
defaults['rel'] = self.remote_field
except AttributeError:
defaults['rel'] = self.rel
defaults.update(kwargs)
return super(FilerFileField, self).formfield(**defaults)
17 changes: 5 additions & 12 deletions filer/fields/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
from django import forms
from django.contrib.admin.sites import site
from django.contrib.admin.widgets import ForeignKeyRawIdWidget
from django.core.urlresolvers import reverse
from django.db import models
from django.template.loader import render_to_string
from django.utils.http import urlencode
from django.utils.safestring import mark_safe

from ..models import Folder
from ..utils.compatibility import truncate_words
from ..utils.compatibility import reverse, truncate_words
from ..utils.model_label import get_model_label


Expand Down Expand Up @@ -125,16 +124,10 @@ def formfield(self, **kwargs):
# while letting the caller override them.
defaults = {
'form_class': self.default_form_class,
'rel': self.rel,
}
try:
defaults['rel'] = self.remote_field
except AttributeError:
defaults['rel'] = self.rel
defaults.update(kwargs)
return super(FilerFolderField, self).formfield(**defaults)

def south_field_triple(self):
"Returns a suitable description of this field for South."
# We'll just introspect ourselves, since we inherit.
from south.modelsinspector import introspector
field_class = "django.db.models.fields.related.ForeignKey"
args, kwargs = introspector(self)
# That's our definition!
return (field_class, args, kwargs)
1 change: 0 additions & 1 deletion filer/management/commands/generate_thumbnails.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-

from django.core.management.base import BaseCommand
from filer.models.imagemodels import Image

Expand Down
25 changes: 13 additions & 12 deletions filer/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

from django.db import models, migrations
import django.db.models.deletion
import filer.fields.multistorage_file
import filer.models.mixins
from filer.settings import FILER_IMAGE_MODEL
Expand Down Expand Up @@ -32,7 +33,7 @@ class Migration(migrations.Migration):
name='ClipboardItem',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('clipboard', models.ForeignKey(verbose_name='clipboard', to='filer.Clipboard')),
('clipboard', models.ForeignKey(verbose_name='clipboard', to='filer.Clipboard', on_delete=django.db.models.deletion.CASCADE)),
],
options={
'verbose_name': 'clipboard item',
Expand Down Expand Up @@ -73,8 +74,8 @@ class Migration(migrations.Migration):
('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)),
('owner', models.ForeignKey(related_name='filer_owned_folders', verbose_name='owner', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
('parent', models.ForeignKey(related_name='children', verbose_name='parent', blank=True, to='filer.Folder', null=True)),
('owner', models.ForeignKey(related_name='filer_owned_folders', verbose_name='owner', blank=True, to=settings.AUTH_USER_MODEL, null=True, on_delete=django.db.models.deletion.CASCADE)),
('parent', models.ForeignKey(related_name='children', verbose_name='parent', blank=True, to='filer.Folder', null=True, on_delete=django.db.models.deletion.CASCADE)),
],
options={
'ordering': ('name',),
Expand All @@ -93,9 +94,9 @@ class Migration(migrations.Migration):
('can_edit', models.SmallIntegerField(default=None, null=True, verbose_name='can edit', blank=True, choices=[(1, 'allow'), (0, 'deny')])),
('can_read', models.SmallIntegerField(default=None, null=True, verbose_name='can read', blank=True, choices=[(1, 'allow'), (0, 'deny')])),
('can_add_children', models.SmallIntegerField(default=None, null=True, verbose_name='can add children', blank=True, choices=[(1, 'allow'), (0, 'deny')])),
('folder', models.ForeignKey(verbose_name='folder', blank=True, to='filer.Folder', null=True)),
('group', models.ForeignKey(related_name='filer_folder_permissions', verbose_name='group', blank=True, to='auth.Group', null=True)),
('user', models.ForeignKey(related_name='filer_folder_permissions', verbose_name='user', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
('folder', models.ForeignKey(verbose_name='folder', blank=True, to='filer.Folder', null=True, on_delete=django.db.models.deletion.CASCADE)),
('group', models.ForeignKey(related_name='filer_folder_permissions', verbose_name='group', blank=True, to='auth.Group', null=True, on_delete=django.db.models.deletion.CASCADE)),
('user', models.ForeignKey(related_name='filer_folder_permissions', verbose_name='user', blank=True, to=settings.AUTH_USER_MODEL, null=True, on_delete=django.db.models.deletion.CASCADE)),
],
options={
'verbose_name': 'folder permission',
Expand All @@ -110,25 +111,25 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='file',
name='folder',
field=models.ForeignKey(related_name='all_files', verbose_name='folder', blank=True, to='filer.Folder', null=True),
field=models.ForeignKey(related_name='all_files', verbose_name='folder', blank=True, to='filer.Folder', null=True, on_delete=django.db.models.deletion.CASCADE),
preserve_default=True,
),
migrations.AddField(
model_name='file',
name='owner',
field=models.ForeignKey(related_name='owned_files', verbose_name='owner', blank=True, to=settings.AUTH_USER_MODEL, null=True),
field=models.ForeignKey(related_name='owned_files', verbose_name='owner', blank=True, to=settings.AUTH_USER_MODEL, null=True, on_delete=django.db.models.deletion.CASCADE),
preserve_default=True,
),
migrations.AddField(
model_name='file',
name='polymorphic_ctype',
field=models.ForeignKey(related_name='polymorphic_filer.file_set', editable=False, to='contenttypes.ContentType', null=True),
field=models.ForeignKey(related_name='polymorphic_filer.file_set', editable=False, to='contenttypes.ContentType', null=True, on_delete=django.db.models.deletion.CASCADE),
preserve_default=True,
),
migrations.AddField(
model_name='clipboarditem',
name='file',
field=models.ForeignKey(verbose_name='file', to='filer.File'),
field=models.ForeignKey(verbose_name='file', to='filer.File', on_delete=django.db.models.deletion.CASCADE),
preserve_default=True,
),
migrations.AddField(
Expand All @@ -140,13 +141,13 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='clipboard',
name='user',
field=models.ForeignKey(related_name='filer_clipboards', verbose_name='user', to=settings.AUTH_USER_MODEL),
field=models.ForeignKey(related_name='filer_clipboards', verbose_name='user', to=settings.AUTH_USER_MODEL, on_delete=django.db.models.deletion.CASCADE),
preserve_default=True,
),
migrations.CreateModel(
name='Image',
fields=[
('file_ptr', models.OneToOneField(serialize=False, auto_created=True, to='filer.File', primary_key=True, parent_link=True)),
('file_ptr', models.OneToOneField(serialize=False, auto_created=True, to='filer.File', primary_key=True, parent_link=True, on_delete=django.db.models.deletion.CASCADE)),
('_height', models.IntegerField(null=True, blank=True)),
('_width', models.IntegerField(null=True, blank=True)),
('date_taken', models.DateTimeField(verbose_name='date taken', null=True, editable=False, blank=True)),
Expand Down
3 changes: 2 additions & 1 deletion filer/migrations/0002_auto_20150606_2003.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

from django.db import models, migrations
import django.db.models.deletion


class Migration(migrations.Migration):
Expand All @@ -14,7 +15,7 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='file',
name='polymorphic_ctype',
field=models.ForeignKey(related_name='polymorphic_filer.file_set+', editable=False, to='contenttypes.ContentType', null=True),
field=models.ForeignKey(related_name='polymorphic_filer.file_set+', editable=False, to='contenttypes.ContentType', null=True, on_delete=django.db.models.deletion.CASCADE),
preserve_default=True,
),
]
Loading

0 comments on commit 935c213

Please sign in to comment.