Skip to content

Commit

Permalink
Updates for Django 4.
Browse files Browse the repository at this point in the history
* Test 4.2 and 5.0 in tox/GitHub.
* Switch from OSMGeoAdmin to GISModelAdmin
* Remove USE_L10N.
* Stop prefetching countries – this isn't needed because any single
  lookup can look it up, and any list fetches it separately in
  output_areas for the iterator. Django 5 will stop iterator() working
  with a prefetch_related() without a chunk size, we don't need this.
  • Loading branch information
dracos committed Jun 4, 2024
1 parent 8835262 commit e220c0f
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 24 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.9]
thing-to-test: [flake8, 3.2, 4.2]
python-version: ["3.10"]
thing-to-test: [flake8, 4.2, 5.0]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down
16 changes: 8 additions & 8 deletions mapit/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CodeInline(admin.TabularInline):
model = Code


class AreaAdmin(admin.OSMGeoAdmin):
class AreaAdmin(admin.GISModelAdmin):
list_filter = ('type', 'country')
list_display = ('name', 'type', 'country', 'generation_low', 'generation_high', 'parent_area', 'geometries_link')
search_fields = ('name', 'names__name', 'codes__code')
Expand All @@ -26,32 +26,32 @@ def geometries_link(self, obj):
return format_html('<a href="../geometry/?area=%d">Shapes</a>' % obj.id)


class GeometryAdmin(admin.OSMGeoAdmin):
class GeometryAdmin(admin.GISModelAdmin):
raw_id_fields = ('area',)


class GenerationAdmin(admin.OSMGeoAdmin):
class GenerationAdmin(admin.GISModelAdmin):
list_display = ('id', 'active', 'created', 'description')


class PostcodeAdmin(admin.OSMGeoAdmin):
class PostcodeAdmin(admin.GISModelAdmin):
search_fields = ['postcode']
raw_id_fields = ('areas',)


class TypeAdmin(admin.OSMGeoAdmin):
class TypeAdmin(admin.GISModelAdmin):
pass


class NameTypeAdmin(admin.OSMGeoAdmin):
class NameTypeAdmin(admin.GISModelAdmin):
pass


class CodeTypeAdmin(admin.OSMGeoAdmin):
class CodeTypeAdmin(admin.GISModelAdmin):
pass


class CountryAdmin(admin.OSMGeoAdmin):
class CountryAdmin(admin.GISModelAdmin):
pass


Expand Down
2 changes: 1 addition & 1 deletion mapit/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def __str__(self):
class AreaManager(models.Manager):
def get_queryset(self):
return super(AreaManager, self).get_queryset().select_related(
'type', 'country', 'parent_area').prefetch_related('countries')
'type', 'country', 'parent_area')

def by_location(self, location, query):
if not location:
Expand Down
4 changes: 0 additions & 4 deletions project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True

# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = False

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def read_file(filename):
scripts=['bin/mapit_make_css'],
include_package_data=True,
install_requires=[
'Django >= 2.2, <5.0',
'Django >= 4.2, <6.0',
'libsass >= 0.13.3',
'psycopg2',
'PyYAML',
Expand Down
12 changes: 6 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[tox]
envlist = flake8, py39-{3.2,4.2}
envlist = flake8, py310-{4.2,5.0}

[testenv]
commands =
flake8: flake8 mapit mapit_gb mapit_it mapit_no mapit_se mapit_za project
py39: python -W all -W ignore::PendingDeprecationWarning -m coverage run --source mapit manage.py test mapit mapit_gb
py310: python -W all -W ignore::PendingDeprecationWarning -m coverage run --source mapit manage.py test mapit mapit_gb
deps =
py39: coverage
py310: coverage
flake8: flake8
3.2: Django>=3.2,<4.0
4.2: Django>=4.2,<5.0
5.0: Django>=5.0,<5.1
passenv =
CFLAGS
PYTHONWARNINGS
Expand All @@ -21,10 +21,10 @@ skip_install = True

[gh-actions]
python =
3.9: flake8, py39
3.10: flake8, py310

[gh-actions:env]
THING_TO_TEST =
flake8: flake8
3.2: 3.2
4.2: 4.2
5.0: 5.0

0 comments on commit e220c0f

Please sign in to comment.