mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add forms / views for creating / editing / deleting test templates
This commit is contained in:
parent
cd0e66e3c6
commit
e30f6ec374
@ -15,6 +15,7 @@ from django.utils.translation import ugettext as _
|
|||||||
from .models import Part, PartCategory, PartAttachment
|
from .models import Part, PartCategory, PartAttachment
|
||||||
from .models import BomItem
|
from .models import BomItem
|
||||||
from .models import PartParameterTemplate, PartParameter
|
from .models import PartParameterTemplate, PartParameter
|
||||||
|
from .models import PartTestTemplate
|
||||||
|
|
||||||
from common.models import Currency
|
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):
|
class BomExportForm(forms.Form):
|
||||||
""" Simple form to let user set BOM export options,
|
""" Simple form to let user set BOM export options,
|
||||||
before exporting a BOM (bill of materials) file.
|
before exporting a BOM (bill of materials) 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 %}
|
{% endblock %}
|
@ -108,6 +108,13 @@ part_urls = [
|
|||||||
# Part attachments
|
# Part attachments
|
||||||
url(r'^attachment/', include(part_attachment_urls)),
|
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
|
# Part parameters
|
||||||
url(r'^parameter/', include(part_parameter_urls)),
|
url(r'^parameter/', include(part_parameter_urls)),
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ from .models import PartCategory, Part, PartAttachment
|
|||||||
from .models import PartParameterTemplate, PartParameter
|
from .models import PartParameterTemplate, PartParameter
|
||||||
from .models import BomItem
|
from .models import BomItem
|
||||||
from .models import match_part_names
|
from .models import match_part_names
|
||||||
|
from .models import PartTestTemplate
|
||||||
|
|
||||||
from common.models import Currency, InvenTreeSetting
|
from common.models import Currency, InvenTreeSetting
|
||||||
from company.models import SupplierPart
|
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):
|
class PartSetCategory(AjaxUpdateView):
|
||||||
""" View for settings the part category for multiple parts at once """
|
""" View for settings the part category for multiple parts at once """
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user