diff --git a/computers/forms.py b/computers/forms.py index de4819d..1e6663d 100644 --- a/computers/forms.py +++ b/computers/forms.py @@ -8,6 +8,7 @@ from computers.models import ComputerDiskRelation from computers.models import ComputerGpuRelation from computers.models import ComputerRamRelation from computers.models import ComputerSoftwareRelation +from computers.models import Raid class ComputerCreateForm(forms.ModelForm): @@ -81,3 +82,12 @@ class ComputerSoftwareRelationCreateForm(forms.ModelForm): class Meta: model = ComputerSoftwareRelation fields = '__all__' + + +class RaidCreateForm(forms.ModelForm): + """ + Basic form class to use crispies HTML5 forms. + """ + class Meta: + model = Raid + fields = '__all__' diff --git a/computers/templates/computers/computer_details.html b/computers/templates/computers/computer_details.html index 112aa7f..66af12d 100644 --- a/computers/templates/computers/computer_details.html +++ b/computers/templates/computers/computer_details.html @@ -107,10 +107,9 @@ Type: {{ raid.raid_type }} - - Usable Space {{ raid.usable_space }} + delete {% if disks %} {% for disk in disks %} @@ -126,7 +125,7 @@ {% endif %} {% endfor %} -

add

+

add

diff --git a/computers/templates/computers/raid_create.html b/computers/templates/computers/raid_create.html new file mode 100644 index 0000000..ba5c03e --- /dev/null +++ b/computers/templates/computers/raid_create.html @@ -0,0 +1,14 @@ +{% extends "core/base.html" %} +{% load crispy_forms_tags %} + +{% block section_title %}Add RAID{% endblock %} +{% block content %} +
+
+ {% csrf_token %} + {{ form|crispy }} + + Cancel +
+
+{% endblock %} diff --git a/computers/tests/test_computer_form_views.py b/computers/tests/test_computer_form_views.py index 3363702..a82157f 100644 --- a/computers/tests/test_computer_form_views.py +++ b/computers/tests/test_computer_form_views.py @@ -128,6 +128,19 @@ def test_software_relation_create_view(create_admin_user): assert response.status_code == 302 +def test_raid_create_view(create_admin_user): + create_admin_user() + client = Client() + client.login(username="pharma-admin", password="password") + computer = mixer.blend('computers.Computer', customer=mixer.SELECT) + data = { + 'computer': computer.id, + } + url = '/computer/{}/create/raid/'.format(computer.id) + response = client.post(url, data) + assert response.status_code == 302 + + def test_ram_relation_delete_view(create_admin_user): create_admin_user() client = Client() @@ -191,3 +204,14 @@ def test_software_relation_delete_view(create_admin_user): url = '/delete/software-relation/{}/'.format(software_relation.id) response = client.post(url) assert response.status_code == 302 + + +def test_raid_delete_view(create_admin_user): + create_admin_user() + client = Client() + client.login(username="pharma-admin", password="password") + computer = mixer.blend('computers.Computer', customer=mixer.SELECT) + raid = mixer.blend('computers.Raid', computer=computer) + url = '/delete/raid/{}/'.format(raid.id) + response = client.post(url) + assert response.status_code == 302 diff --git a/computers/urls.py b/computers/urls.py index fad56a2..4e26b9b 100644 --- a/computers/urls.py +++ b/computers/urls.py @@ -50,4 +50,8 @@ urlpatterns = [ path('delete/software-relation//', views.ComputerSoftwareRelationDeleteView.as_view(), name='software_relation_delete'), + path('computer//create/raid/', views.RaidCreateView.as_view(), + name='raid_create'), + path('delete/raid//', views.RaidDeleteView.as_view(), + name='raid_delete'), ] diff --git a/computers/views.py b/computers/views.py index e2d9eae..ba5d519 100644 --- a/computers/views.py +++ b/computers/views.py @@ -28,6 +28,7 @@ from .forms import ComputerDiskRelationCreateForm from .forms import ComputerGpuRelationCreateForm from .forms import ComputerRamRelationCreateForm from .forms import ComputerSoftwareRelationCreateForm +from .forms import RaidCreateForm from .models import Computer from .models import ComputerCpuRelation from .models import ComputerDiskRelation @@ -274,3 +275,31 @@ class ComputerSoftwareRelationDeleteView(LoginRequiredMixin, DeleteView): def get_success_url(self): return reverse('computer', args=(self.object.computer.pk,)) + +class RaidCreateView(LoginRequiredMixin, CreateView): + model = Raid + form_class = RaidCreateForm + template_name = 'computers/raid_create.html' + + def get_success_url(self): + return reverse('computer', args=(self.computer.pk,)) + + def get_initial(self): + """ + Set the device and customer dropdown to the device from the previous + view and the customer related to the device. + """ + self.computer = get_object_or_404(Computer, id=self.kwargs.get('pk')) + return { + 'computer': self.computer, + } + + +class RaidDeleteView(LoginRequiredMixin, DeleteView): + model = Raid + template_name = 'computers/relation_confirm_delete.html' + + def get_success_url(self): + return reverse('computer', args=(self.object.computer.pk,)) + +