Пример #1
0
 def visible_by_user(self, user):
     queryset = self.all()
     if not user.is_superuser:
         queryset = queryset.filter(
             Q(visible_by_roles__isnull=True) | Q(visible_by_roles__in=get_roles(user)),
         ).distinct()
     return queryset
Пример #2
0
 def current_roles(self, obj):
     role_ano = unicode(Role.objects.get(slug=ANONYMOUS_ROLE_SLUG))
     roles_str = None
     if obj.user:
         roles = get_roles(obj.user, obj.content)
         roles_str = ', '.join([unicode(role) for role in roles])
     if not roles_str:
         return role_ano
     return u'%s, %s' % (role_ano, roles_str)
Пример #3
0
 def current_roles(self, obj):
     role_ano = unicode(Role.objects.get(slug=ANONYMOUS_ROLE_SLUG))
     roles_str = None
     if obj.user:
         roles = get_roles(obj.user, obj.content)
         roles_str = ', '.join([unicode(role) for role in roles])
     if not roles_str:
         return role_ano
     return u'%s, %s' % (role_ano, roles_str)
Пример #4
0
 def save(self, *args, **kwargs):
     obj = super(AccessRequestForm, self).save(*args, **kwargs)
     if obj.content and isinstance(obj.content, BaseContent):
         obj.state = obj.content.workflow_status
     if self.user:
         obj.user = self.user
         roles = get_roles(obj.user, obj.content)
         for rol in roles:
             obj.roles.add(rol)
     obj.roles.add(Role.objects.get(slug=ANONYMOUS_ROLE_SLUG))
     owners = self.get_owners_of_content(obj)
     for owner in owners:
         obj.owners.add(owner)
     obj.save()
     self.notification_access_request(obj, owners)
     return obj
Пример #5
0
 def save(self, *args, **kwargs):
     obj = super(AccessRequestForm, self).save(*args, **kwargs)
     if obj.content and isinstance(obj.content, BaseContent):
         obj.state = obj.content.workflow_status
     if self.user:
         obj.user = self.user
         roles = get_roles(obj.user, obj.content)
         for rol in roles:
             obj.roles.add(rol)
     obj.roles.add(Role.objects.get(slug=ANONYMOUS_ROLE_SLUG))
     owners = self.get_owners_of_content(obj)
     for owner in owners:
         obj.owners.add(owner)
     obj.save()
     self.notification_access_request(obj, owners)
     return obj