Skip to content

Commit

Permalink
django 4.2 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
benzkji committed Apr 20, 2023
1 parent 428b6c5 commit 7a5454a
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 27 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: [3.7, 3.8, 3.9]
python: [3.8, 3.9, "3.10", "3.11"]
steps:
- uses: actions/checkout@v2
- name: Setup Python ${{ matrix.python }}
Expand All @@ -25,15 +25,15 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: [3.9]
python: ["3.11"]
steps:
- uses: actions/checkout@v2
- name: Setup Python ${{ matrix.python }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Install flake8
run: pip install flake8
run: pip install flake8 flake8-print
- name: Run flake8
# Run tox using the version of Python in `PATH`
# run: tox -e py${{ matrix.python }}-${{ matrix.django }}
Expand Down
6 changes: 3 additions & 3 deletions filer_addons/filer_gui/admin/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import django
from django import forms
from django.conf.urls import url
from django.urls import re_path
from django.contrib import admin
# from django.core.urlresolvers import reverse
from django.http.response import JsonResponse
Expand Down Expand Up @@ -74,12 +74,12 @@ class FilerGuiAdmin(admin.ModelAdmin):

def get_urls(self):
urls = [
url(
re_path(
r'^file-detail-json/$',
self.admin_site.admin_view(self.file_detail_json_view),
name='file_detail_json_for_id'
),
url(
re_path(
r'^file-upload/$',
self.admin_site.admin_view(self.file_upload_view),
name='file_upload'
Expand Down
4 changes: 2 additions & 2 deletions filer_addons/filer_gui/admin/upload_inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.contrib import admin
from django.core.exceptions import ImproperlyConfigured
from django.forms import widgets
from django.utils.encoding import force_text
from django.utils.encoding import force_str
from django.utils.html import mark_safe
from django.utils.translation import gettext_lazy as _

Expand Down Expand Up @@ -81,7 +81,7 @@ def html_data_fields(self):
'file_field': self.get_file_field(),
'file_type': self.get_file_type(),
'messages': {
'generic_upload_error': force_text(_('Upload error')),
'generic_upload_error': force_str(_('Upload error')),
},
}
data_fields = '{} data-uploadinline=\'{}\''.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
{{ file.owner|default:"n/a" }}
</td>
<td class="column-size">
<span class="tiny"> ({{ file.size|filesize:"auto1000long" }}{% ifequal file.file_type "Image" %}, {{ file.width }}x{{ file.height }} px{% endifequal %})</span>
<span class="tiny"> ({{ file.size|filesize:"auto1000long" }}{% if file.file_type == "Image" %}, {{ file.width }}x{{ file.height }} px{% endif %})</span>
</td>
<td class="column-action">
<a href="{{ file.canonical_url }}"
Expand Down
2 changes: 0 additions & 2 deletions filer_addons/filer_gui/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from filer.models import File, Image


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def add_arguments(self, parser):
)

def handle(self, *args, **options):
print(File.objects.count())
self.stdout.write(File.objects.count())
if not options.get('force', False) and File.objects.count():
raise Exception('Must use --force, you have existing files in db!')

Expand All @@ -45,7 +45,7 @@ def handle(self, *args, **options):
self.prefix_public = filer_settings.FILER_STORAGES['public']['main']['UPLOAD_TO_PREFIX'] # noqa

def walk(absdir, reldir, db_folder):
print("walk %s" % db_folder)
self.stdout.write("walk %s" % db_folder)
storage = self.storage_public
child_dirs, files = storage.listdir(absdir)
for filename in files:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ def resolve_for_class(self, cls):
'sha1').order_by().filter(id__count__gt=1)
# keep the oldes, that is probably longest in search indexes...
duplicates = cls.objects.filter(sha1__in=temp).order_by('uploaded_at')
print("resolving duplicates in {}!".format(cls.__name__))
self.stdout.write("resolving duplicates in {}!".format(cls.__name__))
# relation business
model_links = [
rel.get_accessor_name()
for rel in model_get_all_related_objects(cls)
]
print(model_links)
self.stdout.write(model_links)
# state
done = {}
count = 0
Expand All @@ -45,21 +45,21 @@ def resolve_for_class(self, cls):
relation = getattr(file, link, None)
if getattr(relation, 'all', None):
for usage_obj in relation.all():
# print(relation.field.name)
# print(usage_obj)
# print(usage_obj.__class__)
# print(usage_obj.id)
# self.stdout.write(relation.field.name)
# self.stdout.write(usage_obj)
# self.stdout.write(usage_obj.__class__)
# self.stdout.write(usage_obj.id)
setattr(usage_obj, relation.field.name,
cls.objects.get(id=done[file.sha1]))
usage_obj.save()
# DELETE
print("delete {}".format(file.path))
self.stdout.write("delete {}".format(file.path))
file.delete()
count += 1
else:
# first time, keep this file
done[file.sha1] = file.id
print("resolved {} duplicates in {}!".format(count, cls.__name__))
self.stdout.write("resolved {} duplicates in {}!".format(count, cls.__name__))


def model_get_all_related_objects(model):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.utils.encoding import force_text
from django.utils.encoding import force_str
from filer.models import File, Folder, Image

from .base import SubcommandsCommand
Expand Down Expand Up @@ -67,7 +67,7 @@ def unused_for_file_type(self, model_cls, **options):
amount = unused.count()
for file in unused:
if options['verbose']:
self.stdout.write(force_text(file))
self.stdout.write(force_str(file))
if options['delete']:
file.delete()
self.stdout.write(
Expand Down
4 changes: 2 additions & 2 deletions filer_addons/tests/testapp/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.conf import settings
from django.conf.urls import url
from django.urls import re_path
from django.contrib import admin
from django.conf.urls.static import static

Expand All @@ -8,7 +8,7 @@


urlpatterns = [
url(
re_path(
r'^admin/',
admin.site.urls
),
Expand Down
12 changes: 10 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@

[tox]
envlist = py{37,38,39}-django{32}-filer{20x,21x}-django-polymorphic{new}, py{37,38,39}-django{22}-filer{16x}-django-polymorphic{old}
envlist =
py{38,39,310,311}-django{42}-filer{22x}-django-polymorphic{new}
py{38,39,310,311}-django{32}-filer{20x,21x}-django-polymorphic{new}
py{38,39,310}-django{22}-filer{16x}-django-polymorphic{old}

[gh-actions]
python =
3.7: py37
3.8: py38
3.9: py39
3.10: py310
3.11: py311

[testenv]
commands = python manage.py test
Expand All @@ -17,10 +21,14 @@ deps =
django-polymorphic-old: django-polymorphic==2.0.1
django-polymorphic-new: django-polymorphic
coverage
reportlab
svglib
django-coverage
filer142: django-filer==1.4.2
filer16x: django-filer<1.7
filer20x: django-filer<2.1
filer21x: django-filer<2.2
filer22x: django-filer<2.3
django22: django>=2.2,<3.0
django32: django>=3.2,<4.0
django42: django>=4.2,<5.0

0 comments on commit 7a5454a

Please sign in to comment.