def remove_element(request): element_id = request.POST['id'] # sub_element = SchemaElement.objects.get(pk=element_id) element_list = SchemaElement.objects(children=element_id) if len(element_list) == 0: raise ValueError("No SchemaElement found") elif len(element_list) > 1: raise ValueError("More than one SchemaElement found") # Removing the element from the data structure schema_element = element_list[0] schema_element_to_pull = SchemaElement.objects.get(pk=element_id) schema_element.update(pull__children=schema_element_to_pull) schema_element.reload() update_branch_xpath(schema_element) # Deleting the branch from the database delete_branch_from_db(element_id) children_number = len(schema_element.children) # TODO Move it to parser function # FIXME Sequence elem it might not work if len(schema_element.children) == 0: elem_iter = SchemaElement() if schema_element.tag == 'element': elem_iter.tag = 'elem-iter' elif schema_element.tag == 'choice': elem_iter.tag = 'choice-iter' elif schema_element.tag == 'sequence': elem_iter.tag = 'sequence-iter' elem_iter.save() schema_element.update(add_to_set__children=[elem_iter]) schema_element.reload() response = { 'code': 0, 'html': "" } if children_number > schema_element.options['min']: return HttpResponse(json.dumps(response), status=HTTP_200_OK) else: # len(schema_element.children) == schema_element.options['min'] if schema_element.options['min'] != 0: response['code'] = 1 else: # schema_element.options['min'] == 0 renderer = ListRenderer(schema_element, request) html_form = renderer.render(True) response['code'] = 2 response['html'] = html_form return HttpResponse(json.dumps(response))
def remove_element(request): element_id = request.POST['id'] # sub_element = SchemaElement.objects.get(pk=element_id) element_list = SchemaElement.objects(children=element_id) if len(element_list) == 0: raise ValueError("No SchemaElement found") elif len(element_list) > 1: raise ValueError("More than one SchemaElement found") # Removing the element from the data structure schema_element = element_list[0] schema_element.update(pull__children=element_id) schema_element.reload() update_branch_xpath(schema_element) # Deleting the branch from the database delete_branch_from_db(element_id) children_number = len(schema_element.children) # TODO Move it to parser function # FIXME Sequence elem it might not work if len(schema_element.children) == 0: elem_iter = SchemaElement() if schema_element.tag == 'element': elem_iter.tag = 'elem-iter' elif schema_element.tag == 'choice': elem_iter.tag = 'choice-iter' elif schema_element.tag == 'sequence': elem_iter.tag = 'sequence-iter' elem_iter.save() schema_element.update(add_to_set__children=[elem_iter]) schema_element.reload() response = { 'code': 0, 'html': "" } if children_number > schema_element.options['min']: return HttpResponse(json.dumps(response), status=HTTP_200_OK) else: # len(schema_element.children) == schema_element.options['min'] if schema_element.options['min'] != 0: response['code'] = 1 else: # schema_element.options['min'] == 0 renderer = ListRenderer(schema_element, request) html_form = renderer.render(True) response['code'] = 2 response['html'] = html_form return HttpResponse(json.dumps(response))
client = MongoClient(MONGODB_URI) db = client[DB_NAME] xmldata = db['xmldata'] for cursor in xmldata.find({ "content.amProjectDB.@xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance" }): projectIDs.add(cursor["content"]["amProjectDB"]["amProject"]["projectID"]) product_element = SchemaElement() product_element.tag = u'restriction' product_element.value = u"blank" product_element.options = {u'base': u'xs:string'} product_element.children = [] product_element.save() for ProjectID in projectIDs: xsd_element = SchemaElement() xsd_element.tag = u'enumeration' xsd_element.value = str(ProjectID).decode('UTF-8') xsd_element.options = {} xsd_element.children = [] xsd_element.save() product_element.children.append(xsd_element) product_element.save() a = product_element product_element = SchemaElement() product_element.tag = u'simple_type' product_element.value = None product_element.options = {