mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-16 20:15:44 +00:00
Merge remote-tracking branch 'inventree/master'
This commit is contained in:
@ -338,9 +338,7 @@ class PartThumbs(generics.ListAPIView):
|
|||||||
- Images may be used for multiple parts!
|
- Images may be used for multiple parts!
|
||||||
"""
|
"""
|
||||||
|
|
||||||
queryset = self.get_queryset()
|
queryset = self.filter_queryset(self.get_queryset())
|
||||||
|
|
||||||
# TODO - We should return the thumbnails here, not the full image!
|
|
||||||
|
|
||||||
# Return the most popular parts first
|
# Return the most popular parts first
|
||||||
data = queryset.values(
|
data = queryset.values(
|
||||||
@ -349,6 +347,19 @@ class PartThumbs(generics.ListAPIView):
|
|||||||
|
|
||||||
return Response(data)
|
return Response(data)
|
||||||
|
|
||||||
|
filter_backends = [
|
||||||
|
filters.SearchFilter,
|
||||||
|
]
|
||||||
|
|
||||||
|
search_fields = [
|
||||||
|
'name',
|
||||||
|
'description',
|
||||||
|
'IPN',
|
||||||
|
'revision',
|
||||||
|
'keywords',
|
||||||
|
'category__name',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class PartThumbsUpdate(generics.RetrieveUpdateAPIView):
|
class PartThumbsUpdate(generics.RetrieveUpdateAPIView):
|
||||||
""" API endpoint for updating Part thumbnails"""
|
""" API endpoint for updating Part thumbnails"""
|
||||||
|
@ -240,32 +240,20 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
$("#cat-create").click(function() {
|
$("#cat-create").click(function() {
|
||||||
launchModalForm(
|
|
||||||
"{% url 'category-create' %}",
|
var fields = categoryFields();
|
||||||
{
|
|
||||||
follow: true,
|
|
||||||
data: {
|
|
||||||
{% if category %}
|
{% if category %}
|
||||||
category: {{ category.id }}
|
fields.parent.value = {{ category.pk }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
},
|
|
||||||
secondary: [
|
constructForm('{% url "api-part-category-list" %}', {
|
||||||
{
|
fields: fields,
|
||||||
field: 'default_location',
|
method: 'POST',
|
||||||
label: '{% trans "New Location" %}',
|
title: '{% trans "Create Part Category" %}',
|
||||||
title: '{% trans "Create new location" %}',
|
follow: true,
|
||||||
url: "{% url 'stock-location-create' %}",
|
});
|
||||||
},
|
});
|
||||||
{
|
|
||||||
field: 'parent',
|
|
||||||
label: '{% trans "New Category" %}',
|
|
||||||
title: '{% trans "Create new category" %}',
|
|
||||||
url: "{% url 'category-create' %}",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
);
|
|
||||||
})
|
|
||||||
|
|
||||||
$("#part-export").click(function() {
|
$("#part-export").click(function() {
|
||||||
|
|
||||||
@ -286,12 +274,6 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
},
|
},
|
||||||
secondary: [
|
secondary: [
|
||||||
{
|
|
||||||
field: 'category',
|
|
||||||
label: '{% trans "New Category" %}',
|
|
||||||
title: '{% trans "Create new Part Category" %}',
|
|
||||||
url: "{% url 'category-create' %}",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
field: 'default_location',
|
field: 'default_location',
|
||||||
label: '{% trans "New Location" %}',
|
label: '{% trans "New Location" %}',
|
||||||
@ -307,24 +289,7 @@
|
|||||||
{% if category %}
|
{% if category %}
|
||||||
$("#cat-edit").click(function () {
|
$("#cat-edit").click(function () {
|
||||||
|
|
||||||
constructForm(
|
editCategory({{ category.pk }});
|
||||||
'{% url "api-part-category-detail" category.pk %}',
|
|
||||||
{
|
|
||||||
fields: {
|
|
||||||
name: {},
|
|
||||||
description: {},
|
|
||||||
parent: {
|
|
||||||
help_text: '{% trans "Select parent category" %}',
|
|
||||||
},
|
|
||||||
default_location: {},
|
|
||||||
default_keywords: {
|
|
||||||
icon: 'fa-key',
|
|
||||||
}
|
|
||||||
},
|
|
||||||
title: '{% trans "Edit Part Category" %}',
|
|
||||||
reload: true
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
{% if category.parent %}
|
{% if category.parent %}
|
||||||
|
@ -415,13 +415,16 @@
|
|||||||
// Callback when the image-selection modal form is displayed
|
// Callback when the image-selection modal form is displayed
|
||||||
// Populate the form with image data (requested via AJAX)
|
// Populate the form with image data (requested via AJAX)
|
||||||
|
|
||||||
$("#modal-form").find("#image-select-table").bootstrapTable({
|
$("#modal-form").find("#image-select-table").inventreeTable({
|
||||||
pagination: true,
|
|
||||||
pageSize: 25,
|
|
||||||
url: "{% url 'api-part-thumbs' %}",
|
url: "{% url 'api-part-thumbs' %}",
|
||||||
showHeader: false,
|
showHeader: false,
|
||||||
|
showColumns: false,
|
||||||
clickToSelect: true,
|
clickToSelect: true,
|
||||||
|
sidePagination: 'server',
|
||||||
singleSelect: true,
|
singleSelect: true,
|
||||||
|
formatNoMatches: function() {
|
||||||
|
return '{% trans "No matching images found" %}';
|
||||||
|
},
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
checkbox: true,
|
checkbox: true,
|
||||||
@ -429,6 +432,7 @@
|
|||||||
{
|
{
|
||||||
field: 'image',
|
field: 'image',
|
||||||
title: 'Image',
|
title: 'Image',
|
||||||
|
searchable: true,
|
||||||
formatter: function(value, row, index, field) {
|
formatter: function(value, row, index, field) {
|
||||||
return "<img src='/media/" + value + "' class='grid-image'/>"
|
return "<img src='/media/" + value + "' class='grid-image'/>"
|
||||||
}
|
}
|
||||||
|
@ -243,19 +243,6 @@ class PartQRTest(PartViewTestCase):
|
|||||||
class CategoryTest(PartViewTestCase):
|
class CategoryTest(PartViewTestCase):
|
||||||
""" Tests for PartCategory related views """
|
""" Tests for PartCategory related views """
|
||||||
|
|
||||||
def test_create(self):
|
|
||||||
""" Test view for creating a new category """
|
|
||||||
response = self.client.get(reverse('category-create'), {'category': 1}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
|
||||||
def test_create_invalid_parent(self):
|
|
||||||
""" test creation of a new category with an invalid parent """
|
|
||||||
response = self.client.get(reverse('category-create'), {'category': 9999}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
|
||||||
|
|
||||||
# Form should still return OK
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
|
||||||
def test_set_category(self):
|
def test_set_category(self):
|
||||||
""" Test that the "SetCategory" view works """
|
""" Test that the "SetCategory" view works """
|
||||||
|
|
||||||
|
@ -65,9 +65,6 @@ category_parameter_urls = [
|
|||||||
|
|
||||||
category_urls = [
|
category_urls = [
|
||||||
|
|
||||||
# Create a new category
|
|
||||||
url(r'^new/', views.CategoryCreate.as_view(), name='category-create'),
|
|
||||||
|
|
||||||
# Top level subcategory display
|
# Top level subcategory display
|
||||||
url(r'^subcategory/', views.PartIndex.as_view(template_name='part/subcategory.html'), name='category-index-subcategory'),
|
url(r'^subcategory/', views.PartIndex.as_view(template_name='part/subcategory.html'), name='category-index-subcategory'),
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ from django.db.utils import IntegrityError
|
|||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from django.shortcuts import HttpResponseRedirect
|
from django.shortcuts import HttpResponseRedirect
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.urls import reverse, reverse_lazy
|
from django.urls import reverse
|
||||||
from django.views.generic import DetailView, ListView
|
from django.views.generic import DetailView, ListView
|
||||||
from django.forms.models import model_to_dict
|
from django.forms.models import model_to_dict
|
||||||
from django.forms import HiddenInput, CheckboxInput
|
from django.forms import HiddenInput, CheckboxInput
|
||||||
@ -1905,49 +1905,6 @@ class CategoryDelete(AjaxDeleteView):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class CategoryCreate(AjaxCreateView):
|
|
||||||
""" Create view to make a new PartCategory """
|
|
||||||
model = PartCategory
|
|
||||||
ajax_form_action = reverse_lazy('category-create')
|
|
||||||
ajax_form_title = _('Create new part category')
|
|
||||||
ajax_template_name = 'modal_form.html'
|
|
||||||
form_class = part_forms.EditCategoryForm
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
|
||||||
""" Add extra context data to template.
|
|
||||||
|
|
||||||
- If parent category provided, pass the category details to the template
|
|
||||||
"""
|
|
||||||
context = super(CategoryCreate, self).get_context_data(**kwargs).copy()
|
|
||||||
|
|
||||||
parent_id = self.request.GET.get('category', None)
|
|
||||||
|
|
||||||
if parent_id:
|
|
||||||
try:
|
|
||||||
context['category'] = PartCategory.objects.get(pk=parent_id)
|
|
||||||
except PartCategory.DoesNotExist:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return context
|
|
||||||
|
|
||||||
def get_initial(self):
|
|
||||||
""" Get initial data for new PartCategory
|
|
||||||
|
|
||||||
- If parent provided, pre-fill the parent category
|
|
||||||
"""
|
|
||||||
initials = super(CategoryCreate, self).get_initial().copy()
|
|
||||||
|
|
||||||
parent_id = self.request.GET.get('category', None)
|
|
||||||
|
|
||||||
if parent_id:
|
|
||||||
try:
|
|
||||||
initials['parent'] = PartCategory.objects.get(pk=parent_id)
|
|
||||||
except PartCategory.DoesNotExist:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return initials
|
|
||||||
|
|
||||||
|
|
||||||
class CategoryParameterTemplateCreate(AjaxCreateView):
|
class CategoryParameterTemplateCreate(AjaxCreateView):
|
||||||
""" View for creating a new PartCategoryParameterTemplate """
|
""" View for creating a new PartCategoryParameterTemplate """
|
||||||
|
|
||||||
|
@ -14,6 +14,37 @@ function yesNoLabel(value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function categoryFields() {
|
||||||
|
return {
|
||||||
|
parent: {
|
||||||
|
help_text: '{% trans "Parent part category" %}',
|
||||||
|
},
|
||||||
|
name: {},
|
||||||
|
description: {},
|
||||||
|
default_location: {},
|
||||||
|
default_keywords: {
|
||||||
|
icon: 'fa-key',
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Edit a PartCategory via the API
|
||||||
|
function editCategory(pk, options={}) {
|
||||||
|
|
||||||
|
var url = `/api/part/category/${pk}/`;
|
||||||
|
|
||||||
|
var fields = categoryFields();
|
||||||
|
|
||||||
|
constructForm(url, {
|
||||||
|
fields: fields,
|
||||||
|
title: '{% trans "Edit Part Category" %}',
|
||||||
|
reload: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function editPart(pk, options={}) {
|
function editPart(pk, options={}) {
|
||||||
|
|
||||||
var url = `/api/part/${pk}/`;
|
var url = `/api/part/${pk}/`;
|
||||||
|
@ -187,7 +187,7 @@ $.fn.inventreeTable = function(options) {
|
|||||||
if (!options.disablePagination) {
|
if (!options.disablePagination) {
|
||||||
options.pagination = true;
|
options.pagination = true;
|
||||||
options.paginationVAlign = options.paginationVAlign || 'both';
|
options.paginationVAlign = options.paginationVAlign || 'both';
|
||||||
options.pageSize = inventreeLoad(varName, 25);
|
options.pageSize = options.pageSize || inventreeLoad(varName, 25);
|
||||||
options.pageList = [25, 50, 100, 250, 'all'];
|
options.pageList = [25, 50, 100, 250, 'all'];
|
||||||
options.totalField = 'count';
|
options.totalField = 'count';
|
||||||
options.dataField = 'results';
|
options.dataField = 'results';
|
||||||
|
Reference in New Issue
Block a user