Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Add field list_handling to AbstractTemplate model #814

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 4.2.7 on 2023-11-13 18:51

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("sample_config", "0005_add_organizationalloweddevice"),
]

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",
),
),
]
Loading