2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 13:05:42 +00:00

Client side QR Codes (#4357)

* Add JS for qrcodejs

Ref: https://davidshimjs.github.io/qrcodejs/

* Simple function for rendering a QR code

* Refactor QR code view for Part

* Replace QR code view for SupplierPart

* Refactor QR codes for stock item and stock location models

* Remove base QRCodeView entirely
This commit is contained in:
Oliver
2023-02-17 13:33:36 +11:00
committed by GitHub
parent 0f445ea6e4
commit cde2050236
15 changed files with 56 additions and 161 deletions

View File

@ -2118,9 +2118,6 @@ part_api_urls = [
# 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'),

View File

@ -447,11 +447,9 @@
{% if barcodes %}
$("#show-qr-code").click(function() {
launchModalForm(
"{% url 'api-part-qr' part.id %}",
{
no_post: true,
}
showQRDialog(
'{% trans "Part QR Code" %}',
'{"part": {{ part.pk }}}',
);
});

View File

@ -113,28 +113,3 @@ class PartDetailTest(PartViewTestCase):
response = self.client.get(reverse('api-bom-download', args=(1,)), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.assertEqual(response.status_code, 200)
self.assertIn('streaming_content', dir(response))
class PartQRTest(PartViewTestCase):
"""Tests for the Part QR Code AJAX view."""
def test_html_redirect(self):
"""A HTML request for a QR code should be redirected (use an AJAX request instead)"""
response = self.client.get(reverse('api-part-qr', args=(1,)))
self.assertEqual(response.status_code, 302)
def test_valid_part(self):
"""Test QR code response for a Part"""
response = self.client.get(reverse('api-part-qr', args=(1,)), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.assertEqual(response.status_code, 200)
data = str(response.content)
self.assertIn('Part QR Code', data)
self.assertIn('<img src=', data)
def test_invalid_part(self):
"""Test response for an invalid Part ID value"""
response = self.client.get(reverse('api-part-qr', args=(9999,)), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.assertEqual(response.status_code, 200)

View File

@ -16,8 +16,7 @@ from common.models import InvenTreeSetting
from common.views import FileManagementAjaxView, FileManagementFormView
from company.models import SupplierPart
from InvenTree.helpers import str2bool, str2int
from InvenTree.views import (AjaxUpdateView, AjaxView, InvenTreeRoleMixin,
QRCodeView)
from InvenTree.views import AjaxUpdateView, AjaxView, InvenTreeRoleMixin
from plugin.views import InvenTreePluginViewMixin
from stock.models import StockItem, StockLocation
@ -372,22 +371,6 @@ class PartDetailFromIPN(PartDetail):
return super(PartDetailFromIPN, self).get(request, *args, **kwargs)
class PartQRCode(QRCodeView):
"""View for displaying a QR code for a Part object."""
ajax_form_title = _("Part QR Code")
role_required = 'part.view'
def get_qr_data(self):
"""Generate QR code data for the Part."""
try:
part = Part.objects.get(id=self.pk)
return part.format_barcode()
except Part.DoesNotExist:
return None
class PartImageSelect(AjaxUpdateView):
"""View for selecting Part image from existing images."""