add LicenseWithComputerCreateView
This commit is contained in:
parent
16fc66385f
commit
efaead7d7d
|
@ -7,4 +7,4 @@
|
|||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
<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 'license_with_computer_create' pk %}" class="add" title="Add" data-toggle="tooltip"><i class="material-icons">add</i></a></p>
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
{% extends "core/base.html" %}
|
||||
{% load crispy_forms_tags %}
|
||||
|
||||
{% block section_title %}Add License{% 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 %}
|
|
@ -0,0 +1,24 @@
|
|||
from django.test import Client
|
||||
from mixer.backend.django import mixer
|
||||
import pytest
|
||||
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
||||
|
||||
def test_license_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)
|
||||
license = mixer.blend('licenses.ComputerLicense')
|
||||
data = {
|
||||
'computer': computer.id,
|
||||
'license': license.id,
|
||||
'amount': 1
|
||||
}
|
||||
url = '/create/license-with/computer/{}/'.format(computer.id)
|
||||
response = client.post(url, data)
|
||||
assert response.status_code == 302
|
||||
|
||||
|
|
@ -3,6 +3,9 @@ from django.urls import path
|
|||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('customer/<int:pk>/licenses/', views.licenses_table_view,
|
||||
name='licenses'),
|
||||
path('customer/<int:pk>/licenses/', views.licenses_table_view,
|
||||
name='licenses'),
|
||||
path('create/license-with/computer/<int:pk>/',
|
||||
views.LicenseWithComputerCreateView.as_view(),
|
||||
name='license_with_computer_create'),
|
||||
]
|
||||
|
|
|
@ -1,12 +1,19 @@
|
|||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.shortcuts import render
|
||||
from django.urls import reverse
|
||||
from django.views.generic import CreateView
|
||||
|
||||
from django_tables2 import RequestConfig
|
||||
|
||||
from customers.decorators import customer_view_permission
|
||||
|
||||
from computers.models import Computer
|
||||
|
||||
from .models import ComputerLicense
|
||||
from .models import UserLicense
|
||||
from .models import LicenseWithComputer
|
||||
from .tables import ComputerLicensesTable
|
||||
from .tables import UserLicensesTable
|
||||
# Create your views here.
|
||||
|
@ -24,3 +31,23 @@ def licenses_table_view(request, pk):
|
|||
'licenses/license_list.html',
|
||||
{'user_licenses': user_licenses,
|
||||
'computer_licenses': computer_licenses})
|
||||
|
||||
|
||||
class LicenseWithComputerCreateView(LoginRequiredMixin, CreateView):
|
||||
model = LicenseWithComputer
|
||||
#form_class = ComputerSoftwareRelationCreateForm
|
||||
template_name = 'licenses/license_with_computer_create.html'
|
||||
fields = '__all__'
|
||||
|
||||
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