示例#1
0
def resolve_dependencies(request):
    print 'BEGIN def resolveDependencies(request)'
    dependencies = request.POST.getlist('dependencies[]')
     
    objectContent = None
    
    response_dict = {}
    if ('uploadObjectName' in request.session and request.session['uploadObjectName'] is not None and
        'uploadObjectFilename' in request.session and request.session['uploadObjectFilename'] is not None and
        'uploadObjectContent' in request.session and request.session['uploadObjectContent'] is not None and
        'uploadObjectType' in request.session and request.session['uploadObjectType'] is not None):    
        objectContent = request.session['uploadObjectContent']
#         contentSession = 'uploadObjectContent'
        validSession = 'uploadObjectValid'
        flatSession = 'uploadObjectFlat'
        apiSession = 'uploadObjectAPIurl'
        saveBtn = "<span class='btn' onclick='saveObject()'>Save</span>"
    elif ('uploadVersionFilename' in request.session and request.session['uploadVersionFilename'] is not None and
        'uploadVersionContent' in request.session and request.session['uploadVersionContent'] is not None):
        objectContent = request.session['uploadVersionContent']
#         contentSession = 'uploadVersionContent'
        validSession = 'uploadVersionValid'
        flatSession = 'uploadVersionFlat'
        apiSession = 'uploadVersionAPIurl'
        saveBtn = "<span class='btn' onclick='saveVersion()'>Save</span>"
    else:
        response_dict= {'errors': "Please upload a file first."}
        return HttpResponse(json.dumps(response_dict), content_type='application/javascript')
         
    xmlTree = etree.parse(BytesIO(objectContent.encode('utf-8')))        
    # get the imports
#     imports = xmlTree.findall("{http://www.w3.org/2001/XMLSchema}import")
     
    # get the includes
    includes = xmlTree.findall("{http://www.w3.org/2001/XMLSchema}include")
     
    idxInclude = 0        
    # replace includes/imports by API calls
    for dependency in dependencies:
        includes[idxInclude].attrib['schemaLocation'] = getSchemaLocation(request, str(dependency))
        idxInclude += 1            
     
#         flattener = XSDFlattenerURL(etree.tostring(xmlTree),'admin','admin')
    flattener = XSDFlattenerMDCS(etree.tostring(xmlTree))
    flatStr = flattener.get_flat()
    flatTree = etree.fromstring(flatStr)
    
    try:
        # is it a valid XML schema ?
        xmlSchema = etree.XMLSchema(flatTree)
#         request.session[contentSession] = etree.tostring(xmlTree)
        request.session[validSession] = True
        
        request.session[flatSession] = flatStr
        request.session[apiSession] = etree.tostring(xmlTree)
        request.session["uploadDependencies"] = dependencies
        message = "The uploaded template is valid. You can now save it." + saveBtn
        response_dict = {'message': message}
    except Exception, e:
        response_dict = {'errorDependencies': e.message.replace("'", "")}
        return HttpResponse(json.dumps(response_dict), content_type='application/javascript')      
示例#2
0
# 
################################################################################
def save_template(request):
    template_name = request.POST['templateName']    
    content=request.session['newXmlTemplateCompose']
    
    response_dict = {}
    # is it a valid XML document ?
    try:            
        xmlTree = etree.parse(BytesIO(content.encode('utf-8')))
    except Exception, e:
        response_dict['errors'] = e.message.replace("'","")
        return HttpResponse(json.dumps(response_dict), content_type='application/javascript')
    
    flattener = XSDFlattenerMDCS(etree.tostring(xmlTree))
    flatStr = flattener.get_flat()
    flatTree = etree.fromstring(flatStr)
    
    try:
        # is it a valid XML schema ?
        xmlSchema = etree.XMLSchema(flatTree)
    except Exception, e:
        response_dict['errors'] = e.message.replace("'","")
        return HttpResponse(json.dumps(response_dict), content_type='application/javascript')
    
    hash = XSDhash.get_hash(content) 
    dependencies = []
    for uri in request.session["includedTypesCompose"]:
        url = urlparse(uri)
        id = url.query.split("=")[1]
        dependencies.append(id)
