def create_label(self, org, uuid, name, description, keywords=(), **kwargs): label = Label.objects.create(org=org, uuid=uuid, name=name, description=description, **kwargs) if keywords: rule = Rule.create(org, [ContainsTest(keywords, Quantifier.ANY)], [LabelAction(label)]) label.rule = rule label.save(update_fields=('rule',)) return label
def update_tests(self, tests): from casepro.rules.models import Rule, LabelAction if tests: if self.rule: self.rule.tests = json_encode(tests) self.rule.save(update_fields=('tests', )) else: self.rule = Rule.create(self.org, tests, [LabelAction(self)]) self.save(update_fields=('rule', )) else: if self.rule: rule = self.rule self.rule = None self.save(update_fields=('rule', )) rule.delete()
def update_tests(self, tests): from casepro.rules.models import Rule, LabelAction if tests: if self.rule: self.rule.tests = json_encode(tests) self.rule.save(update_fields=('tests',)) else: self.rule = Rule.create(self.org, tests, [LabelAction(self)]) self.save(update_fields=('rule',)) else: if self.rule: rule = self.rule self.rule = None self.save(update_fields=('rule',)) rule.delete()
def create_rule(self, org, tests, actions): return Rule.create(org, tests, actions)