File tree Expand file tree Collapse file tree 8 files changed +40
-8
lines changed
sample_connection/migrations Expand file tree Collapse file tree 8 files changed +40
-8
lines changed Original file line number Diff line number Diff line change 11import collections
22import logging
33
4+ import django
45import jsonschema
56from django .core .exceptions import ValidationError
67from django .db import models , transaction
2425 ORGANIZATION_COMMAND_SCHEMA ,
2526 ORGANIZATION_ENABLED_COMMANDS ,
2627 get_command_callable ,
28+ get_command_choices ,
2729 get_command_schema ,
2830)
2931from ..exceptions import NoWorkingDeviceConnectionError
@@ -408,7 +410,18 @@ class AbstractCommand(TimeStampedEditableModel):
408410 status = models .CharField (
409411 max_length = 12 , choices = STATUS_CHOICES , default = STATUS_CHOICES [0 ][0 ]
410412 )
411- type = models .CharField (max_length = 16 , choices = COMMAND_CHOICES )
413+ type = models .CharField (
414+ max_length = 16 ,
415+ choices = (
416+ COMMAND_CHOICES
417+ if django .VERSION < (5 , 0 )
418+ # In Django 5.0+, choices are normalized at model definition,
419+ # creating a static list of tuples that doesn't update when command
420+ # are dynamically registered or unregistered. Using a callable
421+ # ensures we always get the current choices from the registry.
422+ else get_command_choices
423+ ),
424+ )
412425 input = JSONField (
413426 blank = True ,
414427 null = True ,
Original file line number Diff line number Diff line change @@ -155,3 +155,10 @@ def _unregister_command_choice(command):
155155 ORGANIZATION_COMMAND_SCHEMA [org_id ] = OrderedDict ()
156156 for command in commands :
157157 ORGANIZATION_COMMAND_SCHEMA [org_id ][command ] = COMMANDS [command ]['schema' ]
158+
159+
160+ def get_command_choices ():
161+ """
162+ Returns the command choices.
163+ """
164+ return COMMAND_CHOICES
Original file line number Diff line number Diff line change 33import collections
44import uuid
55
6+ import django
67import django .db .migrations .operations .special
78import django .db .models .deletion
89import django .utils .timezone
1112import swapper
1213from django .db import migrations , models
1314
14- from ..commands import COMMAND_CHOICES
15+ from ..commands import COMMAND_CHOICES , get_command_choices
1516from . import assign_command_permissions_to_groups
1617
1718
@@ -65,7 +66,9 @@ class Migration(migrations.Migration):
6566 (
6667 'type' ,
6768 models .CharField (
68- choices = COMMAND_CHOICES ,
69+ choices = COMMAND_CHOICES
70+ if django .VERSION < (5 , 0 )
71+ else get_command_choices ,
6972 max_length = 16 ,
7073 ),
7174 ),
Original file line number Diff line number Diff line change 22
33
44def get_connection_working_notification_target_url (obj , field , absolute_url = True ):
5- url = _get_object_link (obj , field , absolute_url )
5+ url = _get_object_link (obj . _related_object ( field ) , absolute_url )
66 return f'{ url } #deviceconnection_set-group'
Original file line number Diff line number Diff line change @@ -78,3 +78,4 @@ def test_add_mobile(self):
7878
7979
8080del TestConfigAdmin
81+ del BaseTestAdminInline
Original file line number Diff line number Diff line change @@ -577,7 +577,7 @@ def test_change_location_type_to_outdoor_api(self):
577577 self ._create_floorplan (location = l1 )
578578 path = reverse ('geo_api:detail_location' , args = [l1 .pk ])
579579 data = {'type' : 'outdoor' }
580- with self .assertNumQueries (8 ):
580+ with self .assertNumQueries (9 ):
581581 response = self .client .patch (path , data , content_type = 'application/json' )
582582 self .assertEqual (response .status_code , 200 )
583583 self .assertEqual (response .data ['floorplan' ], [])
Original file line number Diff line number Diff line change 33import collections
44import uuid
55
6+ import django
67import django .db .models .deletion
78import django .utils .timezone
89import jsonfield .fields
1415import openwisp_controller .connection .base .models
1516import openwisp_users .mixins
1617from openwisp_controller .connection import settings as connection_settings
17- from openwisp_controller .connection .commands import COMMAND_CHOICES
18+ from openwisp_controller .connection .commands import COMMAND_CHOICES , get_command_choices
1819
1920
2021class Migration (migrations .Migration ):
@@ -245,7 +246,9 @@ class Migration(migrations.Migration):
245246 (
246247 'type' ,
247248 models .CharField (
248- choices = COMMAND_CHOICES ,
249+ choices = COMMAND_CHOICES
250+ if django .VERSION < (5 , 0 )
251+ else get_command_choices ,
249252 max_length = 16 ,
250253 ),
251254 ),
Original file line number Diff line number Diff line change @@ -204,7 +204,12 @@ class Migration(migrations.Migration):
204204 'verbose_name' : 'user' ,
205205 'verbose_name_plural' : 'users' ,
206206 'abstract' : False ,
207- 'index_together' : {('id' , 'email' )},
207+ 'indexes' : [
208+ models .Index (
209+ fields = ['id' , 'email' ],
210+ name = 'user_id_email_idx' ,
211+ )
212+ ],
208213 },
209214 managers = [('objects' , openwisp_users .base .models .UserManager ())],
210215 ),
You can’t perform that action at this time.
0 commit comments