Add organization private pages

This commit is contained in:
cuom1999 2020-12-27 23:45:58 -06:00
parent 4c3441b197
commit 4502dbf6b9
14 changed files with 369 additions and 156 deletions

View file

@ -30,8 +30,15 @@ class PostList(ListView):
orphans=orphans, allow_empty_first_page=allow_empty_first_page, **kwargs)
def get_queryset(self):
return (BlogPost.objects.filter(visible=True, publish_on__lte=timezone.now()).order_by('-sticky', '-publish_on')
.prefetch_related('authors__user'))
queryset = BlogPost.objects.filter(visible=True, publish_on__lte=timezone.now()) \
.order_by('-sticky', '-publish_on') \
.prefetch_related('authors__user', 'organizations')
if not self.request.user.has_perm('judge.edit_all_post'):
filter = Q(is_organization_private=False)
if self.request.user.is_authenticated:
filter |= Q(organizations__in=self.request.profile.organizations.all())
queryset = queryset.filter(filter)
return queryset
def get_context_data(self, **kwargs):
context = super(PostList, self).get_context_data(**kwargs)
@ -107,7 +114,7 @@ class PostView(TitleMixin, CommentedDetailView):
model = BlogPost
pk_url_kwarg = 'id'
context_object_name = 'post'
template_name = 'blog/content.html'
template_name = 'blog/blog.html'
def get_title(self):
return self.object.title