Commit 4e0f35e6 by Őry Máté

dashboard: support save_as with custom template name

parent e5f5d4f4
{% extends "dashboard/operate.html" %}
{% load i18n %}
{% load sizefieldtags %}
{% block question %}
<p>
{% blocktrans %}
Choose a name for the new template.
{% endblocktrans %}
</p>
<p class="text-info">{{op.name}}: {{op.description}}</p>
{% endblock %}
{% block formfields %}
<div class="form-group">
<label for="input-name" class="col-sm-4">{% trans "Name of template" %}</label>
<div class="col-sm-8">
<input type="text" value="{{name}}" name="name" class="form-control" />
</div>
</div>
{% endblock %}
......@@ -513,7 +513,7 @@ class VmMigrateView(VmOperationView):
template_name = 'dashboard/_vm-migrate.html'
def get_context_data(self, **kwargs):
ctx = super(VmOperationView, self).get_context_data(**kwargs)
ctx = super(VmMigrateView, self).get_context_data(**kwargs)
ctx['nodes'] = [n for n in Node.objects.filter(enabled=True)
if n.state == "ONLINE"]
return ctx
......@@ -528,6 +528,26 @@ class VmMigrateView(VmOperationView):
return super(VmMigrateView, self).post(request, extra, *args, **kwargs)
class VmSaveView(VmOperationView):
op = 'save_as_template'
icon = 'save'
template_name = 'dashboard/_vm-save.html'
def get_context_data(self, **kwargs):
ctx = super(VmSaveView, self).get_context_data(**kwargs)
ctx['name'] = self.get_op()._rename(self.object.name)
return ctx
def post(self, request, extra=None, *args, **kwargs):
if extra is None:
extra = {}
name = self.request.POST.get("name")
if name:
extra["name"] = name
return super(VmSaveView, self).post(request, extra, *args, **kwargs)
vm_ops = {
'reset': VmOperationView.factory(op='reset', icon='bolt'),
'deploy': VmOperationView.factory(op='deploy', icon='play'),
......@@ -535,8 +555,7 @@ vm_ops = {
'reboot': VmOperationView.factory(op='reboot', icon='refresh'),
'shut_off': VmOperationView.factory(op='shut_off', icon='ban-circle'),
'shutdown': VmOperationView.factory(op='shutdown', icon='off'),
'save_as_template': VmOperationView.factory(
op='save_as_template', icon='save'),
'save_as_template': VmSaveView,
'destroy': VmOperationView.factory(op='destroy', icon='remove'),
'sleep': VmOperationView.factory(op='sleep', icon='moon'),
'wake_up': VmOperationView.factory(op='wake_up', icon='sun'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment