def clean(self): super().clean() if not can_moderate(self.article, self.request.user): raise forms.ValidationError( gettext("User not allowed to moderate this article") ) return self.cleaned_data
def get_queryset(self): if not self.query: return models.Article.objects.none() # test for language:<lang> along with query match = re.match('(?:language:(?P<lb>\w+)\s(?P<qb>.*)|(?P<qa>.*)\slanguage:(?P<la>\w+))', self.query) if match: lang = match.group('la') realquery = match.group('qa') if lang is None: lang = match.group('lb') realquery = match.group('qb') articles = models.Article.objects.filter(Q(urlpath__language=lang) & (Q(current_revision__title__icontains=realquery) | Q(current_revision__content__icontains=realquery))) self.query = "language:%s %s" % (lang, realquery) # test for language:<lang> alone - show all article of <lang> elif re.match('language:(?P<l>\w+)',self.query): lang = re.match('language:(?P<l>\w+)',self.query).group('l') articles = models.Article.objects.filter(Q(urlpath__language=lang)) else: articles = models.Article.objects.filter(Q(current_revision__title__icontains=self.query) | Q(current_revision__content__icontains=self.query)) if not permissions.can_moderate(models.URLPath.root().article, self.request.user): articles = articles.active().can_read(self.request.user) return articles
def get_queryset(self): if not self.query: return models.Article.objects.get_empty_query_set() articles = models.Article.objects.filter(Q(current_revision__title__icontains=self.query) | Q(current_revision__content__icontains=self.query)) if not permissions.can_moderate(models.URLPath.root().article, self.request.user): articles = articles.active().can_read(self.request.user) return articles
def __call__(self, request): self.request = request if self.request.user.is_anonymous and not settings.ANONYMOUS: return redirect(settings.LOGIN_URL) self.form = self.build_form() self.query = self.get_query() self.results = self.get_results() if not permissions.can_moderate(models.URLPath.root().article, self.request.user): self.results = self.__filter_can_read(self.request.user) #self.results = self.results.filter(current_revision__deleted=False) return self.create_response()
def __call__(self, request): self.request = request if self.request.user.is_anonymous and not settings.ANONYMOUS: return redirect(settings.LOGIN_URL) self.form = self.build_form() self.query = self.get_query() self.results = self.get_results() if not permissions.can_moderate(models.URLPath.root().article, self.request.user): self.results = self.__filter_can_read(self.request.user) return self.create_response()
def get_queryset(self): qs = SearchQuerySet().all() if self.request.user.is_authenticated: if not permissions.can_moderate(models.URLPath.root().article, self.request.user): qs = qs.filter( SQ(owner_id=self.request.user.id) | (SQ(group_id__in=self.request.user.groups.values_list( 'id', flat=True)) & SQ(group_read=True)) | SQ(other_read=True)) else: qs = qs.exclude(other_read=False) qs = qs.filter(content=AutoQuery(self.query)) qs = qs.load_all() return qs
def get_queryset(self): qs = SearchQuerySet().all() if self.request.user.is_authenticated(): # TODO: This has a leak! It should say: # group=self.request.group.id AND group_read=True if not permissions.can_moderate(models.URLPath.root().article, self.request.user): qs = qs.filter_or(owner=self.request.user.id, group=self.request.group.id, other_read=True) else: qs = qs.exclude(other_read=False) qs = qs.filter(content=AutoQuery(self.query)) qs = qs.exclude(other_read=False) qs = qs.load_all() return qs
def get_queryset(self): qs = SearchQuerySet().all() if self.request.user.is_authenticated(): if not permissions.can_moderate(models.URLPath.root().article, self.request.user): qs = qs.filter( SQ(owner_id=self.request.user.id) | ( SQ(group_id__in=self.request.user.groups.values_list('id', flat=True)) & SQ(group_read=True) ) | SQ(other_read=True) ) else: qs = qs.exclude(other_read=False) qs = qs.filter(content=AutoQuery(self.query)) qs = qs.load_all() return qs
def get_queryset(self): qs = SearchQuerySet().all() if self.request.user.is_authenticated(): # TODO: This has a leak! It should say: # group=self.request.group.id AND group_read=True if not permissions.can_moderate(models.URLPath.root().article, self.request.user): qs = qs.filter_or( owner=self.request.user.id, group=self.request.group.id, other_read=True ) else: qs = qs.exclude(other_read=False) qs = qs.filter(content=AutoQuery(self.query)) qs = qs.exclude(other_read=False) qs = qs.load_all() return qs
def get_queryset(self): if not self.query: return models.Article.objects.none().order_by('-current_revision__created') articles = models.Article.objects path = self.kwargs.get('path', None) if path: try: self.urlpath = models.URLPath.get_by_path(path) article_ids = self.urlpath.get_descendants( include_self=True).values_list('article_id') articles = articles.filter(id__in=article_ids) except (NoRootURL, models.URLPath.DoesNotExist): raise Http404 articles = articles.filter( Q(current_revision__title__icontains=self.query) | Q(current_revision__content__icontains=self.query)) if not permissions.can_moderate( models.URLPath.root().article, self.request.user): articles = articles.active().can_read(self.request.user) return articles.order_by('-current_revision__created')
def get_queryset(self): if not self.query: return models.Article.objects.none().order_by( '-current_revision__created') articles = models.Article.objects path = self.kwargs.get('path', None) if path: try: self.urlpath = models.URLPath.get_by_path(path) article_ids = self.urlpath.get_descendants( include_self=True).values_list('article_id') articles = articles.filter(id__in=article_ids) except (NoRootURL, models.URLPath.DoesNotExist): raise Http404 articles = articles.filter( Q(current_revision__title__icontains=self.query) | Q(current_revision__content__icontains=self.query)) if not permissions.can_moderate(models.URLPath.root().article, self.request.user): articles = articles.active().can_read(self.request.user) return articles.order_by('-current_revision__created')
def can_moderate(self, user): return permissions.can_moderate(self, user)
def clean(self): if not can_moderate(self.article, self.request.user): raise forms.ValidationError( ugettext("User not allowed to moderate this article")) return self.cleaned_data
def clean(self): if not can_moderate(self.article, self.request.user): raise forms.ValidationError("User") return self.cleaned_data