Add forms / views for creating / editing / deleting test templates

This commit is contained in:
Oliver Walters 2020-05-17 16:50:34 +10:00
parent cd0e66e3c6
commit e30f6ec374
4 changed files with 107 additions and 0 deletions

View File

@ -15,6 +15,7 @@ from django.utils.translation import ugettext as _
from .models import Part, PartCategory, PartAttachment
from .models import BomItem
from .models import PartParameterTemplate, PartParameter
from .models import PartTestTemplate
from common.models import Currency
@ -29,6 +30,19 @@ class PartImageForm(HelperForm):
]
class EditPartTestTemplateForm(HelperForm):
""" Class for creating / editing a PartTestTemplate object """
class Meta:
model = PartTestTemplate
fields = [
'part',
'test_name',
'required'
]
class BomExportForm(forms.Form):
""" Simple form to let user set BOM export options,
before exporting a BOM (bill of materials) file.

View File

@ -36,4 +36,40 @@ loadPartTestTemplateTable(
}
);
function reloadTable() {
$("#test-template-table").bootstrapTable("refresh");
}
$("#add-test-template").click(function() {
launchModalForm(
"{% url 'part-test-template-create' %}",
{
data: {
part: {{ part.id }},
},
success: reloadTable,
}
);
});
$("#test-template-table").on('click', '.button-test-edit', function() {
var button = $(this);
var url = `/part/test-template/${button.attr('pk')}/edit/`;
launchModalForm(url, {
success: reloadTable,
});
});
$("#test-template-table").on('click', '.button-test-delete', function() {
var button = $(this);
var url = `/part/test-template/${button.attr('pk')}/delete/`;
launchModalForm(url, {
success: reloadTable,
});
});
{% endblock %}

View File

@ -108,6 +108,13 @@ part_urls = [
# Part attachments
url(r'^attachment/', include(part_attachment_urls)),
# Part test templates
url(r'^test-template/', include([
url(r'^new/', views.PartTestTemplateCreate.as_view(), name='part-test-template-create'),
url(r'^(?P<pk>\d+)/edit/', views.PartTestTemplateEdit.as_view(), name='part-test-template-edit'),
url(r'^(?P<pk>\d+)/delete/', views.PartTestTemplateDelete.as_view(), name='part-test-template-delete'),
])),
# Part parameters
url(r'^parameter/', include(part_parameter_urls)),

View File

@ -25,6 +25,7 @@ from .models import PartCategory, Part, PartAttachment
from .models import PartParameterTemplate, PartParameter
from .models import BomItem
from .models import match_part_names
from .models import PartTestTemplate
from common.models import Currency, InvenTreeSetting
from company.models import SupplierPart
@ -149,6 +150,55 @@ class PartAttachmentDelete(AjaxDeleteView):
}
class PartTestTemplateCreate(AjaxCreateView):
""" View for creating a PartTestTemplate """
model = PartTestTemplate
form_class = part_forms.EditPartTestTemplateForm
ajax_form_title = _("Create Test Template")
def get_initial(self):
initials = super().get_initial()
try:
part_id = self.request.GET.get('part', None)
initials['part'] = Part.objects.get(pk=part_id)
except (ValueError, Part.DoesNotExist):
pass
return initials
def get_form(self):
form = super().get_form()
form.fields['part'].widget = HiddenInput()
return form
class PartTestTemplateEdit(AjaxUpdateView):
""" View for editing a PartTestTemplate """
model = PartTestTemplate
form_class = part_forms.EditPartTestTemplateForm
ajax_form_title = _("Edit Test Template")
def get_form(self):
form = super().get_form()
form.fields['part'].widget = HiddenInput()
return form
class PartTestTemplateDelete(AjaxDeleteView):
""" View for deleting a PartTestTemplate """
model = PartTestTemplate
ajax_form_title = _("Delete Test Template")
class PartSetCategory(AjaxUpdateView):
""" View for settings the part category for multiple parts at once """