Skip to content

Commit

Permalink
Merge pull request #11 from joshyu/feat/django-42-compatible
Browse files Browse the repository at this point in the history
feat: add django 4.2 support, python 3.10 support
  • Loading branch information
FreemanPancake authored Mar 15, 2024
2 parents 0ce55d4 + bdb2943 commit b05c242
Show file tree
Hide file tree
Showing 21 changed files with 218 additions and 136 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.9
- name: Install flake8
run: pip install --upgrade flake8
- name: Run flake8
Expand All @@ -29,10 +29,10 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.9
- run: python -m pip install isort
- name: isort
uses: liskin/gh-problem-matcher-wrap@v1
with:
linters: isort
run: isort -c -rc -df ./
run: isort --check-only --diff ./
15 changes: 8 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,26 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ 3.7, 3.8, 3.9 ] # latest release minus two
python-version: [ 3.8, 3.9, '3.10' ]
requirements-file: [
dj22_cms40.txt,
dj32_cms40.txt,
dj42_cms40.txt,
]

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: 'tests/requirements/*.txt'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r tests/requirements/${{ matrix.requirements-file }}
python setup.py install
- name: Run coverage
run: coverage run setup.py test

- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v1
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Changelog

Unreleased
==========
* Introduced Django 4.2 support.
* Dropped Support for Django<3.1
* Dropped the dependency of `aldryn-translation-tools`
* Dropped support for python<3.8

1.0.2 (2023-02-24)
==================
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ include README.rst
include CHANGELOG.rst
recursive-include aldryn_redirects/locale *
recursive-include aldryn_redirects/migrations *
recursive-include aldryn_redirects/static *
recursive-include aldryn_redirects/templates *

recursive-exclude * *.pyc
103 changes: 87 additions & 16 deletions aldryn_redirects/admin.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
from aldryn_translation_tools.admin import AllTranslationsMixin
from django.conf import settings
from django.contrib import admin, messages
from django.forms import widgets
from django.http import HttpResponse
from django.shortcuts import redirect, render
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import gettext
from django.utils.translation import gettext_lazy as _
from django.utils.encoding import force_str
from django.utils.translation import gettext, gettext_lazy as _

from cms.utils.i18n import get_current_language
from cms.utils.urlutils import admin_reverse

from parler.admin import TranslatableAdmin
from tablib import Dataset

from .forms import (RedirectsImportForm, StaticRedirectForm,
StaticRedirectsImportForm)
from .models import (Redirect, StaticRedirect,
StaticRedirectInboundRouteQueryParam)
from .forms import (
RedirectsImportForm,
StaticRedirectForm,
StaticRedirectsImportForm,
)
from .models import (
Redirect,
StaticRedirect,
StaticRedirectInboundRouteQueryParam,
)


class DeletionMixin():
actions = ['delete_selected']

@admin.action(
description=_('Delete selected objects')
)
def delete_selected(self, request, queryset):
max_items_deletion = getattr(settings, 'DATA_UPLOAD_MAX_NUMBER_FIELDS', 1000) # COMPAT: Django<1.10

Expand All @@ -35,9 +48,70 @@ def delete_selected(self, request, queryset):
object_label = self.opts.verbose_name_plural if deleted_qty > 1 else self.opts.verbose_name
msg = _('Successfully deleted {qty} {object_label}.').format(qty=deleted_qty, object_label=object_label)
self.message_user(request, msg)
delete_selected.short_description = _('Delete selected objects')


class AllTranslationsMixin(object):

@property
def media(self):
return super().media + widgets.Media(
css={'all': ('css/admin/all-translations-mixin.css', ), }
)

@admin.display(
description='Translations'
)
def all_translations(self, obj):
"""
Adds a property to the list_display that lists all translations with
links directly to their change forms. Includes CSS to style the links
to looks like tags with color indicating current language, active and
inactive translations.
A similar capability is in HVAD, and now there is this for
Parler-based projects.
"""
available = list(obj.get_available_languages())
current = get_current_language()
langs = []
for code, lang_name in settings.LANGUAGES:
classes = ["lang-code", ]
title = force_str(lang_name)
if code == current:
classes += ["current", ]
if code in available:
classes += ["active", ]
title += " (translated)"
else:
title += " (untranslated)"
change_form_url = admin_reverse(
'{app_label}_{model_name}_change'.format(
app_label=obj._meta.app_label.lower(),
model_name=obj.__class__.__name__.lower(),
), args=(obj.id, )
)
link = '<a class="{classes}" href="{url}?language={code}" title="{title}">{code}</a>'.format(
classes=' '.join(classes),
url=change_form_url,
code=code,
title=title,
)
langs.append(link)
return ''.join(langs)

def get_list_display(self, request):
"""
Unless the the developer has already placed "all_translations" in the
list_display list (presumably specifically where she wants it), append
the list of translations to the end.
"""
list_display = super().get_list_display(request)
if 'all_translations' not in list_display:
list_display = list(list_display) + ['all_translations', ]
return list_display


@admin.register(Redirect)
class RedirectAdmin(DeletionMixin, AllTranslationsMixin, TranslatableAdmin):
list_display = ('old_path',)
list_filter = ('site',)
Expand All @@ -47,12 +121,12 @@ class RedirectAdmin(DeletionMixin, AllTranslationsMixin, TranslatableAdmin):
export_headers = ['Domain', 'Old', 'New', 'Language']

def get_urls(self):
from django.conf.urls import url
from django.urls import re_path

def pattern(regex, fn, name):
args = [regex, self.admin_site.admin_view(fn)]
url_name = "%s_%s_%s" % (self.opts.app_label, self.opts.model_name, name)
return url(*args, name=url_name)
return re_path(*args, name=url_name)

url_patterns = [
pattern(r'export/$', self.export_view, 'export'),
Expand Down Expand Up @@ -130,6 +204,7 @@ class StaticRedirectInboundRouteQueryParamInline(admin.TabularInline):
extra = 1


@admin.register(StaticRedirect)
class StaticRedirectAdmin(DeletionMixin, admin.ModelAdmin):
inlines = [StaticRedirectInboundRouteQueryParamInline]
filter_horizontal = ('sites',)
Expand All @@ -143,12 +218,12 @@ class StaticRedirectAdmin(DeletionMixin, admin.ModelAdmin):
export_headers = ['domain', 'inbound_route', 'outbound_route']

def get_urls(self):
from django.conf.urls import url
from django.urls import re_path

def pattern(regex, fn, name):
args = [regex, self.admin_site.admin_view(fn)]
url_name = "%s_%s_%s" % (self.opts.app_label, self.opts.model_name, name)
return url(*args, name=url_name)
return re_path(*args, name=url_name)

url_patterns = [
pattern(r'export/$', self.export_view, 'export'),
Expand Down Expand Up @@ -215,7 +290,3 @@ def import_view(self, request):
'errors': form.errors,
}
return render(request, 'admin/aldryn_redirects/staticredirect/import_form.html', context)


admin.site.register(Redirect, RedirectAdmin)
admin.site.register(StaticRedirect, StaticRedirectAdmin)
1 change: 1 addition & 0 deletions aldryn_redirects/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django import forms
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _

from tablib import Dataset

from .importers import RedirectImporter, StaticRedirectImporter
Expand Down
10 changes: 6 additions & 4 deletions aldryn_redirects/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from django.contrib.sites.models import Site
from django.db import models
from django.urls import reverse
from django.utils.translation import gettext
from django.utils.translation import gettext_lazy as _
from django.utils.translation import gettext, gettext_lazy as _

from parler.models import TranslatableModel, TranslatedFields
from six.moves.urllib.parse import urljoin, urlparse

from .managers import (StaticRedirectInboundRouteQueryParamManager,
StaticRedirectManager)
from .managers import (
StaticRedirectInboundRouteQueryParamManager,
StaticRedirectManager,
)
from .utils import add_query_params_to_url
from .validators import validate_inbound_route, validate_outbound_route

Expand Down
81 changes: 0 additions & 81 deletions aldryn_redirects/south_migrations/0001_initial.py

This file was deleted.

Empty file.
23 changes: 23 additions & 0 deletions aldryn_redirects/static/css/admin/all-translations-mixin.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
a.lang-code {
background-color: #BFBFBF; /* hsl(0, 0%, 75%); */
border-radius: 3px;
color: #fff !important;
display: inline-block;
font-size: 0.75em;
letter-spacing: 0.05em;
line-height: 1em;
margin-right: 0.25em;
padding: 3px;
text-decoration: none;
text-transform: uppercase;
}
a.lang-code.active {
background-color: #3B99FC; /* hsl(211, 97%, 61%) */
}
a.lang-code.current {
background-color: #999999; /* hsl(0, 0%, 60%); */
font-weight: bold;
}
a.lang-code.current.active {
background-color: #3178BE; /* hsl(211, 59%, 48%) */
}
1 change: 1 addition & 0 deletions aldryn_redirects/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _

from six.moves.urllib.parse import urlparse


Expand Down
Loading

0 comments on commit b05c242

Please sign in to comment.