Commit a87215f0 by Kálmán Viktor

dashboard: display multiple connections strings

Also add empty text and prefix to tables in profile
parent 69abf63b
......@@ -155,22 +155,25 @@ class Profile(Model):
default=2048 * 1024 * 1024,
help_text=_('Disk quota in mebibytes.'))
def get_connect_command(self, instance, use_ipv6=False):
def get_connect_commands(self, instance, use_ipv6=False):
""" Generate connection command based on template."""
try:
command = self.user.command_set.get(
single_command = instance.get_connect_command(use_ipv6)
if single_command: # can we even connect to that VM
commands = self.user.command_set.filter(
access_method=instance.access_method)
except ConnectCommand.DoesNotExist:
# No template for this protocol return default
return instance.get_connect_command(use_ipv6)
if commands.count() < 1:
return [single_command]
else:
return command.template % {
return [
command.template % {
'port': instance.get_connect_port(use_ipv6=use_ipv6),
'host': instance.get_connect_host(use_ipv6=use_ipv6),
'password': instance.pw,
'app': command.application,
'username': 'cloud'
}
'username': 'cloud',
} for command in commands]
else:
return []
def notify(self, subject, template, context=None, valid_until=None,
**kwargs):
......
......@@ -251,6 +251,8 @@ class UserKeyListTable(Table):
model = UserKey
attrs = {'class': ('table table-bordered table-striped table-hover')}
fields = ('name', 'fingerprint', 'created', 'actions')
prefix = "key-"
empty_text = _("You haven't added any public keys yet.")
class ConnectCommandListTable(Table):
......@@ -279,3 +281,6 @@ class ConnectCommandListTable(Table):
model = ConnectCommand
attrs = {'class': ('table table-bordered table-striped table-hover')}
fields = ('access_method', 'application', 'template', 'actions')
prefix = "cmd-"
empty_text = _("You don't have any custom connection string, the "
"default ones will be used.")
......@@ -111,16 +111,28 @@
</div>
</dd>
</dl>
{% for c in connect_commands %}
<div class="input-group" id="dashboard-vm-details-connect-command">
<span class="input-group-addon input-tags">{% trans "Command" %}</span>
<input type="text" spellcheck="false"
value="{% if connect_command %}{{ connect_command }}{% else %}{% trans "Connection is not possible." %}{% endif %}"
value="{{ c }}"
id="vm-details-connection-string" class="form-control input-tags" />
<span class="input-group-addon input-tags" id="vm-details-connection-string-copy">
<i class="fa fa-copy" title="{% trans "Select all" %}"></i>
</span>
</div>
{% empty %}
<div class="input-group" id="dashboard-vm-details-connect-command">
<span class="input-group-addon input-tags">{% trans "Command" %}</span>
<input type="text" spellcheck="false" value="{% trans "Connection is not possible." %}"
id="vm-details-connection-string" class="form-control input-tags" />
<span class="input-group-addon input-tags" id="vm-details-connection-string-copy">
<i class="fa fa-copy" title="{% trans "Select all" %}"></i>
</span>
</div>
{% endfor %}
</div>
<div class="col-md-8" id="vm-detail-pane">
<div class="panel panel-default" id="vm-detail-panel">
......
......@@ -304,7 +304,7 @@ class VmDetailView(CheckedDetailView):
kwargs={'pk': self.object.pk}),
'ops': ops,
'op': {i.op: i for i in ops},
'connect_command': user.profile.get_connect_command(instance)
'connect_commands': user.profile.get_connect_commands(instance)
})
# activity data
......@@ -3201,8 +3201,7 @@ class ConnectCommandDetail(LoginRequiredMixin, SuccessMessageMixin,
object = self.get_object()
if object.user != request.user:
raise PermissionDenied()
return super(ConnectCommandDetail, self).post(self, request,
args, kwargs)
return super(ConnectCommandDetail, self).post(request, args, kwargs)
class ConnectCommandDelete(LoginRequiredMixin, DeleteView):
......
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