Skip to content

Commit 53da00c

Browse files
[feature] Made Device verbose_name configurable #287 (#302)
Closes #287 Co-authored-by: Sankalp <[email protected]> Co-authored-by: Federico Capoano <[email protected]>
1 parent 85e8cbc commit 53da00c

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

README.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,24 @@ their hardware ID instead of their name.
563563

564564
If you still want to reference devices by their name, set this to ``False``.
565565

566+
``OPENWISP_CONTROLLER_DEVICE_VERBOSE_NAME``
567+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
568+
569+
+--------------+----------------------------+
570+
| **type**: | ``tuple`` |
571+
+--------------+----------------------------+
572+
| **default**: | ``('Device', 'Devices')`` |
573+
+--------------+----------------------------+
574+
575+
Defines the ``verbose_name`` attribute of the ``Device`` model, which is displayed in the
576+
admin site. The first and second element of the tuple represent the singular and plural forms.
577+
578+
For example, if we want to change the verbose name to "Hotspot", we could write:
579+
580+
.. code-block:: python
581+
582+
OPENWISP_CONTROLLER_DEVICE_VERBOSE_NAME = ('Hotspot', 'Hotspots')
583+
566584
Default Alerts / Notifications
567585
------------------------------
568586

openwisp_controller/config/base/device.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ class Meta:
8383
('hardware_id', 'organization'),
8484
)
8585
abstract = True
86+
verbose_name = app_settings.DEVICE_VERBOSE_NAME[0]
87+
verbose_name_plural = app_settings.DEVICE_VERBOSE_NAME[1]
8688

8789
def __str__(self):
8890
return (

openwisp_controller/config/migrations/0004_add_device_model.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import openwisp_utils.base
1313
import openwisp_utils.utils
1414

15+
from .. import settings as app_settings
16+
1517

1618
class Migration(migrations.Migration):
1719

@@ -114,7 +116,11 @@ class Migration(migrations.Migration):
114116
),
115117
),
116118
],
117-
options={'abstract': False},
119+
options={
120+
'abstract': False,
121+
'verbose_name': app_settings.DEVICE_VERBOSE_NAME[0],
122+
'verbose_name_plural': app_settings.DEVICE_VERBOSE_NAME[1],
123+
},
118124
),
119125
migrations.AddField(
120126
model_name='config',

openwisp_controller/config/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,6 @@ def get_settings_value(option, default):
5252
}
5353
HARDWARE_ID_OPTIONS.update(get_settings_value('HARDWARE_ID_OPTIONS', {}))
5454
HARDWARE_ID_AS_NAME = get_settings_value('HARDWARE_ID_AS_NAME', True)
55+
DEVICE_VERBOSE_NAME = get_settings_value(
56+
'DEVICE_VERBOSE_NAME', (_('Device'), _('Devices'))
57+
)

tests/openwisp2/sample_config/migrations/0001_initial.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Generated by Django 3.0.7 on 2020-06-27 11:16
2-
32
import collections
43
import re
54
import uuid
@@ -17,6 +16,7 @@
1716
import openwisp_users.mixins
1817
import openwisp_utils.base
1918
import openwisp_utils.utils
19+
from openwisp_controller.config import settings as app_settings
2020

2121

2222
class Migration(migrations.Migration):
@@ -736,6 +736,8 @@ class Migration(migrations.Migration):
736736
('hardware_id', 'organization'),
737737
('name', 'organization'),
738738
},
739+
'verbose_name': app_settings.DEVICE_VERBOSE_NAME[0],
740+
'verbose_name_plural': app_settings.DEVICE_VERBOSE_NAME[1],
739741
},
740742
bases=(openwisp_users.mixins.ValidateOrgMixin, models.Model),
741743
),

0 commit comments

Comments
 (0)