def description(update, context): context.user_data['event'].description = update.message.text modification = Modification(author=update.message.from_user.username) context.user_data['event'].modifications = [modification] context.user_data['messages'].append(update.message) save_event(update, context) return ConversationHandler.END
def postNewRule(request): #Modification.objects.all().delete() #Rule.objects.all().delete() if request.is_ajax(): if request.method == 'POST': jdata = json.loads(request.raw_post_data) print jdata # if jdata['rules'][0]['scope'] == 'this_place': # filteredRuleSet = RuleSet.objects.filter(userId=jdata['userName']).filter(\ # appliesTo=jdata['urn']).filter(name=jdata['ruleSetName']) # elif jdata['rules'][0]['scope'] == 'this_entity': # print "this_entity" # elif jdata['rules'][0]['scope'] == 'this_place': # print "all_places" filteredRuleSet = RuleSet.objects.filter(userId=jdata['userName']).filter(\ appliesTo=jdata['urn']).filter(name=jdata['ruleSetName']) if filteredRuleSet and filteredRuleSet.count() == 1: filteredModifications = Modification.objects.filter(userId=jdata['userName']).filter(\ modification_type=jdata['rules'][0]['modifications'][0]['modification_type']).filter(\ dateTime=jdata['rules'][0]['modifications'][0]['dateTime']) found = False for rule in filteredRuleSet[0].rules.all(): if (rule.appliesTo == jdata['urn'] and rule.action == \ jdata['rules'][0]['action'] and rule.scope == jdata['rules'][0]['scope'] \ and rule.token == jdata['rules'][0]['token']): found = True if not filteredModifications and not found: m = Modification() m.userId = jdata['userName'] m.modification_type = jdata['rules'][0]['modifications'][ 0]['modification_type'] m.dateTime = jdata['rules'][0]['modifications'][0][ 'dateTime'] m.save() r = Rule() r.appliesTo = jdata['urn'] r.action = jdata['rules'][0]['action'] r.scope = jdata['rules'][0]['scope'] r.token = jdata['rules'][0]['token'] r.save() r.modifications.add(m) filteredRuleSet[0].rules.add(r) else: print "error: filteredModifications OR filteredRules" else: print "error: filteredRuleSet" return HttpResponse("OK")
def changeRules(request): if request.is_ajax(): if request.method == 'POST': jdata = json.loads(request.POST.get('data')) filteredRuleSet = RuleSet.objects.filter(userId=jdata['userName']).filter(\ appliesTo=jdata['urn']).filter(name=jdata['ruleSetName']) if filteredRuleSet and filteredRuleSet.count() == 1: for modification in jdata['rules']: found = False for rule in filteredRuleSet[0].rules.all(): if (rule.appliesTo == jdata['urn'] and rule.action == \ modification['action'] and rule.scope == modification['scope'] \ and rule.token == modification['token']): found = True modifiedRule = rule if found: m = Modification() m.userId = jdata['userName'] m.modification_type = modification['modifications'][-1]['modification_type'] m.dateTime = modification['modifications'][-1]['dateTime'] m.save() modifiedRule.modifications.add(m) modify = modification['modifications'][-1]['modification_type'] if modify != 'delete': modify = modify.split("modify(") modify = "".join(modify) modify = modify.split(")") modify = "".join(modify) modify = modify.split(",") modType = modify[0] modFrom = modify[1] modTo = modify[2] if(modType == 'scope'): modifiedRule.scope = modTo if(modType == 'reg_this'): modifiedRule.token = modTo regTo = modifedRule.action.split(",")[-1] regTo = "".join(regTo) regTo = regTo.split(")")[0] regTo = "".join(regTo) modifiedRule.action = "regularize(" + modTo + "," + regTo + ")"; if(modType == 'reg_to'): regThis = modifieRule.action.split(",")[0] regThis = "".join(regThis) regThis = regThis.split("(")[-1] regThis = "".join(regThis) modifedRule.action = "regularize(" + regThis + "," + modTo + ")"; modifiedRule.save() return HttpResponse("OK")
def postNewAlign(request): if request.is_ajax(): if request.method == 'POST': jdata = json.loads(request.raw_post_data) #print jdata filteredRuleSet = RuleSet.objects.filter(userId=jdata['userName']).filter(\ appliesTo=jdata['urn']).filter(name=jdata['ruleSetName']) if filteredRuleSet and filteredRuleSet.count() == 1: for newAlign in jdata['alignments']: found = False print newAlign for align in filteredRuleSet[0].alignments.all(): if (align.appliesTo == jdata['urn'] and align.appliesTo == \ newAlign['appliesTo'] and align.witnessId == \ newAlign['witnessId'] and align.isForward == \ newAlign['isForward'] and align.isMove == \ newAlign['isMove'] and align.numPos == \ newAlign['numPos'] and align.token == \ newAlign['position'] and align.position == \ newAlign['token'] and align.context == \ newAlign['context']): print "hereFound" found = True if not found: print "here" m = Modification() m.userId = jdata['userName'] m.modification_type = newAlign['modifications'][0]\ ['modification_type'] m.dateTime = newAlign['modifications'][0]['dateTime'] m.save() a = Alignment() a.appliesTo = jdata['urn'] a.witnessId = newAlign['witnessId'] a.isMove = newAlign['isMove'] a.isForward = newAlign['isForward'] a.token = newAlign['token'] a.numPos = newAlign['numPos'] a.context = newAlign['context'] a.position = newAlign['position'] a.save() print a.witnessId a.modifications.add(m) filteredRuleSet[0].alignments.add(a) else: print "error: filteredRuleSet" return HttpResponse("OK")
def postNewRule(request): #Modification.objects.all().delete() #Rule.objects.all().delete() if request.is_ajax(): if request.method == 'POST': jdata = json.loads(request.raw_post_data) print jdata # if jdata['rules'][0]['scope'] == 'this_place': # filteredRuleSet = RuleSet.objects.filter(userId=jdata['userName']).filter(\ # appliesTo=jdata['urn']).filter(name=jdata['ruleSetName']) # elif jdata['rules'][0]['scope'] == 'this_entity': # print "this_entity" # elif jdata['rules'][0]['scope'] == 'this_place': # print "all_places" filteredRuleSet = RuleSet.objects.filter(userId=jdata['userName']).filter(\ appliesTo=jdata['urn']).filter(name=jdata['ruleSetName']) if filteredRuleSet and filteredRuleSet.count() == 1: filteredModifications = Modification.objects.filter(userId=jdata['userName']).filter(\ modification_type=jdata['rules'][0]['modifications'][0]['modification_type']).filter(\ dateTime=jdata['rules'][0]['modifications'][0]['dateTime']) found = False for rule in filteredRuleSet[0].rules.all(): if (rule.appliesTo == jdata['urn'] and rule.action == \ jdata['rules'][0]['action'] and rule.scope == jdata['rules'][0]['scope'] \ and rule.token == jdata['rules'][0]['token']): found = True if not filteredModifications and not found: m = Modification() m.userId = jdata['userName'] m.modification_type = jdata['rules'][0]['modifications'][0]['modification_type'] m.dateTime = jdata['rules'][0]['modifications'][0]['dateTime'] m.save() r = Rule() r.appliesTo = jdata['urn'] r.action = jdata['rules'][0]['action'] r.scope = jdata['rules'][0]['scope'] r.token = jdata['rules'][0]['token'] r.save() r.modifications.add(m) filteredRuleSet[0].rules.add(r) else: print "error: filteredModifications OR filteredRules" else: print "error: filteredRuleSet" return HttpResponse("OK")
def changeAligns(request): if request.is_ajax(): if request.method == 'POST': jdata = json.loads(request.raw_post_data) print jdata filteredRuleSet = RuleSet.objects.filter(userId=jdata['userName']).filter(\ appliesTo=jdata['urn']).filter(name=jdata['ruleSetName']) if filteredRuleSet and filteredRuleSet.count() == 1: for modification in jdata['alignments']: found = False for align in filteredRuleSet[0].alignments.all(): if (align.appliesTo == jdata['urn'] and align.appliesTo == \ modification['appliesTo'] and align.witnessId == \ modification['witnessId'] and align.isForward == \ modification['isForward'] and align.isMove == \ modification['isMove'] and align.numPos == \ modification['numPos'] and align.token == \ modification['token'] and align.position == \ modification['position'] and align.context == \ modification['context']): modifications = align.modifications.all() number = 1 for modificationIn in modifications: if(number == len(modifications) and modificationIn.modification_type != \ 'delete'): print "here" m = Modification() m.userId = jdata['userName'] m.modification_type = modification['modifications'][-1]\ ['modification_type'] m.dateTime = modification['modifications'][ -1]['dateTime'] m.save() align.modifications.add(m) number = number + 1 return HttpResponse("OK")
def changeAligns(request): if request.is_ajax(): if request.method == 'POST': jdata = json.loads(request.raw_post_data) print jdata filteredRuleSet = RuleSet.objects.filter(userId=jdata['userName']).filter(\ appliesTo=jdata['urn']).filter(name=jdata['ruleSetName']) if filteredRuleSet and filteredRuleSet.count() == 1: for modification in jdata['alignments']: found = False for align in filteredRuleSet[0].alignments.all(): if (align.appliesTo == jdata['urn'] and align.appliesTo == \ modification['appliesTo'] and align.witnessId == \ modification['witnessId'] and align.isForward == \ modification['isForward'] and align.isMove == \ modification['isMove'] and align.numPos == \ modification['numPos'] and align.token == \ modification['token'] and align.position == \ modification['position'] and align.context == \ modification['context']): modifications = align.modifications.all() number = 1 for modificationIn in modifications: if(number == len(modifications) and modificationIn.modification_type != \ 'delete'): print "here" m = Modification() m.userId = jdata['userName'] m.modification_type = modification['modifications'][-1]\ ['modification_type'] m.dateTime = modification['modifications'][-1]['dateTime'] m.save() align.modifications.add(m) number = number + 1 return HttpResponse("OK")
def changeRules(request): if request.is_ajax(): if request.method == 'POST': jdata = json.loads(request.POST.get('data')) filteredRuleSet = RuleSet.objects.filter(userId=jdata['userName']).filter(\ appliesTo=jdata['urn']).filter(name=jdata['ruleSetName']) if filteredRuleSet and filteredRuleSet.count() == 1: for modification in jdata['rules']: found = False for rule in filteredRuleSet[0].rules.all(): if (rule.appliesTo == jdata['urn'] and rule.action == \ modification['action'] and rule.scope == modification['scope'] \ and rule.token == modification['token']): found = True modifiedRule = rule if found: m = Modification() m.userId = jdata['userName'] m.modification_type = modification['modifications'][ -1]['modification_type'] m.dateTime = modification['modifications'][-1][ 'dateTime'] m.save() modifiedRule.modifications.add(m) modify = modification['modifications'][-1][ 'modification_type'] if modify != 'delete': modify = modify.split("modify(") modify = "".join(modify) modify = modify.split(")") modify = "".join(modify) modify = modify.split(",") modType = modify[0] modFrom = modify[1] modTo = modify[2] if (modType == 'scope'): modifiedRule.scope = modTo if (modType == 'reg_this'): modifiedRule.token = modTo regTo = modifedRule.action.split(",")[-1] regTo = "".join(regTo) regTo = regTo.split(")")[0] regTo = "".join(regTo) modifiedRule.action = "regularize(" + modTo + "," + regTo + ")" if (modType == 'reg_to'): regThis = modifieRule.action.split(",")[0] regThis = "".join(regThis) regThis = regThis.split("(")[-1] regThis = "".join(regThis) modifedRule.action = "regularize(" + regThis + "," + modTo + ")" modifiedRule.save() return HttpResponse("OK")