def _save_type_version(request, assets, context, type_version_manager): """Save a type version. Args: request: assets: context: type_version_manager: Returns: """ # get the file from the form xsd_file = request.FILES['xsd_file'] # read the content of the file xsd_data = read_xsd_file(xsd_file) try: type_object = Type(filename=xsd_file.name, content=xsd_data) type_version_manager_api.insert(type_version_manager, type_object) return HttpResponseRedirect( reverse( "admin:core_composer_app_manage_type_versions", kwargs={'version_manager_id': str(type_version_manager.id)})) except exceptions.XSDError, xsd_error: return _handle_xsd_errors(request, assets, context, xsd_error, xsd_data, xsd_file.name)
def _save_type_version(request, assets, context, type_version_manager): """Save a type version. Args: request: assets: context: type_version_manager: Returns: """ # get the file from the form xsd_file = request.FILES["xsd_file"] # read the content of the file xsd_data = read_xsd_file(xsd_file) try: type_object = Type(filename=xsd_file.name, content=xsd_data) type_version_manager_api.insert(type_version_manager, type_object, request=request) return HttpResponseRedirect( reverse( "admin:core_composer_app_manage_type_versions", kwargs={"version_manager_id": str(type_version_manager.id)}, )) except exceptions.XSDError as xsd_error: return _handle_xsd_errors(request, assets, context, xsd_error, xsd_data, xsd_file.name) except Exception as e: context["errors"] = html_escape(str(e)) return _upload_type_response(request, assets, context)
def _save_type(request, assets, context): """Save a type. Args: request: assets: context: Returns: """ # get the schema name name = request.POST['name'] # get the file from the form xsd_file = request.FILES['xsd_file'] # read the content of the file xsd_data = read_xsd_file(xsd_file) # get the buckets buckets = request.POST.getlist('buckets') try: type_object = Type(filename=xsd_file.name, content=xsd_data) type_version_manager = TypeVersionManager(title=name) type_version_manager_api.insert(type_version_manager, type_object, buckets) return HttpResponseRedirect(reverse("admin:core_composer_app_types")) except exceptions.XSDError, xsd_error: return _handle_xsd_errors(request, assets, context, xsd_error, xsd_data, xsd_file.name)
def _save_template(request, assets, context): """Save a template. Args: request: assets: context: Returns: """ # get the schema name name = request.POST['name'] # get the file from the form xsd_file = request.FILES['upload_file'] # read the content of the file xsd_data = read_xsd_file(xsd_file) try: template = Template(filename=xsd_file.name, content=xsd_data) template_version_manager = TemplateVersionManager(title=name) template_version_manager_api.insert(template_version_manager, template) return HttpResponseRedirect(reverse("admin:core_main_app_templates")) except exceptions.XSDError, xsd_error: return handle_xsd_errors(request, assets, context, xsd_error, xsd_data, xsd_file.name)
def _save_type(request, assets, context): """Save a type. Args: request: assets: context: Returns: """ try: # get the schema name name = request.POST["name"] # get the file from the form xsd_file = request.FILES["xsd_file"] # read the content of the file xsd_data = read_xsd_file(xsd_file) # get the buckets buckets = request.POST.getlist("buckets") type_object = Type(filename=xsd_file.name, content=xsd_data) type_version_manager = TypeVersionManager(title=name) type_version_manager_api.insert(type_version_manager, type_object, request=request, list_bucket_ids=buckets) return HttpResponseRedirect(reverse("admin:core_composer_app_types")) except exceptions.XSDError as xsd_error: return _handle_xsd_errors(request, assets, context, xsd_error, xsd_data, xsd_file.name) except Exception as e: context["errors"] = html_escape(str(e)) return _upload_type_response(request, assets, context)
def _save_xslt(self, request): """Saves an XSLT. Args: request: Request. """ try: # get the XSLT name name = request.POST['name'] # get the file from the form xsd_file = request.FILES['upload_file'] # read the content of the file xsd_data = read_xsd_file(xsd_file) xslt = XslTransformation(name=name, filename=xsd_file.name, content=xsd_data) xslt_transformation_api.upsert(xslt) return HttpResponseRedirect(reverse("admin:core_main_app_xslt")) except exceptions.NotUniqueError: self.context.update( {'errors': html_escape("This name already exists.")}) return admin_render(request, 'core_main_app/admin/xslt/upload.html', context=self.context) except Exception, e: self.context.update({'errors': html_escape(e.message)}) return admin_render(request, 'core_main_app/admin/xslt/upload.html', context=self.context)
def _save_template_version(request, assets, context, template_version_manager): """Save a template version. Args: request: assets: context: template_version_manager: Returns: """ # get the file from the form xsd_file = request.FILES['xsd_file'] # read the content of the file xsd_data = read_xsd_file(xsd_file) try: template = Template(filename=xsd_file.name, content=xsd_data) template_version_manager_api.insert(template_version_manager, template) return HttpResponseRedirect( reverse("admin:core_main_app_manage_template_versions", kwargs={ 'version_manager_id': str(template_version_manager.id) })) except exceptions.XSDError as xsd_error: return handle_xsd_errors(request, assets, context, xsd_error, xsd_data, xsd_file.name) except Exception as e: context['errors'] = html_escape(str(e)) return _upload_template_response(request, assets, context)
def _save_template(request, assets, context): """Save a template. Args: request: assets: context: Returns: """ # get the schema name name = request.POST['name'] # get the file from the form xsd_file = request.FILES['upload_file'] # read the content of the file xsd_data = read_xsd_file(xsd_file) try: template = Template(filename=xsd_file.name, content=xsd_data) template_version_manager = TemplateVersionManager(title=name) template_version_manager_api.insert(template_version_manager, template) return HttpResponseRedirect(reverse("admin:core_main_app_templates")) except exceptions.XSDError as xsd_error: return handle_xsd_errors(request, assets, context, xsd_error, xsd_data, xsd_file.name) except exceptions.NotUniqueError: context['errors'] = html_escape( "A template with the same name already exists. Please choose another name." ) return _upload_template_response(request, assets, context) except Exception as e: context['errors'] = html_escape(str(e)) return _upload_template_response(request, assets, context)
def _start_curate_post(request): """Start curate POST request. Args: request: Returns: """ template_id = str(request.POST["hidden_value"]) selected_option = request.POST["curate_form"] user_id = str(request.user.id) if selected_option == "new" or selected_option == "upload": if selected_option == "new": new_form = users_forms.NewForm(request.POST) if new_form.is_valid(): name = new_form.data["document_name"] curate_data_structure = CurateDataStructure( user=user_id, template=template_id, name=name) else: raise CurateAjaxError( "An error occurred during the validation " + get_form_label()) else: upload_form = users_forms.UploadForm(request.POST, request.FILES) if upload_form.is_valid(): xml_file = request.FILES["file"] xml_data = read_xsd_file(xml_file) well_formed = is_well_formed_xml(xml_data) name = xml_file.name if not well_formed: raise CurateAjaxError( "An error occurred during the file upload: the file is " "not well formed XML") else: curate_data_structure = CurateDataStructure( user=user_id, template=template_id, name=name, form_string=xml_data, ) else: raise CurateAjaxError( "An error occurred during the validation " + get_form_label()) curate_data_structure_api.upsert(curate_data_structure, request.user) else: open_form = users_forms.OpenForm(request.POST) curate_data_structure = curate_data_structure_api.get_by_id( open_form.data["forms"], request.user) url = reverse("core_curate_enter_data", args=(curate_data_structure.id, )) return HttpResponse(url)
def _save_template_version(request, assets, context, template_version_manager): """Save a template version. Args: request: assets: context: template_version_manager: Returns: """ try: # get the file from the form xsd_file = request.FILES["xsd_file"] # read the content of the file xsd_data = read_xsd_file(xsd_file) template = Template(filename=xsd_file.name, content=xsd_data) template_version_manager_api.insert(template_version_manager, template, request=request) # create the fragment url with all the version of the template (minus the new template) version_manager_string = "" for version in template_version_manager.versions: if version != str(template.id): current_version_string = (version if version_manager_string == "" else f",{version}") version_manager_string += current_version_string # add the fragment data to the url fragment = f"#from={version_manager_string}&to={template.id}" return HttpResponseRedirect( reverse("admin:core_main_app_data_migration") + fragment) except exceptions.XSDError as xsd_error: return handle_xsd_errors(request, assets, context, xsd_error, xsd_data, xsd_file.name) except Exception as e: context["errors"] = html_escape(str(e)) return _upload_template_response(request, assets, context)
def _save_query_ontology(request, context): """Save a query ontology. Args: request: context: Returns: """ # get the schema name name = request.POST['name'] # get the file from the form owl_file = request.FILES['upload_file'] # check the extension file if not owl_file.name.endswith('.owl'): raise Exception('The extension file must be .owl') # retrieve the template id template_id = request.POST['templates_manager'] # read the content of the file # FIXME: this method should be renamed to read_file, can't be done in this commit owl_data = read_xsd_file(owl_file) owl = QueryOntology(title=name, content=owl_data, template=template_id) query_ontology_api.upsert(owl)