def regularization(request): # get data from form, send to collatex engine and send resultant collation # onto the page that can change the collation url = 'http://127.0.0.1:8080/collatex-web-0.9.1-RC2/api/collate' headers = { 'Content-Type': 'application/json', 'Accept': 'application/json' } # creates form, if necessary form = WitnessInputForm(request.POST or None) # getting data from form # POST means form has been submit if request.method == 'POST' and form.is_valid(): witnessA = form.cleaned_data['witness_a'] witnessB = form.cleaned_data['witness_b'] witnessC = form.cleaned_data['witness_c'] witnessD = form.cleaned_data['witness_d'] witnessE = form.cleaned_data['witness_e'] jdata = json.dumps({ "witnesses": [{ "id": "A", "content": witnessA }, { "id": "B", "content": witnessB }, { "id": "C", "content": witnessC }, { "id": "D", "content": witnessD }, { "id": "E", "content": witnessE }] }) send = httplib2.Http() response, content = send.request(url, 'POST', jdata, headers) # print response # print content jdata = json.loads(content) # print jdata # saving collation to database c = Collation() c.save() for data in jdata['alignment']: # print data['witness'] # print data['tokens'][2]['t'] content = "" pos = 0 w = Witness() w.witnessId = data['witness'] w.save() #must save before can add to manytomanyfield of witness for token in data['tokens']: if token != None: print token['t'] content = content + token['t'] + " " # t = Token(content=token['t'], position=pos,\ # witnessId=data['witness']) # t.save() # must save before can add to m2mfield of witness t = Token.objects.create(content=token['t'],\ original=token['t'],\ position=pos,\ witnessId=data['witness']) w.tokenList.add(t) w.save() else: print "" # t = Token(content="", position=pos,\ # witnessId=data['witness']) # t.save() t = Token.objects.create(content="",\ original="",\ position=pos,\ witnessId=data['witness']) w.tokenList.add(t) w.save() pos = pos + 1 # print content w.content = content # print w w.save() # changes to databases only happen with .save() is called c.witnessList.add(w) c.save() # change pages - to modifications page # redirect to page in urls.py return HttpResponseRedirect('/regularization/change/0/') return render_to_response('input/regularisation.html', {'form': form})
def regularization(request): # get data from form, send to collatex engine and send resultant collation # onto the page that can change the collation url = 'http://127.0.0.1:8080/collatex-web-0.9.1-RC2/api/collate' headers = {'Content-Type': 'application/json', 'Accept': 'application/json'} # creates form, if necessary form = WitnessInputForm(request.POST or None) # getting data from form # POST means form has been submit if request.method == 'POST' and form.is_valid(): witnessA = form.cleaned_data['witness_a'] witnessB = form.cleaned_data['witness_b'] witnessC = form.cleaned_data['witness_c'] witnessD = form.cleaned_data['witness_d'] witnessE = form.cleaned_data['witness_e'] jdata = json.dumps({"witnesses" : [{"id" : "A", "content" : witnessA }, {"id" : "B", "content" : witnessB }, {"id" : "C", "content" : witnessC }, {"id" : "D", "content" : witnessD }, {"id" : "E", "content" : witnessE }]}) send = httplib2.Http() response, content = send.request(url, 'POST', jdata, headers) # print response # print content jdata = json.loads(content) # print jdata # saving collation to database c = Collation() c.save() for data in jdata['alignment']: # print data['witness'] # print data['tokens'][2]['t'] content = "" pos = 0 w = Witness() w.witnessId = data['witness'] w.save() #must save before can add to manytomanyfield of witness for token in data['tokens']: if token != None: print token['t'] content = content + token['t'] + " " # t = Token(content=token['t'], position=pos,\ # witnessId=data['witness']) # t.save() # must save before can add to m2mfield of witness t = Token.objects.create(content=token['t'],\ original=token['t'],\ position=pos,\ witnessId=data['witness']) w.tokenList.add(t) w.save() else: print "" # t = Token(content="", position=pos,\ # witnessId=data['witness']) # t.save() t = Token.objects.create(content="",\ original="",\ position=pos,\ witnessId=data['witness']) w.tokenList.add(t) w.save() pos = pos + 1 # print content w.content = content # print w w.save() # changes to databases only happen with .save() is called c.witnessList.add(w) c.save() # change pages - to modifications page # redirect to page in urls.py return HttpResponseRedirect('/regularization/change/0/') return render_to_response('input/regularisation.html', {'form': form})
def recollate(): # get data from form, send to collatex engine and send resultant collation # onto the page that can change the collation url = 'http://127.0.0.1:8080/collatex-web-0.9.1-RC2/api/collate' headers = { 'Content-Type': 'application/json', 'Accept': 'application/json' } # creates form, if necessary form = WitnessInputForm() position = 0 jdata = '{"witnesses" : [' for w in Witness.objects.all(): if position != 0: jdata = jdata + ',' tokens = Token.objects.filter(witnessId=w.witnessId) jdata = jdata + '{"id": ' + jsonpickle.encode(w.witnessId) +\ ', "tokens" : [' tokPos = 0 for t in tokens: if tokPos != 0 and comma == True: jdata = jdata + ',' comma = False token = tokens.filter(position=tokPos) for t in token: if t.content != '': jdata = jdata + '{ "t" : ' + jsonpickle.encode(t.content)\ + '}' comma = True tokPos = tokPos + 1 jdata = jdata + ']}' position = position + 1 jdata = jdata + ']}' # print jdata send = httplib2.Http() response, content = send.request(url, 'POST', jdata, headers) # print response # print content jdata = json.loads(content) # print jdata # DELETE EVERYTHING OUT OF DATABASE # TODO: JUST delete the ones that correspond to what recollating Token.objects.all().delete() Witness.objects.all().delete() Collation.objects.all().delete() c = Collation() c.save() for data in jdata['alignment']: content = "" pos = 0 w = Witness() w.witnessId = data['witness'] w.save() #must save before can add to manytomanyfield of witness for token in data['tokens']: if token != None: content = content + token['t'] + " " # must save before can add to m2mfield of witness t = Token.objects.create(content=token['t'], position=pos,\ witnessId=data['witness']) w.tokenList.add(t) w.save() else: t = Token.objects.create(content="", position=pos,\ witnessId=data['witness']) w.tokenList.add(t) w.save() pos = pos + 1 w.content = content w.save() # changes to databases only happen with .save() is called c.witnessList.add(w) c.save() # change pages - to modifications page # redirect to page in urls.py return HttpResponseRedirect('/regularization/change/0/')
def recollate(): # get data from form, send to collatex engine and send resultant collation # onto the page that can change the collation url = 'http://127.0.0.1:8080/collatex-web-0.9.1-RC2/api/collate' headers = {'Content-Type': 'application/json', 'Accept': 'application/json'} # creates form, if necessary form = WitnessInputForm() position = 0 jdata = '{"witnesses" : [' for w in Witness.objects.all(): if position != 0: jdata = jdata + ',' tokens = Token.objects.filter(witnessId=w.witnessId) jdata = jdata + '{"id": ' + jsonpickle.encode(w.witnessId) +\ ', "tokens" : [' tokPos = 0 for t in tokens: if tokPos != 0 and comma == True: jdata = jdata + ',' comma = False token = tokens.filter(position=tokPos) for t in token: if t.content != '': jdata = jdata + '{ "t" : ' + jsonpickle.encode(t.content)\ + '}' comma = True tokPos = tokPos + 1 jdata = jdata + ']}' position = position + 1 jdata = jdata + ']}' # print jdata send = httplib2.Http() response, content = send.request(url, 'POST', jdata, headers) # print response # print content jdata = json.loads(content) # print jdata # DELETE EVERYTHING OUT OF DATABASE # TODO: JUST delete the ones that correspond to what recollating Token.objects.all().delete() Witness.objects.all().delete() Collation.objects.all().delete() c = Collation() c.save() for data in jdata['alignment']: content = "" pos = 0 w = Witness() w.witnessId = data['witness'] w.save() #must save before can add to manytomanyfield of witness for token in data['tokens']: if token != None: content = content + token['t'] + " " # must save before can add to m2mfield of witness t = Token.objects.create(content=token['t'], position=pos,\ witnessId=data['witness']) w.tokenList.add(t) w.save() else: t = Token.objects.create(content="", position=pos,\ witnessId=data['witness']) w.tokenList.add(t) w.save() pos = pos + 1 w.content = content w.save() # changes to databases only happen with .save() is called c.witnessList.add(w) c.save() # change pages - to modifications page # redirect to page in urls.py return HttpResponseRedirect('/regularization/change/0/')