Commits

Florian Hahn committed edbce89

add __unicode__ methods

Comments (0)

Files changed (2)

object_permission_backend_nonrel/models.py

     content_type = models.CharField(max_length=256)
     permission_name = models.CharField(max_length=64, null=True)
 
+    def __unicode__(self):
+        return u'%s:%s' % (self.content_type, self.permission_name)
+
 
 class BaseObjectPermission(models.Model):
     permissions = ListField(models.CharField(max_length=64))
 class ObjectPermission(BaseObjectPermission):
     user = models.ForeignKey(User, null=True)
     
+    def __unicode__(self):
+        return u'%s:%s:%i'%(self.user, self.content_type, self.object_id)
+
 
 class GroupObjectPermission(BaseObjectPermission):
     group = models.ForeignKey(Group, null=True)
+
+    def __unicode__(self):
+        return u'%s:%s:%i'%(self.group, self.content_type, self.object_id)

object_permission_backend_nonrel/tests.py

         self.assertEquals(self.user1.has_perm('view', self.obj_foo), True)
         self.assertEquals(self.user1.has_perm('view', self.obj_foo), True)
         self.assertEquals(self.user1.has_perm('invalid', self.obj_foo), False)
+
+    def test_object_permission_unicode_method(self):
+        test_obj = TestObjFoo()
+        test_obj.id = 1
+        
+        user_perm_obj = ObjectPermission.objects.create(user=self.user1, object_id=test_obj.id, content_type=get_content_type_string(test_obj))
+
+        self.assertEquals('%s:%s:%i'%(self.user1, get_content_type_string(test_obj), test_obj.id), user_perm_obj.__unicode__())
+
+    def test_group_object_permission_unicode_method(self):
+        test_obj = TestObjFoo()
+        test_obj.id = 1
+        group = Group.objects.create(name='Group1')
+        
+        group_perm_obj = GroupObjectPermission.objects.create(group=group, object_id=test_obj.id, content_type=get_content_type_string(test_obj))
+
+        self.assertEquals('%s:%s:%i'%(group, get_content_type_string(test_obj), test_obj.id), group_perm_obj.__unicode__())
+
+    def test_permission_type__unicode_method(self):
+        permission_type = PermissionType.objects.create(content_type=get_content_type_string(TestObjFoo()), permission_name='foo')
+        
+        self.assertEquals('%s:%s'%(get_content_type_string(TestObjFoo()), 'foo'), permission_type.__unicode__())
+        
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+