def visible(self, user=None): if user is None: return self.filter(restriction_id__isnull=True) if user.has_perm(VIEW_PERMISSION_NAME): return self if user.id is None: return self.filter(restriction_id__isnull=True) condition = self._get_visible_condition(user.id, get_view_permission().id) return self.extra(where=[condition])
def visible(self, user=None): if user is None: return self.filter(restriction_id__isnull=True) if user.has_perm(VIEW_PERMISSION_NAME): return self if user.id is None: return self.filter(restriction_id__isnull=True) condition = self._get_visible_condition(user.id, get_view_permission().id) return self.extra(where=[condition])
def add_viewer(self, viewer, responsible=None, roles=None): roles = roles or DEFAULT_ROLE otp, created = OwnerToPermission.objects.get_or_create( object_id=self.pk, content_type=ContentType.objects.get_for_model(self), owner_object_id=viewer.pk, owner_content_type=ContentType.objects.get_for_model(viewer), permission=get_view_permission(), defaults={'responsible': responsible, 'roles': roles} ) if not created and otp.roles != roles: otp.roles |= roles otp.save()
def add_viewer(self, viewer, responsible=None, roles=None): roles = roles or DEFAULT_ROLE otp, created = OwnerToPermission.objects.get_or_create( object_id=self.pk, content_type=ContentType.objects.get_for_model(self), owner_object_id=viewer.pk, owner_content_type=ContentType.objects.get_for_model(viewer), permission=get_view_permission(), defaults={'responsible': responsible, 'roles': roles} ) if not created and otp.roles != roles: otp.roles |= roles otp.save()
def get_view_permission(cls): return get_view_permission()
def get_view_permission(cls): return get_view_permission()