示例#3
0
def resolve_dependencies(request):
    print 'BEGIN def resolveDependencies(request)'
    dependencies = request.POST.getlist('dependencies[]')

    objectContent = None

    response_dict = {}
    if ('uploadObjectName' in request.session
            and request.session['uploadObjectName'] is not None
            and 'uploadObjectFilename' in request.session
            and request.session['uploadObjectFilename'] is not None
            and 'uploadObjectContent' in request.session
            and request.session['uploadObjectContent'] is not None
            and 'uploadObjectType' in request.session
            and request.session['uploadObjectType'] is not None):
        objectContent = request.session['uploadObjectContent']
        #         contentSession = 'uploadObjectContent'
        validSession = 'uploadObjectValid'
        flatSession = 'uploadObjectFlat'
        apiSession = 'uploadObjectAPIurl'
        saveBtn = "<span class='btn' onclick='saveObject()'>Save</span>"
    elif ('uploadVersionFilename' in request.session
          and request.session['uploadVersionFilename'] is not None
          and 'uploadVersionContent' in request.session
          and request.session['uploadVersionContent'] is not None):
        objectContent = request.session['uploadVersionContent']
        #         contentSession = 'uploadVersionContent'
        validSession = 'uploadVersionValid'
        flatSession = 'uploadVersionFlat'
        apiSession = 'uploadVersionAPIurl'
        saveBtn = "<span class='btn' onclick='saveVersion()'>Save</span>"
    else:
        response_dict = {'errors': "Please upload a file first."}
        return HttpResponse(json.dumps(response_dict),
                            content_type='application/javascript')

    xmlTree = etree.parse(BytesIO(objectContent.encode('utf-8')))
    # get the imports
    #     imports = xmlTree.findall("{http://www.w3.org/2001/XMLSchema}import")

    # get the includes
    includes = xmlTree.findall("{http://www.w3.org/2001/XMLSchema}include")

    idxInclude = 0
    # replace includes/imports by API calls
    for dependency in dependencies:
        includes[idxInclude].attrib['schemaLocation'] = getSchemaLocation(
            request, str(dependency))
        idxInclude += 1

#         flattener = XSDFlattenerURL(etree.tostring(xmlTree),'admin','admin')
    flattener = XSDFlattenerMDCS(etree.tostring(xmlTree))
    flatStr = flattener.get_flat()
    flatTree = etree.fromstring(flatStr)

    try:
        # is it a valid XML schema ?
        xmlSchema = etree.XMLSchema(flatTree)
        #         request.session[contentSession] = etree.tostring(xmlTree)
        request.session[validSession] = True

        request.session[flatSession] = flatStr
        request.session[apiSession] = etree.tostring(xmlTree)
        request.session["uploadDependencies"] = dependencies
        message = "The uploaded template is valid. You can now save it." + saveBtn
        response_dict = {'message': message}
    except Exception, e:
        response_dict = {'errorDependencies': e.message.replace("'", "")}
        return HttpResponse(json.dumps(response_dict),
                            content_type='application/javascript')
示例#4
0
################################################################################
def save_template(request):
    template_name = request.POST['templateName']
    content = request.session['newXmlTemplateCompose']

    response_dict = {}
    # is it a valid XML document ?
    try:
        xmlTree = etree.parse(BytesIO(content.encode('utf-8')))
    except Exception, e:
        response_dict['errors'] = e.message.replace("'", "")
        return HttpResponse(json.dumps(response_dict),
                            content_type='application/javascript')

    flattener = XSDFlattenerMDCS(etree.tostring(xmlTree))
    flatStr = flattener.get_flat()
    flatTree = etree.fromstring(flatStr)

    try:
        # is it a valid XML schema ?
        xmlSchema = etree.XMLSchema(flatTree)
    except Exception, e:
        response_dict['errors'] = e.message.replace("'", "")
        return HttpResponse(json.dumps(response_dict),
                            content_type='application/javascript')

    hash = XSDhash.get_hash(content)
    dependencies = []
    for uri in request.session["includedTypesCompose"]:
        url = urlparse(uri)
        id = url.query.split("=")[1]