def postSelectedRuleSets(request): if request.is_ajax(): if request.method == 'POST': request.session['selectedRuleSet'] = request.POST.get('data') ruleSet = json.loads(request.POST.get('data')) filteredRuleSet = RuleSet.objects.filter(userId=ruleSet['userName']).filter(\ appliesTo=ruleSet['urn']).filter(\ name=ruleSet['ruleSetName']) if not filteredRuleSet: rs = RuleSet() rs.userId = ruleSet['userName'] rs.appliesTo = ruleSet['urn'] rs.name = ruleSet['ruleSetName'] rs.save() return HttpResponse("OK")
def regularization(request): # request should contain json with username and urn #urn = "urn:det:TCUSASK:CTP2:entity=MI:Tale=MI:Line=IR" #userName = "******" urn = request.GET.get('urn', '') userName = request.GET.get('username', '') returnUrl = request.GET.get('page', '') # if request.session.get('selectedRuleSet'): # request.session.pop('selectedRuleSet') # if request.session.get('selectedWitnesses'): # request.session.pop('selectedWitnesses') # if request.session.get('images'): # request.session.pop('images') # if request.session.get('data'): # request.session.pop('data') if request.session.get('urn'): urnOld = request.session.pop('urn') if urnOld != urn: print "erase old: " + urnOld + "; new: " + urn if request.session.get('selectedRuleSet'): request.session.pop('selectedRuleSet') if request.session.get('selectedWitnesses'): request.session.pop('selectedWitnesses') if request.session.get('images'): request.session.pop('images') if request.session.get('data'): request.session.pop('data') regularization(request) if request.session.get('selectedRuleSet'): jdata = json.loads(request.session.pop('selectedRuleSet')) request.session['selectedRuleSet'] = json.dumps(jdata) ruleSetName = jdata['ruleSetName'] ruleSet = jdata['ruleSet'] images = request.session.pop('images') request.session['images'] = images if request.session.get('selectedWitnesses'): jdata = json.loads(request.session.pop('selectedWitnesses')) #print jdata witnesses = jdata['witnesses'] request.session['selectedWitnesses'] = json.dumps(jdata) allWitnesses = False else: allWitnesses = True witnesses = request.session.pop('data') request.session['data'] = witnesses witnesses = checkDuplicateWitnesses(witnesses) else: if request.session.get('selectedWitnesses'): allWitnesses = False witnesses = json.loads(request.session.pop('selectedWitnesses')) witnesses = witnesses['witnesses'] request.session['selectedWitnesses'] = json.dumps(witnesses) images = request.session.pop('images') request.session['images'] = images else: allWitnesses = True witData = getWitnessData(urn) witnesses = json.loads(witData[0]) witnesses = checkDuplicateWitnesses(witnesses['witnesses']) request.session['data'] = witnesses request.session['images'] = witData[1] images = witData[1] ruleSets = json.loads(getRuleSets(userName, urn)) ruleSetName = 'default' filteredRuleSet = RuleSet.objects.filter(userId=userName).filter(\ appliesTo=urn).filter(name=ruleSetName) if not filteredRuleSet: rs = RuleSet() rs.userId = userName rs.appliesTo = urn rs.name = ruleSetName rs.save() ruleSet = '{}' else: for rs in ruleSets['ruleSets']: if rs['name'] == "default": ruleSet = rs witnesses = json.dumps({'witnesses': witnesses}) ruleSet = json.dumps({'ruleSet': ruleSet}) request.session['urn'] = urn urlCollation = 'http://127.0.0.1:8080/collatex-web-0.9.1-RC2/api/collate' headers = { 'Content-Type': 'application/json', 'Accept': 'application/json' } send = httplib2.Http() response, content = send.request(urlCollation, 'POST', witnesses, headers) return render_to_response('jsRegularize/collate_interface.html', { "userName": userName, "urn": urn, "witnessesTokens": content, "witnessesLines": witnesses, "ruleSetName": ruleSetName, "ruleSet": ruleSet, "position": 0, "images": images, "returnUrl": returnUrl, "isAllWitnesses": allWitnesses }, context_instance=RequestContext(request))
def regularization(request): # request should contain json with username and urn #urn = "urn:det:TCUSASK:CTP2:entity=MI:Tale=MI:Line=IR" #userName = "******" urn = request.GET.get('urn', '') userName = request.GET.get('username', '') returnUrl = request.GET.get('page', '') # if request.session.get('selectedRuleSet'): # request.session.pop('selectedRuleSet') # if request.session.get('selectedWitnesses'): # request.session.pop('selectedWitnesses') # if request.session.get('images'): # request.session.pop('images') # if request.session.get('data'): # request.session.pop('data') if request.session.get('urn'): urnOld = request.session.pop('urn') if urnOld != urn: print "erase old: " + urnOld + "; new: " + urn if request.session.get('selectedRuleSet'): request.session.pop('selectedRuleSet') if request.session.get('selectedWitnesses'): request.session.pop('selectedWitnesses') if request.session.get('images'): request.session.pop('images') if request.session.get('data'): request.session.pop('data') regularization(request) if request.session.get('selectedRuleSet'): jdata = json.loads(request.session.pop('selectedRuleSet')) request.session['selectedRuleSet'] = json.dumps(jdata) ruleSetName = jdata['ruleSetName'] ruleSet = jdata['ruleSet'] images = request.session.pop('images') request.session['images'] = images if request.session.get('selectedWitnesses'): jdata = json.loads(request.session.pop('selectedWitnesses')) #print jdata witnesses = jdata['witnesses'] request.session['selectedWitnesses'] = json.dumps(jdata) allWitnesses = False else: allWitnesses = True witnesses = request.session.pop('data') request.session['data'] = witnesses witnesses = checkDuplicateWitnesses(witnesses) else: if request.session.get('selectedWitnesses'): allWitnesses = False witnesses = json.loads(request.session.pop('selectedWitnesses')) witnesses = witnesses['witnesses'] request.session['selectedWitnesses'] = json.dumps(witnesses) images = request.session.pop('images') request.session['images'] = images else: allWitnesses = True witData = getWitnessData(urn) witnesses = json.loads(witData[0]) witnesses = checkDuplicateWitnesses(witnesses['witnesses']) request.session['data'] = witnesses request.session['images'] = witData[1] images = witData[1] ruleSets = json.loads(getRuleSets(userName, urn)) ruleSetName = 'default' filteredRuleSet = RuleSet.objects.filter(userId=userName).filter(\ appliesTo=urn).filter(name=ruleSetName) if not filteredRuleSet: rs = RuleSet() rs.userId = userName rs.appliesTo = urn rs.name = ruleSetName rs.save() ruleSet = '{}' else: for rs in ruleSets['ruleSets']: if rs['name'] == "default": ruleSet = rs witnesses = json.dumps({'witnesses': witnesses}) ruleSet = json.dumps({'ruleSet': ruleSet}) request.session['urn'] = urn urlCollation = 'http://127.0.0.1:8080/collatex-web-0.9.1-RC2/api/collate' headers = {'Content-Type': 'application/json', 'Accept': 'application/json'} send = httplib2.Http() response, content = send.request(urlCollation, 'POST', witnesses, headers) return render_to_response('jsRegularize/collate_interface.html', {"userName" : userName, "urn" : urn, "witnessesTokens" : content, "witnessesLines": witnesses, "ruleSetName": ruleSetName, "ruleSet": ruleSet, "position": 0, "images": images, "returnUrl": returnUrl, "isAllWitnesses": allWitnesses}, context_instance=RequestContext(request))