Fix custom scripts attributes usage and examples

This commit is contained in:
Stoned Elipot 2019-09-22 18:17:58 +02:00
parent 0798533201
commit c29e01843f
4 changed files with 8 additions and 8 deletions

View File

@ -201,13 +201,13 @@ class BaseScript:
self.source = inspect.getsource(self.__class__)
def __str__(self):
return getattr(self.Meta, 'name', self.__class__.__name__)
return getattr(self, 'name', self.__class__.__name__)
def _get_vars(self):
vars = OrderedDict()
# Infer order from Meta.field_order (Python 3.5 and lower)
field_order = getattr(self.Meta, 'field_order', [])
# Infer order from self.field_order (Python 3.5 and lower)
field_order = getattr(self, 'field_order', [])
for name in field_order:
vars[name] = getattr(self, name)

View File

@ -6,9 +6,9 @@ from extras.scripts import *
class NewBranchScript(Script):
script_name = "New Branch"
script_description = "Provision a new branch site"
script_fields = ['site_name', 'switch_count', 'switch_model']
name = "New Branch"
description = "Provision a new branch site"
field_order = ['site_name', 'switch_count', 'switch_model']
site_name = StringVar(
description="Name of the new site"

View File

@ -16,7 +16,7 @@
</div>
</div>
<h1>{{ script }}</h1>
<p>{{ script.Meta.description }}</p>
<p>{{ script.description }}</p>
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">
<a href="#run" role="tab" data-toggle="tab" class="active">Run</a>

View File

@ -21,7 +21,7 @@
<td>
<a href="{% url 'extras:script' module=module name=class_name %}" name="script.{{ class_name }}"><strong>{{ script }}</strong></a>
</td>
<td>{{ script.Meta.description }}</td>
<td>{{ script.description }}</td>
</tr>
{% endfor %}
</tbody>