From 9a38f44776bd790a933467d5cb147ded8e327f11 Mon Sep 17 00:00:00 2001 From: Christian Glatthard Date: Tue, 11 Aug 2015 14:14:28 +0200 Subject: [PATCH] fix container_grid template to match api response --- ipynbsrv/api/serializer.py | 15 +++++ ipynbsrv/core/models.py | 6 ++ .../web/snippets/container_grid.html | 58 ++++++++++++++----- 3 files changed, 65 insertions(+), 14 deletions(-) diff --git a/ipynbsrv/api/serializer.py b/ipynbsrv/api/serializer.py index 2e61a12..ced546a 100644 --- a/ipynbsrv/api/serializer.py +++ b/ipynbsrv/api/serializer.py @@ -138,6 +138,16 @@ class Meta: model = Server +class PortMappingSerializer(serializers.ModelSerializer): + """ + + """ + is_protected_mapping = serializers.BooleanField(read_only=True) + + class Meta: + model = PortMapping + + class ContainerSerializer(serializers.ModelSerializer): """ Todo: write doc. @@ -145,12 +155,17 @@ class ContainerSerializer(serializers.ModelSerializer): Server is set through the server selection algorithm set in the conf module. """ backend_name = serializers.CharField(read_only=True, source='get_backend_name') + backend_base_url = serializers.CharField(read_only=True, source='get_backend_base_url') friendly_name = serializers.CharField(read_only=True, source='get_friendly_name') is_clone = serializers.BooleanField(read_only=True) is_image_based = serializers.BooleanField(read_only=True) is_running = serializers.BooleanField(read_only=True) is_suspended = serializers.BooleanField(read_only=True) has_clones = serializers.BooleanField(read_only=True) + port_mappings = PortMappingSerializer( + many=True, + read_only=True + ) owner = serializers.HiddenField( default=CurrentBackendUserDefault() diff --git a/ipynbsrv/core/models.py b/ipynbsrv/core/models.py index 60d5d52..6dea440 100644 --- a/ipynbsrv/core/models.py +++ b/ipynbsrv/core/models.py @@ -1173,6 +1173,12 @@ def get_available_server_port(cls, server): # ServerSelectionAlgorithm must guarantee enough ports are free! return port + def is_protected_mapping(self): + """ + Return `True` if this mapping is for the protected container port. + """ + return self.internal_port == self.container.image.protected_port + def __str__(self): """ :inherit. diff --git a/ipynbsrv/web/templates/web/snippets/container_grid.html b/ipynbsrv/web/templates/web/snippets/container_grid.html index e106094..a49ec22 100644 --- a/ipynbsrv/web/templates/web/snippets/container_grid.html +++ b/ipynbsrv/web/templates/web/snippets/container_grid.html @@ -2,8 +2,14 @@
{% for ct in containers %}
- {% if ct.running %} -
+ {% if ct.is_running %} + {% if ct.is_suspended %} +
+ } + {% else %} +
+ } + {% endif %} {% else %}
{% endif %} @@ -11,7 +17,7 @@
{{ ct.description }}
- {% if ct.running and ct.port_mappings %} + {% if ct.is_running and ct.port_mappings %} @@ -21,10 +27,12 @@ {% for port_mapping in ct.port_mappings %} - - - - + {% if not port_mapping.is_protected_mappping %} + + + + + {% endif %} {% endfor %}
{{ port_mapping.internal }}{{ port_mapping.external }}
{{ port_mapping.internal_port }}{{ ct.server.external_ip }}:{{ port_mapping.external_port }}
@@ -37,13 +45,15 @@