mirror of
				https://github.com/retspen/webvirtcloud
				synced 2025-07-31 12:41:08 +00:00 
			
		
		
		
	add user information per instance on the instances list
wider .container (900px)
This commit is contained in:
		
							parent
							
								
									e45c712d67
								
							
						
					
					
						commit
						e966e6c030
					
				
					 3 changed files with 16 additions and 5 deletions
				
			
		| 
						 | 
					@ -39,8 +39,8 @@
 | 
				
			||||||
                                    <table class="table table-hover table-striped sortable-theme-bootstrap" data-sortable>
 | 
					                                    <table class="table table-hover table-striped sortable-theme-bootstrap" data-sortable>
 | 
				
			||||||
                                        <thead>
 | 
					                                        <thead>
 | 
				
			||||||
                                            <tr>
 | 
					                                            <tr>
 | 
				
			||||||
                                                <th>Name</th>
 | 
					                                                <th>Name<br>Description</th>
 | 
				
			||||||
                                                <th>Host</th>
 | 
					                                                <th>Host<br>User</th>
 | 
				
			||||||
                                                <th>Status</th>
 | 
					                                                <th>Status</th>
 | 
				
			||||||
                                                <th>VCPU</th>
 | 
					                                                <th>VCPU</th>
 | 
				
			||||||
                                                <th>Memory</th>
 | 
					                                                <th>Memory</th>
 | 
				
			||||||
| 
						 | 
					@ -52,7 +52,7 @@
 | 
				
			||||||
                                                {% for vm, info in inst.items %}
 | 
					                                                {% for vm, info in inst.items %}
 | 
				
			||||||
                                                    <tr>
 | 
					                                                    <tr>
 | 
				
			||||||
                                                        <td><a href="{% url 'instance' host.0 vm %}">{{ vm }}</a><br><small><em>{{ info.title }}</em></small></td>
 | 
					                                                        <td><a href="{% url 'instance' host.0 vm %}">{{ vm }}</a><br><small><em>{{ info.title }}</em></small></td>
 | 
				
			||||||
                                                        <td><a href="{% url 'overview' host.0 %}">{{ host.1 }}</a></td>
 | 
					                                                        <td><a href="{% url 'overview' host.0 %}">{{ host.1 }}</a><br><small><em>{% if info.userinstances.count > 0 %}{{ info.userinstances.first_user.user.username }}{% if info.userinstances.count > 1 %} (+{{ info.userinstances.count|add:"-1" }}){% endif %}{% endif %}</em></small></td>
 | 
				
			||||||
                                                        <td>{% ifequal info.status 1 %}
 | 
					                                                        <td>{% ifequal info.status 1 %}
 | 
				
			||||||
                                                                <span class="text-success">{% trans "Active" %}</span>
 | 
					                                                                <span class="text-success">{% trans "Active" %}</span>
 | 
				
			||||||
                                                            {% endifequal %}
 | 
					                                                            {% endifequal %}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -45,6 +45,16 @@ def instances(request):
 | 
				
			||||||
    all_user_vms = {}
 | 
					    all_user_vms = {}
 | 
				
			||||||
    computes = Compute.objects.all()
 | 
					    computes = Compute.objects.all()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def get_userinstances_info(instance):
 | 
				
			||||||
 | 
					        info = {}
 | 
				
			||||||
 | 
					        uis = UserInstance.objects.filter(instance=instance)
 | 
				
			||||||
 | 
					        info['count'] = len(uis)
 | 
				
			||||||
 | 
					        if len(uis) > 0:
 | 
				
			||||||
 | 
					            info['first_user'] = uis[0]
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            info['first_user'] = None
 | 
				
			||||||
 | 
					        return info
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if not request.user.is_superuser:
 | 
					    if not request.user.is_superuser:
 | 
				
			||||||
        user_instances = UserInstance.objects.filter(user_id=request.user.id)
 | 
					        user_instances = UserInstance.objects.filter(user_id=request.user.id)
 | 
				
			||||||
        for usr_inst in user_instances:
 | 
					        for usr_inst in user_instances:
 | 
				
			||||||
| 
						 | 
					@ -69,6 +79,7 @@ def instances(request):
 | 
				
			||||||
                                if check_uuid.uuid != info['uuid']:
 | 
					                                if check_uuid.uuid != info['uuid']:
 | 
				
			||||||
                                    check_uuid.save()
 | 
					                                    check_uuid.save()
 | 
				
			||||||
                                all_host_vms[comp.id, comp.name][vm]['is_template'] = check_uuid.is_template
 | 
					                                all_host_vms[comp.id, comp.name][vm]['is_template'] = check_uuid.is_template
 | 
				
			||||||
 | 
					                                all_host_vms[comp.id, comp.name][vm]['userinstances'] = get_userinstances_info(check_uuid)
 | 
				
			||||||
                            except Instance.DoesNotExist:
 | 
					                            except Instance.DoesNotExist:
 | 
				
			||||||
                                check_uuid = Instance(compute_id=comp.id, name=vm, uuid=info['uuid'])
 | 
					                                check_uuid = Instance(compute_id=comp.id, name=vm, uuid=info['uuid'])
 | 
				
			||||||
                                check_uuid.save()
 | 
					                                check_uuid.save()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,7 +12,7 @@ body {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.container {
 | 
					.container {
 | 
				
			||||||
    max-width: 768px;
 | 
					    max-width: 900px;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.page-header {
 | 
					.page-header {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue