Expand dbconfig support

* Support updating settings values
* Support activity stream endpoint
* Support clearing value
* Improve type conversion system for displaying values
This commit is contained in:
Matthew Jones
2015-12-14 15:09:10 -05:00
parent f53f3d805d
commit 273181e894
8 changed files with 80 additions and 14 deletions

View File

@@ -53,6 +53,7 @@ class ActivityStream(models.Model):
ad_hoc_command = models.ManyToManyField("AdHocCommand", blank=True)
schedule = models.ManyToManyField("Schedule", blank=True)
custom_inventory_script = models.ManyToManyField("CustomInventoryScript", blank=True)
tower_settings = models.ManyToManyField("TowerSettings", blank=True)
def get_absolute_url(self):
return reverse('api:activity_stream_detail', args=(self.pk,))

View File

@@ -20,6 +20,7 @@ class TowerSettings(CreatedModifiedModel):
('int', _('Integer')),
('float', _('Decimal')),
('json', _('JSON')),
('bool', _('Boolean')),
('password', _('Password')),
('list', _('List'))
]
@@ -43,3 +44,15 @@ class TowerSettings(CreatedModifiedModel):
editable=False,
)
@property
def value_converted(self):
if self.value_type == 'json':
converted_type = json.loads(self.value)
elif self.value_type == 'password':
converted_type = self.value
elif self.value_type == 'list':
converted_type = [x.strip() for x in self.value.split(',')]
else:
t = __builtins__[self.value_type]
converted_type = t(self.value)
return converted_type