From 1d95d9ebc225d7c8774082e15bfd029781ad37ce Mon Sep 17 00:00:00 2001 From: keroth Date: Sun, 10 May 2015 03:00:33 +0200 Subject: fixed bug in views.py --- inventory/views.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/inventory/views.py b/inventory/views.py index 45313e2..541e300 100644 --- a/inventory/views.py +++ b/inventory/views.py @@ -90,27 +90,31 @@ def upload(request): if form.is_valid() and request.user.is_authenticated: codefile = request.FILES['file'] data = codefile.read().splitlines() - + index = 0 + error = 0 if request.POST['type'] == '1': parent = '' for code in data: - if code != 'NEWPARENT': - if parent == '': - p = get_object_or_404(models.Barcode, pk=code.upper()) - parent = code + try: + b = Barcode.objects.get(code=code.upper()) + if code != 'NEWPARENT': + if parent == '': + p = Barcode.objects.get(code=code.upper()) + parent = code + else: + i = Barcode.objects.get(code=code.upper()) + i.item.parent = p.item + i.item.save() else: - i = get_object_or_404(models.Barcode, pk=code.upper()) - i.item.parent = p.item - i.item.save() - else: - parent = '' + parent = '' + except ObjectDoesNotExist: + error += 1 + data[index] = code + ' existiert nicht' + index += 1 elif request.POST['type'] == '2': - index = 0 - error = 0 business_area = models.BusinessArea.objects.get(name='ideell') category = models.Category.objects.get(name='Inventar') parent = models.Barcode.objects.get(code='H0000') - tag = models.Tag.objects.get(name='Regale & Storage') for code in data: if code[0] == 'H' and len(code) == 5: @@ -119,8 +123,9 @@ def upload(request): error += 1 data[index] = code + ' existiert bereits' except ObjectDoesNotExist: + name = 'Regalborte' + code description = 'Borte im Hochregal \nReihe: ' + code[1] + '\nRegal: ' + code[2] - i = models.Item(name='Regalborte', description=description, business_area=business_area, category=category, parent=parent.item) + i = models.Item(name=name, description=description, business_area=business_area, category=category, parent=parent.item) i.save() barcode = Barcode(code=code, item=i) barcode.save() -- cgit v1.2.3