cook: add auto flag in set-variable action (#44325)
This commit is contained in:
parent
0a476f2b33
commit
ab3d543997
|
@ -39,7 +39,7 @@ from hobo.agent.common.management.commands.hobo_deploy import (
|
|||
from hobo.multitenant.middleware import TenantMiddleware
|
||||
from hobo.environment.models import (AVAILABLE_SERVICES, Authentic, Wcs, Hobo,
|
||||
Passerelle, Combo, Fargo, Welco, MandayeJS, Chrono, Corbo, BiJoe,
|
||||
Variable)
|
||||
Variable, AUTO_VARIABLES)
|
||||
from hobo.environment.validators import validate_service_url
|
||||
from hobo.deploy.signals import notify_agents
|
||||
from hobo.theme.utils import set_theme
|
||||
|
@ -269,14 +269,19 @@ class Command(BaseCommand):
|
|||
{'variables': {'theme': theme}},
|
||||
connection.get_tenant())
|
||||
|
||||
def set_variable(self, name, value, label=None):
|
||||
def set_variable(self, name, value, label=None, auto=None):
|
||||
if auto is None:
|
||||
auto = bool(name in AUTO_VARIABLES)
|
||||
else:
|
||||
auto = bool(auto)
|
||||
variable, created = Variable.objects.get_or_create(name=name,
|
||||
defaults={'label': label or name})
|
||||
defaults={'label': label or name, 'auto': auto})
|
||||
if isinstance(value, dict) or isinstance(value, list):
|
||||
value = json.dumps(value)
|
||||
if variable.label != label or variable.value != value or created:
|
||||
if variable.label != label or variable.value != value or variable.auto != auto or created:
|
||||
if label:
|
||||
variable.label = label
|
||||
variable.auto = auto
|
||||
variable.value = value
|
||||
variable.save()
|
||||
|
||||
|
|
|
@ -43,6 +43,16 @@ SECRET_CHARS = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
|
|||
FLOAT_RE = re.compile(r'^\s*[0-9]+\.[0-9]+\s*')
|
||||
|
||||
|
||||
AUTO_VARIABLES = (
|
||||
'default_from_email',
|
||||
'global_email_prefix',
|
||||
'email_signature',
|
||||
'global_title',
|
||||
'robots_txt',
|
||||
'meta_description',
|
||||
'meta_keywords',
|
||||
)
|
||||
|
||||
class Variable(models.Model):
|
||||
name = models.CharField(max_length=100, verbose_name=_('name'))
|
||||
label = models.CharField(max_length=100, blank=True, verbose_name=_('label'))
|
||||
|
|
|
@ -188,6 +188,7 @@ def test_set_variable(db):
|
|||
var = Variable.objects.get(name='foo')
|
||||
assert var.value == 'bar'
|
||||
assert var.label == 'foo'
|
||||
assert var.auto is False
|
||||
|
||||
command.set_variable('foo', 'bar', label='FOO')
|
||||
var = Variable.objects.get(name='foo')
|
||||
|
@ -203,6 +204,15 @@ def test_set_variable(db):
|
|||
ordered_dump = json.dumps(json.loads(var.value), sort_keys=True)
|
||||
assert ordered_dump == '{"key1": "bar", "key2": "baz"}'
|
||||
|
||||
command.set_variable('varauto', ['bar', 'baz'], auto=True)
|
||||
var = Variable.objects.get(name='varauto')
|
||||
assert var.auto is True
|
||||
|
||||
command.set_variable('meta_description', 'blah blah') # in AUTO_VARIABLES
|
||||
var = Variable.objects.get(name='meta_description')
|
||||
assert var.auto is True
|
||||
|
||||
|
||||
def test_set_attribute(db):
|
||||
command = Command()
|
||||
command.set_attribute('foo_name', 'foo_label')
|
||||
|
|
Loading…
Reference in New Issue