Skip to content

Commit

Permalink
[feature] Add field list_handling to AbstractTemplate model
Browse files Browse the repository at this point in the history
  • Loading branch information
okraits committed Nov 9, 2023
1 parent cb6f91e commit c4b1e78
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions openwisp_controller/config/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@ class TemplateAdmin(MultitenantAdminMixin, BaseConfigAdmin, SystemDefinedVariabl
'name',
'organization',
'type',
'list_handling',
'backend',
'vpn',
'auto_cert',
Expand Down
3 changes: 3 additions & 0 deletions openwisp_controller/config/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,13 @@ def get_backend_instance(self, template_instances=None, context=None, **kwargs):
if template_instances is None:
template_instances = self.templates.all()
templates_list = list()
templates_list_handling = list()
for t in template_instances:
templates_list.append(t.config)
templates_list_handling.append(t.list_handling)
context.update(t.get_context())
kwargs['templates'] = templates_list
kwargs['templates_list_handling'] = templates_list_handling
# pass context to backend if get_context method is defined
if hasattr(self, 'get_context'):
context.update(self.get_context())
Expand Down
17 changes: 17 additions & 0 deletions openwisp_controller/config/base/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
from .base import BaseConfig

TYPE_CHOICES = (('generic', _('Generic')), ('vpn', _('VPN-client')))
LIST_HANDLING_CHOICES = (
('insert_at_beginning', _('Insert items at the beginning')),
('append_at_end', _('Append items at the end')),
('override', _('Override all items')),
)


def default_auto_cert():
Expand Down Expand Up @@ -55,6 +60,18 @@ class AbstractTemplate(ShareableOrgMixinUniqueName, BaseConfig):
db_index=True,
help_text=_('template type, determines which features are available'),
)
list_handling = models.CharField(
_('list handling'),
max_length=20,
choices=LIST_HANDLING_CHOICES,
default='append_at_end',
db_index=True,
help_text=_(
'list handling, determines how list items in this template'
' are handled if the same list exists in a previously '
'applied template'
),
)
default = models.BooleanField(
_('enabled by default'),
default=False,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 4.2.7 on 2023-11-09 18:01

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("config", "0053_vpnclient_secret"),
]

operations = [
migrations.AddField(
model_name="template",
name="list_handling",
field=models.CharField(
choices=[
("insert_at_beginning", "Insert items at the beginning"),
("append_at_end", "Append items at the end"),
("override", "Override all items"),
],
db_index=True,
default="append_at_end",
help_text="list handling, determines how list items in this "
"template are handled if the same list exists in a previously"
" applied template",
max_length=20,
verbose_name="list handling",
),
),
]

0 comments on commit c4b1e78

Please sign in to comment.