Exemple #1
0
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)
Exemple #2
0
 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)
Exemple #3
0
 def apply_obj(cls, obj):
     if isinstance(obj, User):
        return "customergroup" in Group.get_groups(obj)
     return False
Exemple #4
0
 def test_model_group(self):
     assert_that(Group.get_groups(self.product_C), is_(["group_product_model"]))
Exemple #5
0
 def test_get_group_by_name(self):
     assert_that(Group.get_by_name("customergroup"), not_none())
Exemple #6
0
 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"))