def handle(self, *args, **options): filename = options['filename'] try: tos_importer = TOSImporter(filename) except Exception as e: print("Cannot open file '%s': %s" % (filename, e)) return with transaction.atomic(): tos_importer.import_attributes()
def handle(self, *args, **options): filename = options['filename'] try: tos_importer = TOSImporter(filename) except Exception as e: print("Cannot open file '%s': %s" % (filename, e)) return with transaction.atomic(): tos_importer.import_template(options['sheet_name'], options['template_name'])
def test_tos_importer_with_classification_and_function(function, tos_importer_excel_file_path): function.classification.code = "00 00 01 02" function.classification.save(update_fields=["code"]) tos_importer = TOSImporter() tos_importer.open(tos_importer_excel_file_path) tos_importer.import_data() tos_importer.import_attributes()
def tos_import_view(request, context={}): if not (request.user.is_authenticated and request.user.is_superuser): raise PermissionDenied if request.method == 'POST': importer = TOSImporter() logger = logging.getLogger('tos_import_capture_logger') logger.setLevel(logging.DEBUG) handler = CaptureLogRecordsHandler() handler.setLevel(logging.DEBUG) logger.addHandler(handler) importer.logger = logger filename = '' try: data = request.FILES['tosfile'].read() filename = request.FILES['tosfile'].name importer.open(BytesIO(data)) importer.import_data() messages.add_message( request, messages.INFO, _('File "%s" was imported successfully!') % filename) except Exception as e: messages.add_message(request, messages.ERROR, _('Error importing file "%s"') % filename) logger.error(e) context['logs'] = handler.log_records return render(request, 'admin/metarecord/function/import_tos.html', context)
def tos_import_view(request): if not (request.user.is_authenticated and request.user.is_superuser): raise PermissionDenied context = {} if request.method == 'POST': importer = TOSImporter() logger = logging.getLogger('tos_import_capture_logger') logger.setLevel(logging.DEBUG) handler = CaptureLogRecordsHandler() handler.setLevel(logging.DEBUG) logger.addHandler(handler) importer.logger = logger filename = '' try: data = request.FILES['tosfile'].read() filename = request.FILES['tosfile'].name importer.open(BytesIO(data)) importer.import_data() messages.add_message(request, messages.INFO, _('File "%s" was imported successfully!') % filename) except Exception as e: messages.add_message(request, messages.ERROR, _('Error importing file "%s"') % filename) logger.error(e) context['logs'] = handler.log_records return render(request, 'admin/metarecord/function/import_tos.html', context)
def handle(self, *args, **options): filename = options['filename'] try: tos_importer = TOSImporter(options) tos_importer.open(filename) except Exception as e: raise CommandError("Cannot open file '%s': %s" % (filename, e)) try: with transaction.atomic(): tos_importer.import_data() except TOSImporterException as e: raise CommandError(e)
def test_tos_importer_with_no_classification(tos_importer_excel_file_path): tos_importer = TOSImporter() tos_importer.open(tos_importer_excel_file_path) with pytest.raises(TOSImporterException) as excinfo: tos_importer.import_data() assert str(excinfo.value) == "Classification 00 00 01 02 does not exist"