mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-01 13:06:45 +00:00
[FR] Move URL endpoints to API namespace (#4163)
* Move endpoints [FR] Move download URL endpoints to API namespace Fixes #3927 * rename endpoint ref name and update js * update endpoint name and js * rename endpoint and fix js * add docstring
This commit is contained in:
parent
942086741e
commit
0e96654b6a
@ -36,6 +36,7 @@ from plugin.serializers import MetadataSerializer
|
|||||||
from stock.models import StockItem, StockLocation
|
from stock.models import StockItem, StockLocation
|
||||||
|
|
||||||
from . import serializers as part_serializers
|
from . import serializers as part_serializers
|
||||||
|
from . import views
|
||||||
from .models import (BomItem, BomItemSubstitute, Part, PartAttachment,
|
from .models import (BomItem, BomItemSubstitute, Part, PartAttachment,
|
||||||
PartCategory, PartCategoryParameterTemplate,
|
PartCategory, PartCategoryParameterTemplate,
|
||||||
PartInternalPriceBreak, PartParameter,
|
PartInternalPriceBreak, PartParameter,
|
||||||
@ -2196,6 +2197,9 @@ part_api_urls = [
|
|||||||
re_path(r'^(?P<pk>\d+)/?', PartThumbsUpdate.as_view(), name='api-part-thumbs-update'),
|
re_path(r'^(?P<pk>\d+)/?', PartThumbsUpdate.as_view(), name='api-part-thumbs-update'),
|
||||||
])),
|
])),
|
||||||
|
|
||||||
|
# BOM template
|
||||||
|
re_path(r'^bom_template/?', views.BomUploadTemplate.as_view(), name='api-bom-upload-template'),
|
||||||
|
|
||||||
re_path(r'^(?P<pk>\d+)/', include([
|
re_path(r'^(?P<pk>\d+)/', include([
|
||||||
|
|
||||||
# Endpoint for extra serial number information
|
# Endpoint for extra serial number information
|
||||||
@ -2218,6 +2222,15 @@ part_api_urls = [
|
|||||||
# Part pricing
|
# Part pricing
|
||||||
re_path(r'^pricing/', PartPricingDetail.as_view(), name='api-part-pricing'),
|
re_path(r'^pricing/', PartPricingDetail.as_view(), name='api-part-pricing'),
|
||||||
|
|
||||||
|
# BOM download
|
||||||
|
re_path(r'^bom-download/?', views.BomDownload.as_view(), name='api-bom-download'),
|
||||||
|
|
||||||
|
# QR code download
|
||||||
|
re_path(r'^qr_code/?', views.PartQRCode.as_view(), name='api-part-qr'),
|
||||||
|
|
||||||
|
# Old pricing endpoint
|
||||||
|
re_path(r'^pricing2/', views.PartPricing.as_view(), name='part-pricing'),
|
||||||
|
|
||||||
# Part detail endpoint
|
# Part detail endpoint
|
||||||
re_path(r'^.*$', PartDetail.as_view(), name='api-part-detail'),
|
re_path(r'^.*$', PartDetail.as_view(), name='api-part-detail'),
|
||||||
])),
|
])),
|
||||||
|
@ -441,7 +441,7 @@
|
|||||||
{% if barcodes %}
|
{% if barcodes %}
|
||||||
$("#show-qr-code").click(function() {
|
$("#show-qr-code").click(function() {
|
||||||
launchModalForm(
|
launchModalForm(
|
||||||
"{% url 'part-qr' part.id %}",
|
"{% url 'api-part-qr' part.id %}",
|
||||||
{
|
{
|
||||||
no_post: true,
|
no_post: true,
|
||||||
}
|
}
|
||||||
|
@ -23,11 +23,11 @@ class BomExportTest(InvenTreeTestCase):
|
|||||||
"""Perform test setup functions"""
|
"""Perform test setup functions"""
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
self.url = reverse('bom-download', kwargs={'pk': 100})
|
self.url = reverse('api-bom-download', kwargs={'pk': 100})
|
||||||
|
|
||||||
def test_bom_template(self):
|
def test_bom_template(self):
|
||||||
"""Test that the BOM template can be downloaded from the server."""
|
"""Test that the BOM template can be downloaded from the server."""
|
||||||
url = reverse('bom-upload-template')
|
url = reverse('api-bom-upload-template')
|
||||||
|
|
||||||
# Download an XLS template
|
# Download an XLS template
|
||||||
response = self.client.get(url, data={'format': 'xls'})
|
response = self.client.get(url, data={'format': 'xls'})
|
||||||
|
@ -110,7 +110,7 @@ class PartDetailTest(PartViewTestCase):
|
|||||||
|
|
||||||
def test_bom_download(self):
|
def test_bom_download(self):
|
||||||
"""Test downloading a BOM for a valid part."""
|
"""Test downloading a BOM for a valid part."""
|
||||||
response = self.client.get(reverse('bom-download', args=(1,)), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
response = self.client.get(reverse('api-bom-download', args=(1,)), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertIn('streaming_content', dir(response))
|
self.assertIn('streaming_content', dir(response))
|
||||||
|
|
||||||
@ -120,12 +120,12 @@ class PartQRTest(PartViewTestCase):
|
|||||||
|
|
||||||
def test_html_redirect(self):
|
def test_html_redirect(self):
|
||||||
"""A HTML request for a QR code should be redirected (use an AJAX request instead)"""
|
"""A HTML request for a QR code should be redirected (use an AJAX request instead)"""
|
||||||
response = self.client.get(reverse('part-qr', args=(1,)))
|
response = self.client.get(reverse('api-part-qr', args=(1,)))
|
||||||
self.assertEqual(response.status_code, 302)
|
self.assertEqual(response.status_code, 302)
|
||||||
|
|
||||||
def test_valid_part(self):
|
def test_valid_part(self):
|
||||||
"""Test QR code response for a Part"""
|
"""Test QR code response for a Part"""
|
||||||
response = self.client.get(reverse('part-qr', args=(1,)), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
response = self.client.get(reverse('api-part-qr', args=(1,)), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
data = str(response.content)
|
data = str(response.content)
|
||||||
@ -135,6 +135,6 @@ class PartQRTest(PartViewTestCase):
|
|||||||
|
|
||||||
def test_invalid_part(self):
|
def test_invalid_part(self):
|
||||||
"""Test response for an invalid Part ID value"""
|
"""Test response for an invalid Part ID value"""
|
||||||
response = self.client.get(reverse('part-qr', args=(9999,)), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
response = self.client.get(reverse('api-part-qr', args=(9999,)), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
@ -11,14 +11,8 @@ from django.urls import include, re_path
|
|||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
part_detail_urls = [
|
part_detail_urls = [
|
||||||
re_path(r'^bom-download/?', views.BomDownload.as_view(), name='bom-download'),
|
|
||||||
|
|
||||||
re_path(r'^pricing/', views.PartPricing.as_view(), name='part-pricing'),
|
|
||||||
|
|
||||||
re_path(r'^bom-upload/?', views.BomUpload.as_view(), name='upload-bom'),
|
re_path(r'^bom-upload/?', views.BomUpload.as_view(), name='upload-bom'),
|
||||||
|
|
||||||
re_path(r'^qr_code/?', views.PartQRCode.as_view(), name='part-qr'),
|
|
||||||
|
|
||||||
# Normal thumbnail with form
|
# Normal thumbnail with form
|
||||||
re_path(r'^thumb-select/?', views.PartImageSelect.as_view(), name='part-image-select'),
|
re_path(r'^thumb-select/?', views.PartImageSelect.as_view(), name='part-image-select'),
|
||||||
|
|
||||||
@ -40,9 +34,6 @@ part_urls = [
|
|||||||
re_path(r'^import/?', views.PartImportTemplate.as_view(), name='part-template-download'),
|
re_path(r'^import/?', views.PartImportTemplate.as_view(), name='part-template-download'),
|
||||||
re_path(r'^import-api/', views.PartImportAjax.as_view(), name='api-part-import'),
|
re_path(r'^import-api/', views.PartImportAjax.as_view(), name='api-part-import'),
|
||||||
|
|
||||||
# Download a BOM upload template
|
|
||||||
re_path(r'^bom_template/?', views.BomUploadTemplate.as_view(), name='bom-upload-template'),
|
|
||||||
|
|
||||||
# Individual part using pk
|
# Individual part using pk
|
||||||
re_path(r'^(?P<pk>\d+)/', include(part_detail_urls)),
|
re_path(r'^(?P<pk>\d+)/', include(part_detail_urls)),
|
||||||
|
|
||||||
|
@ -293,7 +293,7 @@ function downloadBomTemplate(options={}) {
|
|||||||
$(opts.modal).modal('hide');
|
$(opts.modal).modal('hide');
|
||||||
|
|
||||||
// Download the file
|
// Download the file
|
||||||
location.href = `{% url "bom-upload-template" %}?format=${format}`;
|
location.href = `{% url "api-bom-upload-template" %}?format=${format}`;
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -373,7 +373,7 @@ function exportBom(part_id, options={}) {
|
|||||||
'pricing_data',
|
'pricing_data',
|
||||||
];
|
];
|
||||||
|
|
||||||
var url = `/part/${part_id}/bom-download/?`;
|
var url = `/api/part/${part_id}/bom-download/?`;
|
||||||
|
|
||||||
field_names.forEach(function(fn) {
|
field_names.forEach(function(fn) {
|
||||||
var val = getFormFieldValue(fn, fields[fn], opts);
|
var val = getFormFieldValue(fn, fields[fn], opts);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user