コード例 #1
0
ファイル: views.py プロジェクト: pombredanne/deptx
def create(request):
    if request.method == 'POST':
        if 'convert' in request.POST or 'randomize' in request.POST:
            graphml_str = request.POST["graphml"]
            filename = request.POST["filename"]
            provn_str, output = convert_graphml_string(graphml_str)
            output_list = output.splitlines()
            output_list.sort()
 
            valid, validation_url = validate(provn_str)
            if valid:
                json_str = provn_str.get_provjson()
            else:
                json_str={}
                
            if 'randomize' in request.POST:
                json_str = json.dumps(get_random_graph(json.loads(json_str)))
            
            return render_to_response('provmanager/create.html', {"output_list":output_list, "filename":filename, "graphml_str": graphml_str, "json_str": json_str, "valid":valid, "validation_url":validation_url}, context_instance=RequestContext(request))

        elif 'save' in request.POST:
            graphml_str = request.POST["graphml"]
            provn_str, output = convert_graphml_string(graphml_str)
            valid, validation_url = validate(provn_str)
            if valid:
                name = request.POST["filename"]
                if name=="":
                    name = "PLEASE ENTER A NAME"
                
                inconsistencies_list, clean_graph = get_inconsistencies(json.loads(provn_str.get_provjson()))

                if inconsistencies_list:
                    attribute1 = json.dumps(inconsistencies_list[0])
                    attribute2 = json.dumps(inconsistencies_list[1])
                    type = Provenance.TYPE_CRON
                else:
                    attribute1 = None
                    attribute2 = None
                    #TODO: is there a better way to check the type?
                    #if there are no inconsistencies, then we assume it is a MOP_TEMPLATE provenance document
                    type = Provenance.TYPE_MOP_TEMPLATE
  
                bundle = ProvBundle.from_provjson(json.dumps(clean_graph))
                
                store_id = API.submit_document(bundle, name, public=False)

                provenance = Provenance(name=name, store_id=store_id, attribute1=attribute1, attribute2=attribute2, type=type)
                provenance.save()
                return HttpResponseRedirect(reverse('provmanager_index'))
            
            
    return render_to_response('provmanager/create.html', context_instance=RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: bachour/deptx
def convert(request, id):
    provenance = Provenance.objects.get(id=id)
    convert_graphml_string(provenance.graphml)
コード例 #3
0
ファイル: views.py プロジェクト: bachour/deptx
def create(request):
    if request.method == 'POST':
        if 'convertMop' in request.POST or 'convertCron' in request.POST or 'randomize' in request.POST:
            if 'convertCron' in request.POST:
                isCron = True
                isMop = False
            else:
                isCron = False
                isMop = True
            #graphml_str = request.POST["graphml"]
            filename, graphml_str = getStuff(request)
            
            
            provn_str, output = convert_graphml_string(graphml_str)
            output_list = output.splitlines()
            output_list.sort()

            valid = True
            validation_url = "bla"
            #valid, validation_url = validate(provn_str)
            if valid:
                json_str = provn_str.get_provjson()
            else:
                json_str={}
            
            #print json_str
                
            inconsistencies_list = None
            spoilers = False
            if 'randomize' in request.POST:
                print request.POST
                random_graph = get_random_graph(json.loads(json_str))
                json_str = json.dumps(random_graph)
                inconsistencies_list, clean_graph = get_inconsistencies(random_graph)
                if 'spoilers' in request.POST: 
                    spoilers = True
                else:
                    spoilers = False
                    json_str = json.dumps(clean_graph)
                print spoilers
                
                
            return render(request, 'provmanager/create.html', {"inconsistencies_list":inconsistencies_list, "spoilers":spoilers, "output_list":output_list, "filename":filename, "json_str": json_str, "isMop":isMop, "isCron":isCron, "valid":valid, "validation_url":validation_url})

        elif 'saveMop' in request.POST or 'saveCron' in request.POST:
            if 'saveCron' in request.POST:
                type = Provenance.TYPE_CRON
            else:
                type = Provenance.TYPE_MOP_TEMPLATE
            
            filename, graphml_str = getStuff(request)
            provn_str, output = convert_graphml_string(graphml_str)
            
            valid = True
            validation_url = "bla"
            #valid, validation_url = validate(provn_str)
            if valid:
                name = request.POST["filename"]
                if name=="":
                    name = "PLEASE ENTER A NAME"
                
                inconsistencies_list, clean_graph = get_inconsistencies(json.loads(provn_str.get_provjson()))

                if inconsistencies_list:
                    attribute1 = json.dumps(inconsistencies_list[0])
                    attribute2 = json.dumps(inconsistencies_list[1])
                else:
                    attribute1 = None
                    attribute2 = None
  
                bundle = ProvBundle.from_provjson(json.dumps(clean_graph))
                
                store_id = API.submit_document(bundle, name, public=False)

                provenance = Provenance(name=name, store_id=store_id, attribute1=attribute1, attribute2=attribute2, type=type)
                provenance.save()
                return HttpResponseRedirect(reverse('provmanager_index'))
            
    try:
        filename = request.session['filename']
    except:
        filename = ""      
    return render(request, 'provmanager/create.html', {"filename":filename})