def create_group_model(sender, **kwargs): logging.debug("Receive prepared signal for %s", sender) if isinstance(sender, type): class_name = get_model_group_name(sender.__name__) if not Group.get_by_name(class_name): group = create_group_class(sender) Group.register(group)
def save(self, *args, **kwargs): from rules.base import Group, Predicate super(Rule, self).save(*args, **kwargs) for group in self.groups.all(): if group not in Group.get_group_names(): self.delete() raise ValueError("Group '%s' has not been registered" % group) if self.predicate not in Predicate.get_rule_names() and self.predicate: self.delete() raise ValueError("Predicate '%s' has not been registered" % self.predicate)
def apply_obj(cls, obj): if isinstance(obj, User): return "customergroup" in Group.get_groups(obj) return False
def test_model_group(self): assert_that(Group.get_groups(self.product_C), is_(["group_product_model"]))
def test_get_group_by_name(self): assert_that(Group.get_by_name("customergroup"), not_none())
def test_get_group(self): assert_that(Group.get_groups(self.customer), has_item("customergroup")) assert_that(Group.get_groups(self.admin), has_item("admingroup"))