コード例 #1
0
 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)
コード例 #2
0
 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()
コード例 #3
0
 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')
コード例 #4
0
ファイル: models.py プロジェクト: Palanaeum/palanaeum
 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()
コード例 #5
0
ファイル: models.py プロジェクト: IAmEki/palanaeum
 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)))
コード例 #6
0
    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
コード例 #7
0
 def editable(self):
     return is_contributor(get_request())
コード例 #8
0
 def editable(self):
     request = get_request()
     if hasattr(request, 'user') and request.user.is_staff:
         return True
     return False
コード例 #9
0
 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
コード例 #10
0
 def editable(self):
     request = get_request()
     if request.user.is_staff or request.user == self.created_by:
         return True
     return False
コード例 #11
0
def get_current_user():
    return getattr(get_request(), 'user', None)
コード例 #12
0
 def editable(self):
     request = get_request()
     return request.user.is_authenticated