mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #815 from SchrodingersGat/delete-test-data
Delete test data
This commit is contained in:
commit
1c67bb6026
@ -5,6 +5,7 @@ Helper forms which subclass Django forms to provide additional functionality
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
from django import forms
|
||||
from crispy_forms.helper import FormHelper
|
||||
from crispy_forms.layout import Layout, Field
|
||||
@ -92,6 +93,20 @@ class HelperForm(forms.ModelForm):
|
||||
self.helper.layout = Layout(*layouts)
|
||||
|
||||
|
||||
class ConfirmForm(forms.Form):
|
||||
""" Generic confirmation form """
|
||||
|
||||
confirm = forms.BooleanField(
|
||||
required=False, initial=False,
|
||||
help_text=_("Confirm")
|
||||
)
|
||||
|
||||
class Meta:
|
||||
fields = [
|
||||
'confirm'
|
||||
]
|
||||
|
||||
|
||||
class DeleteForm(forms.Form):
|
||||
""" Generic deletion form which provides simple user confirmation
|
||||
"""
|
||||
@ -99,7 +114,7 @@ class DeleteForm(forms.Form):
|
||||
confirm_delete = forms.BooleanField(
|
||||
required=False,
|
||||
initial=False,
|
||||
help_text='Confirm item deletion'
|
||||
help_text=_('Confirm item deletion')
|
||||
)
|
||||
|
||||
class Meta:
|
||||
@ -131,14 +146,14 @@ class SetPasswordForm(HelperForm):
|
||||
required=True,
|
||||
initial='',
|
||||
widget=forms.PasswordInput(attrs={'autocomplete': 'off'}),
|
||||
help_text='Enter new password')
|
||||
help_text=_('Enter new password'))
|
||||
|
||||
confirm_password = forms.CharField(max_length=100,
|
||||
min_length=8,
|
||||
required=True,
|
||||
initial='',
|
||||
widget=forms.PasswordInput(attrs={'autocomplete': 'off'}),
|
||||
help_text='Confirm new password')
|
||||
help_text=_('Confirm new password'))
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
|
@ -14,6 +14,9 @@
|
||||
<div class='button-toolbar container-fluid' style="float: right;">
|
||||
<div class='btn-group' role='group'>
|
||||
<button type='button' class='btn btn-success' id='add-test-result'>{% trans "Add Test Data" %}</button>
|
||||
{% if user.is_staff %}
|
||||
<button type='button' class='btn btn-danger' id='delete-test-results'>{% trans "Delete Test Data" %}</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class='filter-list' id='filter-list-stocktests'>
|
||||
<!-- Empty div -->
|
||||
@ -40,6 +43,17 @@ function reloadTable() {
|
||||
//$("#test-result-table").bootstrapTable("refresh");
|
||||
}
|
||||
|
||||
{% if user.is_staff %}
|
||||
$("#delete-test-results").click(function() {
|
||||
launchModalForm(
|
||||
"{% url 'stock-item-delete-test-data' item.id %}",
|
||||
{
|
||||
success: reloadTable,
|
||||
}
|
||||
);
|
||||
});
|
||||
{% endif %}
|
||||
|
||||
$("#add-test-result").click(function() {
|
||||
launchModalForm(
|
||||
"{% url 'stock-item-test-create' %}", {
|
||||
|
@ -21,6 +21,7 @@ stock_item_detail_urls = [
|
||||
url(r'^serialize/', views.StockItemSerialize.as_view(), name='stock-item-serialize'),
|
||||
url(r'^delete/', views.StockItemDelete.as_view(), name='stock-item-delete'),
|
||||
url(r'^qr_code/', views.StockItemQRCode.as_view(), name='stock-item-qr'),
|
||||
url(r'^delete_test_data/', views.StockItemDeleteTestData.as_view(), name='stock-item-delete-test-data'),
|
||||
|
||||
url(r'^add_tracking/', views.StockItemTrackingCreate.as_view(), name='stock-tracking-create'),
|
||||
|
||||
|
@ -17,6 +17,7 @@ from django.utils.translation import ugettext as _
|
||||
from InvenTree.views import AjaxView
|
||||
from InvenTree.views import AjaxUpdateView, AjaxDeleteView, AjaxCreateView
|
||||
from InvenTree.views import QRCodeView
|
||||
from InvenTree.forms import ConfirmForm
|
||||
|
||||
from InvenTree.helpers import str2bool, DownloadFile, GetExportFormats
|
||||
from InvenTree.helpers import ExtractSerialNumbers
|
||||
@ -229,6 +230,41 @@ class StockItemAttachmentDelete(AjaxDeleteView):
|
||||
}
|
||||
|
||||
|
||||
class StockItemDeleteTestData(AjaxUpdateView):
|
||||
"""
|
||||
View for deleting all test data
|
||||
"""
|
||||
|
||||
model = StockItem
|
||||
form_class = ConfirmForm
|
||||
ajax_form_title = _("Delete All Test Data")
|
||||
|
||||
def get_form(self):
|
||||
return ConfirmForm()
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
|
||||
valid = False
|
||||
|
||||
stock_item = StockItem.objects.get(pk=self.kwargs['pk'])
|
||||
form = self.get_form()
|
||||
|
||||
confirm = str2bool(request.POST.get('confirm', False))
|
||||
|
||||
if confirm is not True:
|
||||
form.errors['confirm'] = [_('Confirm test data deletion')]
|
||||
form.non_field_errors = [_('Check the confirmation box')]
|
||||
else:
|
||||
stock_item.test_results.all().delete()
|
||||
valid = True
|
||||
|
||||
data = {
|
||||
'form_valid': valid,
|
||||
}
|
||||
|
||||
return self.renderJsonResponse(request, form, data)
|
||||
|
||||
|
||||
class StockItemTestResultCreate(AjaxCreateView):
|
||||
"""
|
||||
View for adding a new StockItemTestResult
|
||||
|
Loading…
Reference in New Issue
Block a user