def test_import_model_small(self): model_path = get_resource_path('model/mysqlwb-small.mwb') data = mysqlwb.import_model(model_path, 'name', 'version') with open(get_resource_path('model/mysqlwb-small.json')) as fin: expected_data = json.load(fin) self.assertDictEqual(expected_data, data)
def model_upload_view(request): """ Administrator view to upload new document versions to the current documents """ if request.method == "GET": return render(request, 'viewer/model-upload.html') if request.method == "POST": tmpfile = request.FILES.get('files[]') path = tmpfile.file.name imported_data = import_model(path, basename(path)) save_imported_model(imported_data['model']) return redirect(reverse('home'))
def handle(self, *args, **options): path = str(options['model_path']) filename, file_extension = os.path.splitext(path) supported_extensions = ['.mwb'] if os.path.exists(path): if file_extension in supported_extensions: start = time.perf_counter() self.stdout.write(self.style.SUCCESS('Starting import of model at "%s"' % path)) model = import_model(path, options['name'], options['version']) status_thread = ConsoleAnimationThread() status_thread.start() save_imported_model(model['model']) status_thread.stop() message = 'Successfully imported model from "%s" in %d ms' % (path, (time.perf_counter() - start) * 1000) self.stdout.write(self.style.SUCCESS(message)) else: raise CommandError('Only files of type %s are supported' % ",".join(supported_extensions)) else: raise CommandError('File does not exist at path %s' % path)