Skip to content

Commit 5557258

Browse files
committed
[feature] Add field list_handling to AbstractTemplate model
1 parent cb6f91e commit 5557258

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed

openwisp_controller/config/admin.py

+1
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,7 @@ class TemplateAdmin(MultitenantAdminMixin, BaseConfigAdmin, SystemDefinedVariabl
831831
'name',
832832
'organization',
833833
'type',
834+
'list_handling',
834835
'backend',
835836
'vpn',
836837
'auto_cert',

openwisp_controller/config/base/base.py

+3
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,13 @@ def get_backend_instance(self, template_instances=None, context=None, **kwargs):
155155
if template_instances is None:
156156
template_instances = self.templates.all()
157157
templates_list = list()
158+
templates_list_handling = list()
158159
for t in template_instances:
159160
templates_list.append(t.config)
161+
templates_list_handling.append(t.list_handling)
160162
context.update(t.get_context())
161163
kwargs['templates'] = templates_list
164+
kwargs['templates_list_handling'] = templates_list_handling
162165
# pass context to backend if get_context method is defined
163166
if hasattr(self, 'get_context'):
164167
context.update(self.get_context())

openwisp_controller/config/base/template.py

+17
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
from .base import BaseConfig
1616

1717
TYPE_CHOICES = (('generic', _('Generic')), ('vpn', _('VPN-client')))
18+
LIST_HANDLING_CHOICES = (
19+
('insert_at_beginning', _('Insert items at the beginning')),
20+
('append_at_end', _('Append items at the end')),
21+
('override', _('Override all items')),
22+
)
1823

1924

2025
def default_auto_cert():
@@ -55,6 +60,18 @@ class AbstractTemplate(ShareableOrgMixinUniqueName, BaseConfig):
5560
db_index=True,
5661
help_text=_('template type, determines which features are available'),
5762
)
63+
list_handling = models.CharField(
64+
_('list handling'),
65+
max_length=20,
66+
choices=LIST_HANDLING_CHOICES,
67+
default='append_at_end',
68+
db_index=True,
69+
help_text=_(
70+
'list handling, determines how list items in this template'
71+
' are handled if the same list exists in a previously '
72+
'applied template'
73+
),
74+
)
5875
default = models.BooleanField(
5976
_('enabled by default'),
6077
default=False,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Generated by Django 4.2.7 on 2023-11-09 18:01
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("config", "0053_vpnclient_secret"),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name="template",
15+
name="list_handling",
16+
field=models.CharField(
17+
choices=[
18+
("insert_at_beginning", "Insert items at the beginning"),
19+
("append_at_end", "Append items at the end"),
20+
("override", "Override all items"),
21+
],
22+
db_index=True,
23+
default="append_at_end",
24+
help_text="list handling, determines how list items in this "
25+
"template are handled if the same list exists in a previously"
26+
" applied template",
27+
max_length=20,
28+
verbose_name="list handling",
29+
),
30+
),
31+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Generated by Django 4.2.7 on 2023-11-13 18:51
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("sample_config", "0005_add_organizationalloweddevice"),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name="template",
15+
name="list_handling",
16+
field=models.CharField(
17+
choices=[
18+
("insert_at_beginning", "Insert items at the beginning"),
19+
("append_at_end", "Append items at the end"),
20+
("override", "Override all items"),
21+
],
22+
db_index=True,
23+
default="append_at_end",
24+
help_text="list handling, determines how list items in this template are handled if the same list exists in a previously applied template",
25+
max_length=20,
26+
verbose_name="list handling",
27+
),
28+
),
29+
]

0 commit comments

Comments
 (0)