From f6a878460d5d61b37c4094d360c22e2dbc1797f3 Mon Sep 17 00:00:00 2001 From: stefan Date: Sat, 25 Jan 2025 14:53:22 +0100 Subject: [PATCH] changed the prefix of stock uuid qr codes --- shimatta_kenkyusho/parts/models.py | 2 +- shimatta_kenkyusho/parts/qr_parser.py | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/shimatta_kenkyusho/parts/models.py b/shimatta_kenkyusho/parts/models.py index 2f19cf4..4355cdf 100644 --- a/shimatta_kenkyusho/parts/models.py +++ b/shimatta_kenkyusho/parts/models.py @@ -316,7 +316,7 @@ class Stock(models.Model): return True def get_qr_code(self): - qr_data = '[stock]'+str(self.id) + qr_data = '[stck_uuid]'+str(self.id) return qr_data def __str__(self): diff --git a/shimatta_kenkyusho/parts/qr_parser.py b/shimatta_kenkyusho/parts/qr_parser.py index 4e5020d..9e3854a 100644 --- a/shimatta_kenkyusho/parts/qr_parser.py +++ b/shimatta_kenkyusho/parts/qr_parser.py @@ -2,7 +2,7 @@ from django.core.exceptions import ValidationError, ObjectDoesNotExist from django.urls import reverse as url_reverse import re -from .models import Storage, Component +from .models import Storage, Component, Stock class QrCode: prefix = '' @@ -19,6 +19,7 @@ class QrCodeValidator: qr_patterns = { 'stor_uuid': QrCode('stor_uuid', 'parts-stocks-detail', Storage), 'comp_uuid': QrCode('comp_uuid', 'parts-components-detail', Component), + 'stck_uuid': QrCode('stck_uuid', 'parts-stock-detail', Stock), } def __init__(self): @@ -32,16 +33,13 @@ class QrCodeValidator: qr_type = matches.group('prefix') qr_uuid = matches.group('uuid') - url_name = self.qr_patterns[qr_type].detail_view - model = None try: + url_name = self.qr_patterns[qr_type].detail_view model = self.qr_patterns[qr_type].model - except: - model = None - if model is None: - raise ValidationError('QR Pattern not registered') - return (model,qr_uuid, url_name) + except KeyError as ex: + raise ValidationError('QR Pattern not registered') from ex + return (model, qr_uuid, url_name) def get_redirect_url(self, data): model, uuid, url_name = self._get_model_from_qr(data)