def save(self, *args, **kwargs): self.modified_date = timezone.now() request = get_request() if request and hasattr(request, 'user') and isinstance( request.user, User): self.modified_by = request.user super(Content, self).save(*args, **kwargs)
def approve(self): request = get_request() if not request.user.is_staff: raise PermissionDenied() self.is_approved = True self.approved_date = timezone.now() self.approved_by = request.user self.save()
def get_queryset(self): request = get_request() if not (request and hasattr(request, 'user')): user = AnonymousUser() else: user = request.user queryset = super(NewestEntryVersionManager, self).get_queryset() if not user.is_staff: if user.is_authenticated: queryset = queryset.filter(entry__is_visible=True) else: queryset = queryset.filter(entry__is_visible=True, is_approved=True) return queryset.order_by('entry_id', '-date', 'id').distinct('entry_id')
def get_tag(name: str): if not name: return None name = name.strip().lower() name = Tag.TAG_SANITIZER.sub("", name) name = " ".join(name.split()) name = name[:Tag.NAME_LENGTH] try: return Tag.objects.get(name__iexact=name) except Tag.DoesNotExist: request = get_request() if request.user.is_staff: return Tag.objects.create(name=name) else: raise PermissionDenied()
def get_queryset(self): request = get_request() if not (request and hasattr(request, 'user')): user = AnonymousUser() else: user = request.user if user.is_staff: return super(VisibleManager, self).get_queryset() else: if user.is_authenticated: return super(VisibleManager, self).get_queryset().filter(is_visible=True) else: return super(VisibleManager, self).get_queryset().filter( Q(is_visible=True) & (Q(is_approved=True)))
def generate_queryset(self, approved_only): request = get_request() if not (request and hasattr(request, 'user')): user = AnonymousUser() else: user = request.user queryset = super(VisibleManager, self).get_queryset() if user.is_staff: return queryset queryset = queryset.filter(is_visible=True) if user.is_anonymous: queryset = queryset.filter(is_approved=True) elif approved_only: queryset = queryset.filter( Q(is_approved=True) | Q(created_by=user)) return queryset
def editable(self): return is_contributor(get_request())
def editable(self): request = get_request() if hasattr(request, 'user') and request.user.is_staff: return True return False
def visible(self) -> bool: request = get_request() if hasattr(request, 'user'): return self.visible_for(request.user) else: return self.is_visible and self.is_approved
def editable(self): request = get_request() if request.user.is_staff or request.user == self.created_by: return True return False
def get_current_user(): return getattr(get_request(), 'user', None)
def editable(self): request = get_request() return request.user.is_authenticated