Made all categories accessible for parameter templates configuration

This commit is contained in:
eeintech 2020-11-03 14:45:53 -05:00
parent 6b702ef676
commit 72b5a105f8
3 changed files with 18 additions and 17 deletions

View File

@ -201,28 +201,25 @@ class ColorThemeSelectForm(forms.ModelForm):
class SettingCategorySelectForm(forms.ModelForm):
""" Form for setting category settings """
name = forms.ChoiceField(required=False)
category = forms.ModelChoiceField(queryset=PartCategory.objects.all())
class Meta:
model = PartCategory
fields = [
'name'
'category'
]
def __init__(self, *args, **kwargs):
super(SettingCategorySelectForm, self).__init__(*args, **kwargs)
# Populate category choices
self.fields['name'].choices = [('', '-' * 10)] + PartCategory.get_parent_categories()
self.helper = FormHelper()
# Form rendering
self.helper.form_show_labels = False
self.helper.layout = Layout(
Div(
Div(Field('name'),
Div(Field('category'),
css_class='col-sm-6',
style='width: auto;'),
style='width: 30%;'),
Div(StrictButton(_('Select Category'), css_class='btn btn-primary', type='submit'),
css_class='col-sm-6',
style='width: auto; padding-left: 0;'),

View File

@ -765,7 +765,7 @@ class SettingCategorySelectView(FormView):
category = self.request.GET.get('category', None)
if category:
initial['name'] = category
initial['category'] = category
return initial
@ -778,11 +778,9 @@ class SettingCategorySelectView(FormView):
form = self.get_form()
if form.is_valid():
category = form.cleaned_data['name']
context = self.get_context_data()
context['category'] = category
context['category'] = form.cleaned_data['category']
return super(SettingCategorySelectView, self).render_to_response(context)

View File

@ -14,7 +14,9 @@
<form action="{% url 'settings-category' %}" method="post">
{% csrf_token %}
{% load crispy_forms_tags %}
<div id="category-select">
{% crispy form %}
</div>
</form>
{% if category %}
@ -35,10 +37,14 @@
{% block js_ready %}
{{ block.super }}
{% if category %}
$(document).ready(function() {
attachSelect('#category-select');
});
{% if category %}
$("#param-table").inventreeTable({
url: "{% url 'api-part-category-parameters' category %}",
url: "{% url 'api-part-category-parameters' category.pk %}",
queryParams: {
ordering: 'name',
},
@ -74,7 +80,7 @@
$("#new-param").click(function() {
launchModalForm("{% url 'category-param-template-create' category %}", {
launchModalForm("{% url 'category-param-template-create' category.pk %}", {
success: function() {
$("#param-table").bootstrapTable('refresh');
},
@ -84,7 +90,7 @@
$("#param-table").on('click', '.template-edit', function() {
var button = $(this);
var url = "/part/category/{{ category }}/parameters/" + button.attr('pk') + "/edit/";
var url = "/part/category/{{ category.pk }}/parameters/" + button.attr('pk') + "/edit/";
launchModalForm(url, {
success: function() {
@ -96,7 +102,7 @@
$("#param-table").on('click', '.template-delete', function() {
var button = $(this);
var url = "/part/category/{{ category }}/parameters/" + button.attr('pk') + "/delete/";
var url = "/part/category/{{ category.pk }}/parameters/" + button.attr('pk') + "/delete/";
launchModalForm(url, {
success: function() {