This commit is contained in:
Iacopo Spalletti 2014-02-23 16:09:27 +01:00
parent d0708d666b
commit 7fff4e90e8
3 changed files with 5 additions and 34 deletions

View file

@ -3,7 +3,7 @@
History
-------
0.1.0 (2013-08-15)
0.1.0 (2014-02-24)
++++++++++++++++++
* First release on PyPI.

View file

@ -1,28 +0,0 @@
# -*- coding: utf-8 -*-
from django.utils.translation import ugettext_lazy as _
from django.db import models
from django.contrib.auth.models import User
class UsersWithPermsManyToManyField(models.ManyToManyField):
def __init__(self, perms, **kwargs):
(super(UsersWithPermsManyToManyField, self)
.__init__(User, limit_choices_to=self.get_limit_choices_to(perms),
**kwargs))
def get_limit_choices_to(self, perms):
return (models.Q(user_permissions__codename__in=perms)
| models.Q(groups__permissions__codename__in=perms)
| models.Q(is_superuser=True))
def formfield(self, **kwargs):
db = kwargs.pop('using', None)
defaults = {
'queryset': (self.rel.to._default_manager.using(db)
.complex_filter(self.rel.limit_choices_to).distinct())
}
defaults.update(kwargs)
return super(UsersWithPermsManyToManyField, self).formfield(**defaults)

View file

@ -16,7 +16,6 @@ from taggit_autosuggest.managers import TaggableManager
from . import settings
from .managers import GenericDateTaggedManager
from .fields import UsersWithPermsManyToManyField
class BlogCategory(TranslatableModel):
@ -159,9 +158,9 @@ class LatestPostsPlugin(CMSPlugin):
class AuthorEntriesPlugin(CMSPlugin):
#authors = models.ManyToManyField(User, verbose_name=_('Authors'))
authors = UsersWithPermsManyToManyField(perms=['add_post'],
verbose_name=_('Authors'))
authors = models.ManyToManyField(User, verbose_name=_('Authors'),
limit_choices_to={'post_set__publish': True}
)
latest_posts = models.IntegerField(_(u'Articles'), default=settings.BLOG_LATEST_POSTS,
help_text=_('The number of author articles to be displayed.'))
@ -178,6 +177,6 @@ class AuthorEntriesPlugin(CMSPlugin):
def get_authors(self):
authors = self.authors.all()
for author in authors:
if author.post_set.filter(publish=True).exists:
if author.post_set.filter(publish=True).exists():
author.count = author.post_set.filter(publish=True).count()
return authors