Merge branch 'gpu'
This commit is contained in:
commit
0aa4a43e13
|
@ -8,6 +8,7 @@ from .models import (
|
|||
Computer,
|
||||
ComputerCpuRelation,
|
||||
ComputerDiskRelation,
|
||||
ComputerGpuRelation,
|
||||
ComputerRamRelation,
|
||||
ComputerSoftwareRelation,
|
||||
Cpu,
|
||||
|
@ -16,6 +17,8 @@ from .models import (
|
|||
Disk,
|
||||
DiskType,
|
||||
DisksInRaid,
|
||||
Gpu,
|
||||
GpuManufacturer,
|
||||
Raid,
|
||||
RaidType,
|
||||
Ram,
|
||||
|
@ -47,6 +50,22 @@ class CpuManufacturerAdmin(admin.ModelAdmin):
|
|||
return {}
|
||||
|
||||
|
||||
class GpuAdmin(admin.ModelAdmin):
|
||||
def get_model_perms(self, request):
|
||||
"""
|
||||
Return empty perms dict thus hiding the model from admin index.
|
||||
"""
|
||||
return {}
|
||||
|
||||
|
||||
class GpuManufacturerAdmin(admin.ModelAdmin):
|
||||
def get_model_perms(self, request):
|
||||
"""
|
||||
Return empty perms dict thus hiding the model from admin index.
|
||||
"""
|
||||
return {}
|
||||
|
||||
|
||||
class IpStatusAdmin(admin.ModelAdmin):
|
||||
def get_model_perms(self, request):
|
||||
"""
|
||||
|
@ -125,6 +144,12 @@ class CpusInLine(nested_admin.NestedStackedInline):
|
|||
verbose_name_plural = 'CPUs'
|
||||
|
||||
|
||||
class GpusInLine(nested_admin.NestedStackedInline):
|
||||
model = ComputerGpuRelation
|
||||
extra = 0
|
||||
verbose_name_plural = 'GPUs'
|
||||
|
||||
|
||||
class RaidInLine(nested_admin.NestedStackedInline):
|
||||
model = Raid
|
||||
extra = 0
|
||||
|
@ -146,8 +171,8 @@ class LicenseWithComputerInLine(nested_admin.NestedStackedInline):
|
|||
|
||||
class ComputerAdmin(nested_admin.NestedModelAdmin):
|
||||
list_display = ('name', 'host')
|
||||
inlines = (SoftwareInLine, CpusInLine, RamInLine, DiskInLine, RaidInLine,
|
||||
DeviceInNetInline, LicenseWithComputerInLine)
|
||||
inlines = (SoftwareInLine, CpusInLine, GpusInLine, RamInLine, DiskInLine,
|
||||
RaidInLine, DeviceInNetInline, LicenseWithComputerInLine)
|
||||
|
||||
|
||||
admin.site.register(Computer, ComputerAdmin)
|
||||
|
@ -156,6 +181,8 @@ admin.site.register(CpuArchitecture, CpuArchitectureAdmin)
|
|||
admin.site.register(CpuManufacturer, CpuManufacturerAdmin)
|
||||
admin.site.register(Disk)
|
||||
admin.site.register(DiskType, DiskTypeAdmin)
|
||||
admin.site.register(Gpu, GpuAdmin)
|
||||
admin.site.register(GpuManufacturer, GpuManufacturerAdmin)
|
||||
admin.site.register(RaidType, RaidTypeAdmin)
|
||||
admin.site.register(Ram, RamModuleAdmin)
|
||||
admin.site.register(RamType, RamTypeAdmin)
|
||||
|
|
|
@ -17,6 +17,16 @@
|
|||
fields:
|
||||
name: ARM64
|
||||
|
||||
- model: computers.GpuManufacturer
|
||||
fields:
|
||||
name: Intel
|
||||
- model: computers.GpuManufacturer
|
||||
fields:
|
||||
name: AMD
|
||||
- model: computers.GpuManufacturer
|
||||
fields:
|
||||
name: Nvidia
|
||||
|
||||
- model: computers.RamType
|
||||
fields:
|
||||
name: unkown
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
from .computer import (Computer, ComputerCpuRelation, ComputerDiskRelation,
|
||||
from .computer import (Computer,
|
||||
ComputerCpuRelation,
|
||||
ComputerDiskRelation,
|
||||
ComputerGpuRelation,
|
||||
ComputerRamRelation,
|
||||
ComputerSoftwareRelation)
|
||||
from .cpu import CpuArchitecture, CpuManufacturer, Cpu
|
||||
from .disk import DiskType, Disk
|
||||
from .gpu import GpuManufacturer, Gpu
|
||||
from .raid import DisksInRaid, RaidType, Raid
|
||||
from .ram import RamType, Ram
|
||||
|
|
|
@ -7,6 +7,7 @@ from softwares.models import SoftwareArchitecture
|
|||
from .cpu import Cpu
|
||||
from devices.models import ConnectedDevice
|
||||
from .disk import Disk
|
||||
from .gpu import Gpu
|
||||
from .ram import Ram
|
||||
|
||||
|
||||
|
@ -15,6 +16,7 @@ class Computer(ConnectedDevice):
|
|||
null=True, verbose_name='OS')
|
||||
cpu = models.ManyToManyField(Cpu, through='ComputerCpuRelation')
|
||||
ram = models.ManyToManyField(Ram, through='ComputerRamRelation')
|
||||
gpu = models.ManyToManyField(Gpu, through='ComputerGpuRelation')
|
||||
disks = models.ManyToManyField(Disk, through='ComputerDiskRelation')
|
||||
software = models.ManyToManyField(Software,
|
||||
through='ComputerSoftwareRelation')
|
||||
|
@ -80,3 +82,16 @@ class ComputerSoftwareRelation(models.Model):
|
|||
|
||||
class Meta:
|
||||
verbose_name_plural = "Software on Computer"
|
||||
|
||||
|
||||
class ComputerGpuRelation(models.Model):
|
||||
gpu = models.ForeignKey(Gpu, on_delete=models.CASCADE)
|
||||
computer = models.ForeignKey(Computer, on_delete=models.CASCADE)
|
||||
amount = models.IntegerField()
|
||||
|
||||
def __str__(self):
|
||||
return self.computer.name
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "GPUs in Computer"
|
||||
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
from django.db import models
|
||||
from core.models import Company
|
||||
|
||||
|
||||
class GpuManufacturer(Company):
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "GPU Manufacturers"
|
||||
|
||||
|
||||
class Gpu(models.Model):
|
||||
name = models.CharField(max_length=50)
|
||||
manufacturer = models.ForeignKey(GpuManufacturer, on_delete=models.CASCADE)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "GPUs"
|
|
@ -21,8 +21,8 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{% if device.os or software_relations or backup_relations or license_list or device.host %}
|
||||
<div class="row">
|
||||
{% if device.os or software_relations or backup_relations or license_list or device.host %}
|
||||
<div class="col">
|
||||
<div class="card mt-3">
|
||||
<div class="card-body">
|
||||
|
@ -68,12 +68,12 @@
|
|||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if cpu_relations or ram_relations or disks_relations or raid_disk_pairs %}
|
||||
{% if cpu_relations or gpu_relations or ram_relations or disks_relations or raid_disk_pairs %}
|
||||
<div class="col">
|
||||
<div class="card mt-3">
|
||||
<h2 class="card-header">Hardware</h2>
|
||||
<div class="card-body">
|
||||
{% if cpu_relations or ram_relations or disks_relations or device.host %}
|
||||
{% if cpu_relations or gpu_relations or ram_relations or disks_relations or device.host %}
|
||||
<table class="table table-bordered">
|
||||
{% if cpu_relations %}
|
||||
<tr>
|
||||
|
@ -86,6 +86,17 @@
|
|||
</tr>
|
||||
{% endif %}
|
||||
|
||||
{% if gpu_relations %}
|
||||
<tr>
|
||||
<td><b>GPUs:</b></td>
|
||||
<td>
|
||||
{% for gpu in gpu_relations %}
|
||||
{{ gpu.amount }}x {{ gpu.gpu }}<br>
|
||||
{% endfor %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
|
||||
{% if ram_relations %}
|
||||
<tr>
|
||||
<td><b>RAM Modules:</b></td>
|
||||
|
@ -141,5 +152,5 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -63,7 +63,9 @@ def test_computer_detail_view_raid_relation(create_admin_user):
|
|||
def test_computer_detail_view_cpu_relation(create_admin_user):
|
||||
create_admin_user()
|
||||
computer = mixer.blend('computers.Computer', customer=mixer.SELECT)
|
||||
cpu = mixer.blend('computers.Cpu', cpu_typ=mixer.SELECT)
|
||||
cpu = mixer.blend('computers.Cpu',
|
||||
architecture=mixer.SELECT,
|
||||
manufacturer=mixer.SELECT)
|
||||
mixer.blend('computers.ComputerCpuRelation', cpu=cpu, computer=computer)
|
||||
client = Client()
|
||||
client.login(username="pharma-admin", password="password")
|
||||
|
@ -80,3 +82,17 @@ def test_computer_detail_view_no_permission(create_admin_user):
|
|||
client.login(username="pharma-admin", password="password")
|
||||
response = client.get('/computer/' + str(computer.id) + '/')
|
||||
assert response.status_code == 403
|
||||
|
||||
|
||||
def test_computer_detail_view_gpu_relation(create_admin_user):
|
||||
create_admin_user()
|
||||
computer = mixer.blend('computers.Computer', customer=mixer.SELECT)
|
||||
gpu = mixer.blend('computers.Gpu', manufacturer=mixer.SELECT)
|
||||
mixer.blend('computers.ComputerGpuRelation', gpu=gpu, computer=computer)
|
||||
client = Client()
|
||||
client.login(username="pharma-admin", password="password")
|
||||
response = client.get('/computer/' + str(computer.id) + '/')
|
||||
assert (response.status_code == 200
|
||||
and helper.in_content(response, gpu))
|
||||
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ from .forms import RamFormSet
|
|||
from .models import Computer
|
||||
from .models import ComputerCpuRelation
|
||||
from .models import ComputerDiskRelation
|
||||
from .models import ComputerGpuRelation
|
||||
from .models import ComputerRamRelation
|
||||
from .models import ComputerSoftwareRelation
|
||||
from .models import DisksInRaid
|
||||
|
@ -41,6 +42,7 @@ def computer_detail_view(request, pk):
|
|||
warranty_relations = Warranty.objects.filter(device=pk)
|
||||
ram_relations = ComputerRamRelation.objects.filter(computer=pk)
|
||||
cpu_relations = ComputerCpuRelation.objects.filter(computer=pk)
|
||||
gpu_relations = ComputerGpuRelation.objects.filter(computer=pk)
|
||||
software_relations = ComputerSoftwareRelation.objects.filter(computer=pk)
|
||||
license_list = LicenseWithComputer.objects.filter(computer=pk)
|
||||
raid_disk_pairs = {}
|
||||
|
@ -52,6 +54,7 @@ def computer_detail_view(request, pk):
|
|||
'disks_relations': disks_relations,
|
||||
'ram_relations': ram_relations,
|
||||
'cpu_relations': cpu_relations,
|
||||
'gpu_relations': gpu_relations,
|
||||
'software_relations': software_relations,
|
||||
'raid_disk_pairs': raid_disk_pairs,
|
||||
'backup_relations': backup_list,
|
||||
|
|
Loading…
Reference in New Issue