mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add form for setting part category
This commit is contained in:
parent
94cd28ecb9
commit
08f958dd72
@ -7,6 +7,7 @@ from __future__ import unicode_literals
|
||||
|
||||
from InvenTree.forms import HelperForm
|
||||
|
||||
from mptt.fields import TreeNodeChoiceField
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
@ -66,6 +67,12 @@ class EditPartAttachmentForm(HelperForm):
|
||||
]
|
||||
|
||||
|
||||
class SetPartCategoryForm(forms.Form):
|
||||
""" Form for setting the category of multiple Part objects """
|
||||
|
||||
part_category = TreeNodeChoiceField(queryset=PartCategory.objects.all(), required=True, help_text=_('Select part category'))
|
||||
|
||||
|
||||
class EditPartForm(HelperForm):
|
||||
""" Form for editing a Part object """
|
||||
|
||||
|
@ -2,26 +2,8 @@
|
||||
|
||||
{% block form %}
|
||||
<form method="post" action='' class='js-modal-form' enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
{% load crispy_forms_tags %}
|
||||
|
||||
<div class='control-group'>
|
||||
<label class='control-label requiredField'>Part Category</label>
|
||||
<div class='controls'>
|
||||
<select class='select' name='part_category'>
|
||||
<option value=''>---------</option>
|
||||
{% for cat in categories %}
|
||||
<option value='{{ cat.id }}' {% if category and category.id == cat.id %}selected='selected'{% endif %}>{{ cat.pathstring }} - {{ cat.description }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
{% if category %}
|
||||
<p class='help-block'>Select Part Category</p>
|
||||
{% else %}
|
||||
<p class='help-inline'>Select Part Category</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label class='control-label'>Parts</label>
|
||||
<p class='help-block'>Set category for the following parts</p>
|
||||
|
||||
@ -54,5 +36,7 @@
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
{% crispy form %}
|
||||
|
||||
</form>
|
||||
{% endblock %}
|
@ -138,11 +138,12 @@ class PartAttachmentDelete(AjaxDeleteView):
|
||||
}
|
||||
|
||||
|
||||
class PartSetCategory(AjaxView):
|
||||
class PartSetCategory(AjaxUpdateView):
|
||||
""" View for settings the part category for multiple parts at once """
|
||||
|
||||
ajax_template_name = 'part/set_category.html'
|
||||
ajax_form_title = 'Set Part Category'
|
||||
form_class = part_forms.SetPartCategoryForm
|
||||
|
||||
category = None
|
||||
parts = []
|
||||
@ -157,7 +158,7 @@ class PartSetCategory(AjaxView):
|
||||
else:
|
||||
self.parts = []
|
||||
|
||||
return self.renderJsonResponse(request, context=self.get_context_data())
|
||||
return self.renderJsonResponse(request, form=self.get_form(), context=self.get_context_data())
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
""" Respond to a POST request to this view """
|
||||
@ -196,7 +197,7 @@ class PartSetCategory(AjaxView):
|
||||
for part in self.parts:
|
||||
part.set_category(self.category)
|
||||
|
||||
return self.renderJsonResponse(request, data=data, context=self.get_context_data())
|
||||
return self.renderJsonResponse(request, data=data, form=self.get_form(), context=self.get_context_data())
|
||||
|
||||
def get_context_data(self):
|
||||
""" Return context data for rendering in the form """
|
||||
|
Loading…
Reference in New Issue
Block a user