add a form to create a ComputerSoftwareRelation
This commit is contained in:
parent
d08a1f0557
commit
61d966f785
|
@ -7,6 +7,7 @@ from computers.models import ComputerCpuRelation
|
|||
from computers.models import ComputerDiskRelation
|
||||
from computers.models import ComputerGpuRelation
|
||||
from computers.models import ComputerRamRelation
|
||||
from computers.models import ComputerSoftwareRelation
|
||||
|
||||
|
||||
class ComputerCreateForm(forms.ModelForm):
|
||||
|
@ -71,3 +72,12 @@ class ComputerDiskRelationCreateForm(forms.ModelForm):
|
|||
class Meta:
|
||||
model = ComputerDiskRelation
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class ComputerSoftwareRelationCreateForm(forms.ModelForm):
|
||||
"""
|
||||
Basic form class to use crispies HTML5 forms.
|
||||
"""
|
||||
class Meta:
|
||||
model = ComputerSoftwareRelation
|
||||
fields = '__all__'
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
<li>{{ relation.software }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<p><a href="{% url 'warranty_create' pk %}" class="add" title="Add" data-toggle="tooltip"><i class="material-icons">add</i></a></p>
|
||||
<p><a href="{% url 'software_relation_create' pk %}" class="add" title="Add" data-toggle="tooltip"><i class="material-icons">add</i></a></p>
|
||||
|
||||
{% block license %}
|
||||
{% include "licenses/license_block.html" %}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
{% extends "core/base.html" %}
|
||||
{% load crispy_forms_tags %}
|
||||
|
||||
{% block section_title %}Add Sofware{% endblock %}
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
<input type="submit" value="Save" class="btn btn-primary">
|
||||
<a href="{% url 'computer' view.kwargs.pk %}" class="btn btn-secondary">Cancel</a>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -112,6 +112,22 @@ def test_disk_relation_create_view(create_admin_user):
|
|||
assert response.status_code == 302
|
||||
|
||||
|
||||
def test_software_relation_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)
|
||||
software = mixer.blend('softwares.Software')
|
||||
data = {
|
||||
'computer': computer.id,
|
||||
'software': software.id,
|
||||
'amount': 1
|
||||
}
|
||||
url = '/computer/{}/create/software-relation/'.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()
|
||||
|
|
|
@ -44,4 +44,7 @@ urlpatterns = [
|
|||
path('delete/disk-relation/<int:pk>/',
|
||||
views.ComputerDiskRelationDeleteView.as_view(),
|
||||
name='disk_relation_delete'),
|
||||
path('computer/<int:pk>/create/software-relation/',
|
||||
views.ComputerSoftwareRelationCreateView.as_view(),
|
||||
name='software_relation_create'),
|
||||
]
|
||||
|
|
|
@ -27,6 +27,7 @@ from .forms import ComputerCpuRelationCreateForm
|
|||
from .forms import ComputerDiskRelationCreateForm
|
||||
from .forms import ComputerGpuRelationCreateForm
|
||||
from .forms import ComputerRamRelationCreateForm
|
||||
from .forms import ComputerSoftwareRelationCreateForm
|
||||
from .models import Computer
|
||||
from .models import ComputerCpuRelation
|
||||
from .models import ComputerDiskRelation
|
||||
|
@ -245,3 +246,23 @@ class ComputerDiskRelationDeleteView(LoginRequiredMixin, DeleteView):
|
|||
|
||||
def get_success_url(self):
|
||||
return reverse('computer', args=(self.object.computer.pk,))
|
||||
|
||||
|
||||
class ComputerSoftwareRelationCreateView(LoginRequiredMixin, CreateView):
|
||||
model = ComputerSoftwareRelation
|
||||
form_class = ComputerSoftwareRelationCreateForm
|
||||
template_name = 'computers/software_relation_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,
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue