Skip to content

Commit ee8d2fe

Browse files
[deps] Update django-import-export requirement from ~=3.3.0 to ~=4.1.1
Updates the requirements on [django-import-export](https://github.com/django-import-export/django-import-export) to permit the latest version. - [Release notes](https://github.com/django-import-export/django-import-export/releases) - [Changelog](https://github.com/django-import-export/django-import-export/blob/main/docs/changelog.rst) - [Commits](django-import-export/django-import-export@3.3.0...4.1.1) --- updated-dependencies: - dependency-name: django-import-export dependency-type: direct:production ... * [fix] Fixed DeviceResource and GeoDeviceResource * [tests] Added tests to improve coverage Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Gagan Deep <[email protected]>
1 parent e1d4e69 commit ee8d2fe

File tree

6 files changed

+58
-19
lines changed

6 files changed

+58
-19
lines changed

openwisp_controller/config/admin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from django.utils.translation import ngettext_lazy
2727
from flat_json_widget.widgets import FlatJsonWidget
2828
from import_export.admin import ImportExportMixin
29+
from import_export.forms import ExportForm
2930
from openwisp_ipam.filters import SubnetFilter
3031
from swapper import load_model
3132

@@ -971,6 +972,7 @@ def add_reversion_following(cls, follow):
971972

972973

973974
class DeviceAdminExportable(ImportExportMixin, DeviceAdmin):
975+
export_form_class = ExportForm
974976
resource_class = DeviceResource
975977
# needed to support both reversion and import-export
976978
change_list_template = 'admin/config/change_list_device.html'

openwisp_controller/config/exportable.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ def validate_instance(
127127
if config.device_id != instance.id:
128128
config.device_id = instance.id
129129

130-
def after_save_instance(self, instance, using_transactions, dry_run):
131-
super().after_save_instance(instance, using_transactions, dry_run)
132-
if not dry_run:
133-
# save config afte device has been imported
130+
def after_save_instance(self, instance, row, **kwargs):
131+
super().after_save_instance(instance, row, **kwargs)
132+
if not self._is_dry_run(kwargs):
133+
# save config after device has been imported
134134
if instance._has_config():
135135
instance.config.save()
136136

openwisp_controller/config/tests/test_admin.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def test_device_import_export_buttons(self):
9090

9191
def test_device_export(self):
9292
response = self.client.post(
93-
reverse(f'admin:{self.app_label}_device_export'), {'file_format': '0'}
93+
reverse(f'admin:{self.app_label}_device_export'), {'format': '0'}
9494
)
9595
self.assertNotContains(response, 'error')
9696
self.assertIsNotNone(response.get('Content-Disposition'))
@@ -108,7 +108,7 @@ def test_device_import(self):
108108
csv = ContentFile(contents)
109109
response = self.client.post(
110110
reverse(f'admin:{self.app_label}_device_import'),
111-
{'input_format': '0', 'import_file': csv},
111+
{'format': '0', 'import_file': csv},
112112
)
113113
self.assertNotContains(response, 'errorlist')
114114
self.assertNotContains(response, 'Errors')
@@ -132,7 +132,7 @@ def test_device_import_empty_config(self):
132132
csv = ContentFile(contents)
133133
response = self.client.post(
134134
reverse(f'admin:{self.app_label}_device_import'),
135-
{'input_format': '0', 'import_file': csv, 'file_name': 'test.csv'},
135+
{'format': '0', 'import_file': csv, 'file_name': 'test.csv'},
136136
)
137137
self.assertFalse(response.context['result'].has_errors())
138138
self.assertIn('confirm_form', response.context)
@@ -173,7 +173,7 @@ def test_device_import_missing_config(self):
173173
csv = ContentFile(contents)
174174
response = self.client.post(
175175
reverse(f'admin:{self.app_label}_device_import'),
176-
{'input_format': '0', 'import_file': csv, 'file_name': 'test.csv'},
176+
{'format': '0', 'import_file': csv, 'file_name': 'test.csv'},
177177
)
178178
self.assertFalse(response.context['result'].has_errors())
179179
self.assertIn('confirm_form', response.context)
@@ -212,7 +212,7 @@ def test_device_import_config_not_templates(self):
212212
csv = ContentFile(contents)
213213
response = self.client.post(
214214
reverse(f'admin:{self.app_label}_device_import'),
215-
{'input_format': '0', 'import_file': csv, 'file_name': 'test.csv'},
215+
{'format': '0', 'import_file': csv, 'file_name': 'test.csv'},
216216
)
217217
self.assertFalse(response.context['result'].has_errors())
218218
self.assertIn('confirm_form', response.context)
@@ -636,7 +636,7 @@ def test_device_import_with_group_apply_templates(self):
636636
csv = ContentFile(contents)
637637
response = self.client.post(
638638
reverse(f'admin:{self.app_label}_device_import'),
639-
{'input_format': '0', 'import_file': csv, 'file_name': 'test.csv'},
639+
{'format': '0', 'import_file': csv, 'file_name': 'test.csv'},
640640
)
641641
self.assertFalse(response.context['result'].has_errors())
642642
self.assertIn('confirm_form', response.context)
@@ -682,7 +682,7 @@ def test_device_import_templates_and_config(self):
682682
csv = ContentFile(contents)
683683
response = self.client.post(
684684
reverse(f'admin:{self.app_label}_device_import'),
685-
{'input_format': '0', 'import_file': csv, 'file_name': 'test.csv'},
685+
{'format': '0', 'import_file': csv, 'file_name': 'test.csv'},
686686
)
687687
self.assertFalse(response.context['result'].has_errors())
688688
self.assertIn('confirm_form', response.context)

openwisp_controller/geo/exportable.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def dehydrate_coords(self, device):
5252
except (ObjectDoesNotExist, AttributeError):
5353
pass
5454

55-
def after_import_instance(self, instance, new, row_number=None, **kwargs):
56-
super().after_import_instance(instance, new, row_number, **kwargs)
55+
def after_init_instance(self, instance, new, row, **kwargs):
56+
super().after_init_instance(instance, new, row, **kwargs)
5757
if not hasattr(instance, 'devicelocation'):
5858
instance.devicelocation = DeviceLocation()
5959

@@ -68,9 +68,9 @@ def validate_instance(
6868
if device_location.location_id or device_location.floorplan_id:
6969
device_location.content_object_id = instance.id
7070

71-
def after_save_instance(self, instance, using_transactions, dry_run):
72-
super().after_save_instance(instance, using_transactions, dry_run)
73-
if not dry_run:
71+
def after_save_instance(self, instance, row, **kwargs):
72+
super().after_save_instance(instance, row, **kwargs)
73+
if not self._is_dry_run(kwargs):
7474
device_location = instance.devicelocation
7575
if device_location.location_id or device_location.floorplan_id:
7676
device_location.save()

openwisp_controller/geo/tests/test_admin.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,43 @@ class TestDeviceAdmin(
164164
def setUp(self):
165165
self.client.force_login(self._get_admin())
166166

167+
def test_device_export_geo(self):
168+
org = self._get_org(org_name='default')
169+
location = self._create_location(
170+
name='location', type='indoor', organization=org
171+
)
172+
floorplan = self._create_floorplan(location=location, organization=org)
173+
device = self._create_object(
174+
name='test',
175+
organization=org,
176+
mac_address='00:11:22:33:44:66',
177+
)
178+
self._create_object_location(
179+
location=location, floorplan=floorplan, content_object=device
180+
)
181+
response = self.client.post(
182+
reverse(f'admin:{self.app_label}_device_export'), {'format': '0'}
183+
)
184+
self.assertEqual(response.status_code, 200)
185+
contents = response.content.decode('utf-8')
186+
self.assertIn(
187+
'name,mac_address,organization,group,model,os,system,notes,venue,address,'
188+
'coords,is_mobile,venue_type,floor,floor_position,last_ip,management_ip,'
189+
'config_status,config_backend,config_data,config_context,config_templates,'
190+
'created,modified,id,key,organization_id,group_id,location_id,floorplan_id',
191+
contents,
192+
)
193+
self.assertIn(
194+
'test,00:11:22:33:44:66,default,,,,,,location,'
195+
'"Via del Corso, Roma, Italia",POINT (12.512124 41.898903),False,indoor,'
196+
'1,"-140.38620,40.369227",,,,,,,,',
197+
contents,
198+
)
199+
self.assertIn(
200+
f'{device.id},{device.key},{org.id},,{location.id},{floorplan.id}',
201+
contents,
202+
)
203+
167204
def test_device_import_geo(self):
168205
org = self._get_org(org_name='default')
169206
location = self._create_location(
@@ -196,7 +233,7 @@ def test_device_import_geo(self):
196233
csv = ContentFile(contents)
197234
response = self.client.post(
198235
reverse(f'admin:{self.app_label}_device_import'),
199-
{'input_format': '0', 'import_file': csv, 'file_name': 'test.csv'},
236+
{'format': '0', 'import_file': csv, 'file_name': 'test.csv'},
200237
)
201238
self.assertFalse(response.context['result'].has_errors())
202239
self.assertIn('confirm_form', response.context)
@@ -253,7 +290,7 @@ def test_device_import_geo_no_floorplan(self):
253290
csv = ContentFile(contents)
254291
response = self.client.post(
255292
reverse(f'admin:{self.app_label}_device_import'),
256-
{'input_format': '0', 'import_file': csv, 'file_name': 'test.csv'},
293+
{'format': '0', 'import_file': csv, 'file_name': 'test.csv'},
257294
)
258295
self.assertFalse(response.context['result'].has_errors())
259296
self.assertIn('confirm_form', response.context)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ scp~=0.15.0
1616
django-cache-memoize~=0.2.1
1717
shortuuid~=1.0.13
1818
netaddr~=1.3.0
19-
django-import-export~=3.3.0
19+
django-import-export~=4.1.1

0 commit comments

Comments
 (0)