Commit 096e1493 by Bridger Maxwell

Merge branch 'master' of github.com:benjaoming/django-wiki

parents af0b2a6c d5d90a4f
...@@ -47,7 +47,7 @@ class ArticleFkQuerySetMixin(): ...@@ -47,7 +47,7 @@ class ArticleFkQuerySetMixin():
def can_read(self, user): def can_read(self, user):
"""Filter objects so only the ones with a user's reading access """Filter objects so only the ones with a user's reading access
are included""" are included"""
if user.has_perm('wiki.moderator'): if user.has_perm('wiki.moderate'):
return self return self
if user.is_anonymous(): if user.is_anonymous():
q = self.filter(article__other_read=True) q = self.filter(article__other_read=True)
...@@ -61,7 +61,7 @@ class ArticleFkQuerySetMixin(): ...@@ -61,7 +61,7 @@ class ArticleFkQuerySetMixin():
def can_write(self, user): def can_write(self, user):
"""Filter objects so only the ones with a user's writing access """Filter objects so only the ones with a user's writing access
are included""" are included"""
if user.has_perm('wiki.moderator'): if user.has_perm('wiki.moderate'):
return self return self
if user.is_anonymous(): if user.is_anonymous():
q = self.filter(article__other_write=True) q = self.filter(article__other_write=True)
......
...@@ -65,7 +65,7 @@ class Article(models.Model): ...@@ -65,7 +65,7 @@ class Article(models.Model):
def can_write(self, user=None): def can_write(self, user=None):
# Deny writing access to deleted articles if user has no delete access # Deny writing access to deleted articles if user has no delete access
if self.current_revision and self.current_revision.deleted and not self.can_delete(user): if self.current_revision and self.current_revision.deleted and not self.can_moderate(user):
return False return False
# Check access for other users... # Check access for other users...
if user.is_anonymous() and not settings.ANONYMOUS_WRITE: if user.is_anonymous() and not settings.ANONYMOUS_WRITE:
...@@ -96,11 +96,15 @@ class Article(models.Model): ...@@ -96,11 +96,15 @@ class Article(models.Model):
for descendant in obj.content_object.get_descendants(): for descendant in obj.content_object.get_descendants():
yield descendant yield descendant
def get_children(self, max_num=None, **kwargs): def get_children(self, max_num=None, user_can_read=None, **kwargs):
"""NB! This generator is expensive, so use it with care!!""" """NB! This generator is expensive, so use it with care!!"""
cnt = 0 cnt = 0
for obj in self.articleforobject_set.filter(is_mptt=True): for obj in self.articleforobject_set.filter(is_mptt=True):
for child in obj.content_object.get_children().filter(**kwargs).order_by('articles__article__current_revision__title'): if user_can_read:
objects = obj.content_object.get_children().filter(**kwargs).can_read(user_can_read)
else:
objects = obj.content_object.get_children().filter(**kwargs)
for child in objects.order_by('articles__article__current_revision__title'):
cnt += 1 cnt += 1
if max_num and cnt > max_num: return if max_num and cnt > max_num: return
yield child yield child
...@@ -187,6 +191,9 @@ class Article(models.Model): ...@@ -187,6 +191,9 @@ class Article(models.Model):
class ArticleForObject(models.Model): class ArticleForObject(models.Model):
objects = managers.ArticleFkManager()
article = models.ForeignKey('Article', on_delete=models.CASCADE) article = models.ForeignKey('Article', on_delete=models.CASCADE)
# Same as django.contrib.comments # Same as django.contrib.comments
content_type = models.ForeignKey(ContentType, content_type = models.ForeignKey(ContentType,
......
...@@ -14,7 +14,8 @@ class ArticleMixin(TemplateResponseMixin): ...@@ -14,7 +14,8 @@ class ArticleMixin(TemplateResponseMixin):
self.children_slice = [] self.children_slice = []
if settings.SHOW_MAX_CHILDREN > 0: if settings.SHOW_MAX_CHILDREN > 0:
for child in self.article.get_children(max_num=settings.SHOW_MAX_CHILDREN+1, for child in self.article.get_children(max_num=settings.SHOW_MAX_CHILDREN+1,
articles__article__current_revision__deleted=False): articles__article__current_revision__deleted=False,
user_can_read=request.user):
self.children_slice.append(child) self.children_slice.append(child)
return super(ArticleMixin, self).dispatch(request, *args, **kwargs) return super(ArticleMixin, self).dispatch(request, *args, **kwargs)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment