Skip to content

Commit

Permalink
[change] Refactored Templates.get_context
Browse files Browse the repository at this point in the history
Context of templates for VPN will now contain variables defined by
the related VPN server
  • Loading branch information
pandafy committed Jan 19, 2022
1 parent 56ccd8c commit dc91b59
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions openwisp_controller/config/base/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,19 @@ def get_context(self, system=False):
context = {}
if self.default_values and not system:
context = copy(self.default_values)
context.update(self.get_vpn_server_context())
context.update(super().get_context())
return context

def get_system_context(self):
system_context = self.get_context(system=True)
return OrderedDict(sorted(system_context.items()))

def get_vpn_server_context(self):
try:
system_context.update(self.vpn.get_vpn_server_context())
return self.vpn.get_vpn_server_context()
except (ObjectDoesNotExist, AttributeError):
pass
return OrderedDict(sorted(system_context.items()))
return {}

def clone(self, user):
clone = copy(self)
Expand Down
2 changes: 1 addition & 1 deletion openwisp_controller/config/tests/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def test_context_regression(self):
template_qs = Template.objects.filter(type='vpn')
self.assertEqual(template_qs.count(), 1)
t = template_qs.first()
self.assertEqual(t.get_context(), _original_context)
self.assertDictContainsSubset(_original_context, t.get_context())
self.assertEqual(app_settings.CONTEXT, _original_context)

with self.subTest(
Expand Down

0 comments on commit dc91b59

Please sign in to comment.