diff --git a/HISTORY.rst b/HISTORY.rst index 7bf6f23..12aa136 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,7 +3,7 @@ History ------- -0.1.0 (2013-08-15) +0.1.0 (2014-02-24) ++++++++++++++++++ * First release on PyPI. \ No newline at end of file diff --git a/djangocms_blog/fields.py b/djangocms_blog/fields.py deleted file mode 100644 index 09095ee..0000000 --- a/djangocms_blog/fields.py +++ /dev/null @@ -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) diff --git a/djangocms_blog/models.py b/djangocms_blog/models.py index e691fba..1fbed59 100644 --- a/djangocms_blog/models.py +++ b/djangocms_blog/models.py @@ -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