Cleanup
This commit is contained in:
parent
d0708d666b
commit
7fff4e90e8
3 changed files with 5 additions and 34 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
History
|
History
|
||||||
-------
|
-------
|
||||||
|
|
||||||
0.1.0 (2013-08-15)
|
0.1.0 (2014-02-24)
|
||||||
++++++++++++++++++
|
++++++++++++++++++
|
||||||
|
|
||||||
* First release on PyPI.
|
* First release on PyPI.
|
||||||
|
|
@ -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)
|
|
||||||
|
|
@ -16,7 +16,6 @@ from taggit_autosuggest.managers import TaggableManager
|
||||||
|
|
||||||
from . import settings
|
from . import settings
|
||||||
from .managers import GenericDateTaggedManager
|
from .managers import GenericDateTaggedManager
|
||||||
from .fields import UsersWithPermsManyToManyField
|
|
||||||
|
|
||||||
|
|
||||||
class BlogCategory(TranslatableModel):
|
class BlogCategory(TranslatableModel):
|
||||||
|
|
@ -159,9 +158,9 @@ class LatestPostsPlugin(CMSPlugin):
|
||||||
|
|
||||||
|
|
||||||
class AuthorEntriesPlugin(CMSPlugin):
|
class AuthorEntriesPlugin(CMSPlugin):
|
||||||
#authors = models.ManyToManyField(User, verbose_name=_('Authors'))
|
authors = models.ManyToManyField(User, verbose_name=_('Authors'),
|
||||||
authors = UsersWithPermsManyToManyField(perms=['add_post'],
|
limit_choices_to={'post_set__publish': True}
|
||||||
verbose_name=_('Authors'))
|
)
|
||||||
latest_posts = models.IntegerField(_(u'Articles'), default=settings.BLOG_LATEST_POSTS,
|
latest_posts = models.IntegerField(_(u'Articles'), default=settings.BLOG_LATEST_POSTS,
|
||||||
help_text=_('The number of author articles to be displayed.'))
|
help_text=_('The number of author articles to be displayed.'))
|
||||||
|
|
||||||
|
|
@ -178,6 +177,6 @@ class AuthorEntriesPlugin(CMSPlugin):
|
||||||
def get_authors(self):
|
def get_authors(self):
|
||||||
authors = self.authors.all()
|
authors = self.authors.all()
|
||||||
for author in authors:
|
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()
|
author.count = author.post_set.filter(publish=True).count()
|
||||||
return authors
|
return authors
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue