Skip to content

Commit 5170a2a

Browse files
authored
Upgrade django to 6.0.2 and all other dependencies (#5092)
* Upgrade django to 6.0.2 and all other dependencies * Fix tests
1 parent 2cffba3 commit 5170a2a

File tree

12 files changed

+72
-50
lines changed

12 files changed

+72
-50
lines changed

bims/admin.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def queryset(self, request, queryset):
248248
return queryset
249249

250250

251-
class LocationSiteAdmin(admin.GeoModelAdmin):
251+
class LocationSiteAdmin(admin.GISModelAdmin):
252252
change_list_template = 'admin/location_site_changelist.html'
253253
form = LocationSiteForm
254254
default_zoom = 5
@@ -483,16 +483,18 @@ class IUCNStatusAdmin(OrderedModelAdmin):
483483
)
484484

485485
def iucn_colour(self, obj):
486-
return format_html('<div style="background:%s; ' \
487-
'width: 50px; height: 15px;"></div>' % obj.colour)
486+
return format_html(
487+
'<div style="background:{}; width: 50px; height: 15px;"></div>',
488+
obj.colour)
488489

489490
def total_species(self, obj):
490491
total_taxa = Taxonomy.objects.filter(
491492
iucn_status=obj
492493
).count()
493494
return format_html(
494-
f'<a href="/admin/bims/taxonomy/?iucn_status__id__exact={obj.id}">'
495-
f'{total_taxa}</a>'
495+
'<a href="/admin/bims/taxonomy/?iucn_status__id__exact={}">'
496+
'{}</a>',
497+
obj.id, total_taxa
496498
)
497499

498500
iucn_colour.allow_tags = True
@@ -974,9 +976,9 @@ def merge_users(self, request, queryset):
974976
merge_users.short_description = 'Merge users'
975977

976978
def sass_accredited_status(self, obj):
977-
false_response = format_html(
979+
false_response = mark_safe(
978980
'<img src="/static/admin/img/icon-no.svg" alt="False">')
979-
true_response = format_html(
981+
true_response = mark_safe(
980982
'<img src="/static/admin/img/icon-yes.svg" alt="True">')
981983

982984
def role(self, obj):
@@ -995,9 +997,9 @@ def sass_accredited_status(self, obj, **kwargs):
995997
false_response = 'False'
996998
true_response = 'True'
997999
else:
998-
false_response = format_html(
1000+
false_response = mark_safe(
9991001
'<img src="/static/admin/img/icon-no.svg" alt="False">')
1000-
true_response = format_html(
1002+
true_response = mark_safe(
10011003
'<img src="/static/admin/img/icon-yes.svg" alt="True">')
10021004
try:
10031005
profile = BimsProfile.objects.get(user=obj)
@@ -1018,9 +1020,9 @@ def signed_up(self, obj, **kwargs):
10181020
false_response = 'False'
10191021
true_response = 'True'
10201022
else:
1021-
false_response = format_html(
1023+
false_response = mark_safe(
10221024
'<img src="/static/admin/img/icon-no.svg" alt="False">')
1023-
true_response = format_html(
1025+
true_response = mark_safe(
10241026
'<img src="/static/admin/img/icon-yes.svg" alt="True">')
10251027
if not obj.email:
10261028
return false_response
@@ -1078,13 +1080,15 @@ def response_add(self, request, obj, post_url_continue=None):
10781080
request, obj, post_url_continue)
10791081

10801082
def changelist_view(self, request, extra_context=None):
1081-
test = request.META['HTTP_REFERER'].split(request.META['PATH_INFO'])
1082-
if test[-1] and not test[-1].startswith('?'):
1083-
if 'signed_up' not in request.GET:
1084-
q = request.GET.copy()
1085-
q['signed_up'] = 'True'
1086-
request.GET = q
1087-
request.META['QUERY_STRING'] = request.GET.urlencode()
1083+
referer = request.META.get('HTTP_REFERER', '')
1084+
if referer:
1085+
test = referer.split(request.META['PATH_INFO'])
1086+
if test[-1] and not test[-1].startswith('?'):
1087+
if 'signed_up' not in request.GET:
1088+
q = request.GET.copy()
1089+
q['signed_up'] = 'True'
1090+
request.GET = q
1091+
request.META['QUERY_STRING'] = request.GET.urlencode()
10881092
return super().changelist_view(request, extra_context=extra_context)
10891093

10901094
class BaseMapLayerAdmin(OrderedModelAdmin):
@@ -1336,8 +1340,7 @@ class TaxonGroupAdmin(admin.ModelAdmin):
13361340
'category',
13371341
)
13381342
filter_horizontal = (
1339-
'taxonomies',
1340-
'experts'
1343+
'experts',
13411344
)
13421345
raw_id_fields = (
13431346
'gbif_parent_species',
@@ -1836,9 +1839,9 @@ def taxon_group_list(self, obj: Biotope):
18361839

18371840
def used_in_SASS(self, obj: Biotope):
18381841
if obj.sassbiotopefraction_set.all().exists():
1839-
return format_html(
1842+
return mark_safe(
18401843
'<img src="/static/admin/img/icon-yes.svg" alt="True">')
1841-
return format_html(
1844+
return mark_safe(
18421845
'<img src="/static/admin/img/icon-no.svg" alt="False">')
18431846

18441847
list_display = (

bims/forms/upload.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ class UploadForm(forms.Form):
1717
name = forms.CharField(max_length=200)
1818
email = forms.EmailField()
1919
upload_type = forms.ModelChoiceField(
20-
queryset=UploadType.objects.all().order_by('order'),
20+
queryset=UploadType.objects.none(),
2121
empty_label=None,
2222
to_field_name='code'
2323
)
24+
25+
def __init__(self, *args, **kwargs):
26+
super().__init__(*args, **kwargs)
27+
self.fields['upload_type'].queryset = UploadType.objects.all().order_by('order')
2428
upload_file = forms.FileField(
2529
validators=[FileExtensionValidator(
2630
allowed_extensions=ALLOWED_EXTENSIONS)

bims/migrations/0183_auto_20190924_0628.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import datetime
66
from django.db import migrations, models
77
import django.db.models.deletion
8-
from django.utils.timezone import utc
8+
from datetime import timezone as tz
9+
utc = tz.utc
910

1011

1112
class Migration(migrations.Migration):

bims/tests/model_factories.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# noinspection PyUnresolvedReferences,PyPackageRequirements
2+
import datetime
23
import factory
34
import random
45

@@ -187,9 +188,8 @@ class Meta:
187188
is_staff = False
188189
is_active = True
189190
is_superuser = False
190-
last_login = timezone.datetime(2000, 1, 1).replace(tzinfo=timezone.utc)
191-
date_joined = timezone.datetime(1999, 1, 1).replace(
192-
tzinfo=timezone.utc)
191+
last_login = timezone.datetime(2000, 1, 1, tzinfo=datetime.timezone.utc)
192+
date_joined = timezone.datetime(1999, 1, 1, tzinfo=datetime.timezone.utc)
193193

194194
@classmethod
195195
def _prepare(cls, create, **kwargs):

bims/tests/test_delete_dangling_sites.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def test_dangling_queryset_for_location_site_skip_logic(self):
155155
qs = _dangling_queryset(
156156
LocationSite, skip_models=frozenset({LocationContext})
157157
)
158-
self.assertQuerysetEqual(
158+
self.assertQuerySetEqual(
159159
qs.order_by("id"),
160160
[site1, site3],
161161
transform=lambda x: x,

bims/tests/test_taxa_upload.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from mock import mock
77

88
from bims.models import TaxonGroupTaxonomy
9+
from bims.models.taxon_origin import TaxonOrigin
910
from bims.scripts.taxa_upload import TaxaCSVUpload
1011
from bims.tests.model_factories import (
1112
UploadSessionF,
@@ -48,6 +49,13 @@ def setUp(self):
4849
national=False
4950
)
5051

52+
# Create TaxonOrigin records used by the upload script
53+
for key in ('indigenous', 'alien', 'unknown', 'alien-invasive', 'alien-non-invasive'):
54+
TaxonOrigin.objects.get_or_create(
55+
origin_key=key,
56+
defaults={'category': key}
57+
)
58+
5159
with open(os.path.join(
5260
test_data_directory, 'taxa_upload_family.csv'
5361
), 'rb') as file:

bims/tests/test_upload_view.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ def setUp(self):
2929
self.url = reverse(UPLOAD_URL_NAME)
3030
except Exception:
3131
self.url = "/upload/"
32+
self.upload_type, _ = UploadType.objects.get_or_create(
33+
code="occurrence",
34+
defaults={"name": "Occurrence", "order": 0},
35+
)
3236

3337
def _make_file(self, name="data.csv", content=b"col1,col2\nx,y\n"):
3438
return SimpleUploadedFile(name, content, content_type="text/csv")

bims/views/site_visit/update.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,10 @@ def get_success_url(self):
402402
session_uuid = '%s' % uuid.uuid4()
403403
self.add_last_session(self.request, session_uuid, {
404404
'edited_at': int(time.mktime(libdatetime.now().timetuple())),
405-
'records': BiologicalCollectionRecord.objects.filter(
405+
'records': list(BiologicalCollectionRecord.objects.filter(
406406
survey=self.object
407-
),
408-
'location_site': self.object.site,
407+
).values_list('id', flat=True)),
408+
'location_site': self.object.site.id if self.object.site else None,
409409
'form': 'site-visit-form'
410410
})
411411
next_url = '/site-visit/detail/{}/'.format(self.object.id)

core/config_hook/apps.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ class AppConfig(AppConfig):
99

1010
def ready(self):
1111
super(AppConfig, self).ready()
12-
# check settings
1312
from django.conf import settings
14-
from bims.utils.add_index import add_indexes_for_taxonomy
15-
add_indexes_for_taxonomy()
13+
from django.db.models.signals import post_migrate
14+
15+
def create_taxonomy_indexes(sender, **kwargs):
16+
from bims.utils.add_index import add_indexes_for_taxonomy
17+
add_indexes_for_taxonomy()
18+
19+
post_migrate.connect(create_taxonomy_indexes, sender=self)
1620

1721
installed_apps = []
1822

core/settings/legacy_geonode_settings.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,10 @@
238238
AUTH_USER_MODEL = os.getenv('AUTH_USER_MODEL', 'people.Profile')
239239

240240
PASSWORD_HASHERS = [
241-
'django.contrib.auth.hashers.SHA1PasswordHasher',
242241
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
243-
'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
242+
'django.contrib.auth.hashers.ScryptPasswordHasher',
244243
# 'django.contrib.auth.hashers.Argon2PasswordHasher',
245244
# 'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
246-
# 'django.contrib.auth.hashers.BCryptPasswordHasher',
247245
]
248246

249247
MODELTRANSLATION_LANGUAGES = ['en', ]
@@ -743,7 +741,7 @@
743741
'DETAIL': 'never',
744742
}
745743

746-
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
744+
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'
747745

748746
try:
749747
# try to parse python notation, default in dockerized env

0 commit comments

Comments
 (0)