def view_by_barcode(request, barcode): barcode = barcode try: validate_barcode(barcode) files = DataFile.objects.filter(barcode__iexact=barcode) return render(request, "robox/web/view.html", {'files': files, 'barcode': barcode}) except ValidationError: return render(request, "robox/web/view.html", {'invalid': True, 'barcode': barcode})
def create(self, request, *args, **kwargs): barcode = request.data.get('barcode') files = request.FILES try: validate_barcode(barcode) database_files = upload_files(barcode, [file for file in files.values()]) return Response({"results": [FileSerializer(database_file).data for database_file in database_files]}, status=client.CREATED) except ValidationError: return Response({'error': 'Invalid barcode', 'barcode': barcode}, status=client.UNPROCESSABLE_ENTITY)
def view_by_barcode(request, barcode): barcode = barcode try: validate_barcode(barcode) files = DataFile.objects.filter(barcode__iexact=barcode) return render(request, "robox/web/view.html", { 'files': files, 'barcode': barcode }) except ValidationError: return render(request, "robox/web/view.html", { 'invalid': True, 'barcode': barcode })
def validate(self, value): validate_barcode(value)