sst/storage_templates #3
@ -91,7 +91,7 @@ class AutocompleteForeingKeyField(forms.UUIDField):
|
|||||||
class MyTestForm(forms.Form):
|
class MyTestForm(forms.Form):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class AddSubStorageForm(forms.Form):
|
class ChangeStorageForm(forms.Form):
|
||||||
storage_name = forms.CharField(label="storage_name", initial='')
|
storage_name = forms.CharField(label="storage_name", initial='')
|
||||||
responsible = AutocompleteForeingKeyField(api_search_url='user-list',
|
responsible = AutocompleteForeingKeyField(api_search_url='user-list',
|
||||||
image_field_name=None,
|
image_field_name=None,
|
||||||
@ -100,6 +100,8 @@ class AddSubStorageForm(forms.Form):
|
|||||||
prepend='@')
|
prepend='@')
|
||||||
|
|
||||||
is_template = forms.BooleanField(label='is_template', required=False)
|
is_template = forms.BooleanField(label='is_template', required=False)
|
||||||
|
|
||||||
|
class AddSubStorageForm(ChangeStorageForm):
|
||||||
template = AutocompleteForeingKeyField(api_search_url='storage-template-list',
|
template = AutocompleteForeingKeyField(api_search_url='storage-template-list',
|
||||||
image_field_name=None,
|
image_field_name=None,
|
||||||
foreign_model=parts_models.Storage,
|
foreign_model=parts_models.Storage,
|
||||||
|
@ -482,6 +482,11 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
|||||||
add_storage_form = AddSubStorageForm()
|
add_storage_form = AddSubStorageForm()
|
||||||
add_storage_form.fields['responsible'].initial = self.request.user.id
|
add_storage_form.fields['responsible'].initial = self.request.user.id
|
||||||
context['add_storage_form'] = add_storage_form
|
context['add_storage_form'] = add_storage_form
|
||||||
|
change_storage_form = ChangeStorageForm()
|
||||||
|
change_storage_form.fields['storage_name'].initial = self.object.name
|
||||||
|
change_storage_form.fields['responsible'].initial = self.object.responsible.id
|
||||||
|
change_storage_form.fields['is_template'].initial = self.object.is_template
|
||||||
|
context['change_storage_form'] = change_storage_form
|
||||||
context['delete_storage_error'] = None
|
context['delete_storage_error'] = None
|
||||||
context['add_stock_form'] = AddStockForm()
|
context['add_stock_form'] = AddStockForm()
|
||||||
|
|
||||||
@ -503,6 +508,21 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
|||||||
context['add_storage_form'] = f
|
context['add_storage_form'] = f
|
||||||
return self.render_to_response(context)
|
return self.render_to_response(context)
|
||||||
|
|
||||||
|
def handle_change_storage_post(self, request, **kwargs):
|
||||||
|
f = ChangeStorageForm(data=request.POST)
|
||||||
|
if f.is_valid():
|
||||||
|
sub_name = f.cleaned_data['storage_name']
|
||||||
|
try:
|
||||||
|
self.object.name = f.cleaned_data['storage_name']
|
||||||
|
self.object.responsible = f.cleaned_data['responsible']
|
||||||
|
self.object.is_template = f.cleaned_data['is_template']
|
||||||
|
self.object.save()
|
||||||
|
except ValidationError as v_err:
|
||||||
|
f.add_error('storage_name', '. '.join(v_err.messages))
|
||||||
|
context = self.get_context_data(**kwargs)
|
||||||
|
context['change_storage_form'] = f
|
||||||
|
return self.render_to_response(context)
|
||||||
|
|
||||||
def handle_del_storage_post(self, request, **kwargs):
|
def handle_del_storage_post(self, request, **kwargs):
|
||||||
parent = self.object.parent_storage
|
parent = self.object.parent_storage
|
||||||
try:
|
try:
|
||||||
@ -578,6 +598,8 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
|||||||
|
|
||||||
if 'submit-add-storage' in request.POST:
|
if 'submit-add-storage' in request.POST:
|
||||||
return self.handle_add_storage_post(request, **kwargs)
|
return self.handle_add_storage_post(request, **kwargs)
|
||||||
|
if 'submit-change-storage' in request.POST:
|
||||||
|
return self.handle_change_storage_post(request, **kwargs)
|
||||||
elif 'submit-delete-storage' in request.POST:
|
elif 'submit-delete-storage' in request.POST:
|
||||||
return self.handle_del_storage_post(request, **kwargs)
|
return self.handle_del_storage_post(request, **kwargs)
|
||||||
elif 'submit-delete-stock' in request.POST:
|
elif 'submit-delete-stock' in request.POST:
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
{% load static %}
|
||||||
|
{% load crispy_forms_tags %}
|
||||||
|
<div class="modal fade" id="change-modal">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title">Change Storage</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<form method="post" enctype="multipart/form-data">
|
||||||
|
{% csrf_token %}
|
||||||
|
<div class="modal-body">
|
||||||
|
{{form|crispy}}
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||||
|
<input type="submit" class="btn btn-primary" value="Change Storage" name="submit-change-storage">
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
@ -27,6 +27,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
<button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#delete-storage-modal">Delete</button>
|
<button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#delete-storage-modal">Delete</button>
|
||||||
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#add-sub-modal"><i class="bi bi-plus-circle"></i></button>
|
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#add-sub-modal"><i class="bi bi-plus-circle"></i></button>
|
||||||
|
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#change-modal"><i class="bi bi-pen-fill"></i></button>
|
||||||
</h1>
|
</h1>
|
||||||
<div class="list-group">
|
<div class="list-group">
|
||||||
{% for storage in storages %}
|
{% for storage in storages %}
|
||||||
@ -109,11 +110,11 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
<!-- Modal for adding a substorage-->
|
<!-- Modal for adding a substorage-->
|
||||||
{% with add_storage_form as form %}
|
{% with add_storage_form as form %}
|
||||||
{% include 'parts/modals/substorage-modal.html' %}
|
{% include 'parts/modals/add-substorage-modal.html' %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
<!-- Modal to change current storag-->
|
<!-- Modal to change current storag-->
|
||||||
{% with change_storage_form as form %}
|
{% with change_storage_form as form %}
|
||||||
{% include 'parts/modals/substorage-modal.html' %}
|
{% include 'parts/modals/change-storage-modal.html' %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
<!-- Modal for deleting this storage -->
|
<!-- Modal for deleting this storage -->
|
||||||
{% with delete_storage_errors as err_msgs %}
|
{% with delete_storage_errors as err_msgs %}
|
||||||
|
@ -53,8 +53,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Add storage modal form -->
|
<!-- Add storage modal form -->
|
||||||
{% with add_storage_form as form %}
|
{% with add_storage_form as form id as "add-sub-modal"%}
|
||||||
{% include 'parts/modals/substorage-modal.html' %}
|
{% include 'parts/modals/add-substorage-modal.html' %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user