Minor code refactoring
Improve coverage
This commit is contained in:
parent
e48e92decd
commit
cae4595a99
5 changed files with 89 additions and 14 deletions
|
|
@ -23,7 +23,7 @@ class TaggedFilterItem(object):
|
|||
o con gli stessi tag di un model o un queryset
|
||||
"""
|
||||
tags = self._taglist(other_model, queryset)
|
||||
return self.get_queryset().filter(taglist__in=tags)
|
||||
return self.get_queryset().filter(tags__in=tags).distinct()
|
||||
|
||||
def _taglist(self, other_model=None, queryset=None):
|
||||
"""
|
||||
|
|
@ -31,21 +31,21 @@ class TaggedFilterItem(object):
|
|||
o queryset passati come argomento
|
||||
"""
|
||||
from taggit.models import TaggedItem
|
||||
filtro = None
|
||||
filter = None
|
||||
if queryset is not None:
|
||||
filtro = set()
|
||||
filter = set()
|
||||
for item in queryset.all():
|
||||
filtro.update(item.tags.all())
|
||||
filtro = set([tag.id for tag in filtro])
|
||||
filter.update(item.tags.all())
|
||||
filter = set([tag.id for tag in filter])
|
||||
elif other_model is not None:
|
||||
filtro = set(TaggedItem.objects.filter(
|
||||
filter = set(TaggedItem.objects.filter(
|
||||
content_type__model=other_model.__name__.lower()
|
||||
).values_list('tag_id', flat=True))
|
||||
tags = set(TaggedItem.objects.filter(
|
||||
content_type__model=self.model.__name__.lower()
|
||||
).values_list('tag_id', flat=True))
|
||||
if filtro is not None:
|
||||
tags = tags.intersection(filtro)
|
||||
if filter is not None:
|
||||
tags = tags.intersection(filter)
|
||||
return list(tags)
|
||||
|
||||
def tag_list(self, other_model=None, queryset=None):
|
||||
|
|
|
|||
|
|
@ -242,6 +242,7 @@ class Post(ModelMeta, TranslatableModel):
|
|||
|
||||
@python_2_unicode_compatible
|
||||
class BasePostPlugin(CMSPlugin):
|
||||
app_config = AppHookConfigField(BlogConfig, verbose_name=_('app. config'), blank=True)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
|
@ -257,11 +258,10 @@ class BasePostPlugin(CMSPlugin):
|
|||
return posts
|
||||
|
||||
def __str__(self):
|
||||
return force_text(self.latest_posts)
|
||||
return _('generic blog plugin')
|
||||
|
||||
|
||||
class LatestPostsPlugin(BasePostPlugin):
|
||||
app_config = AppHookConfigField(BlogConfig, verbose_name=_('app. config'), blank=True)
|
||||
latest_posts = models.IntegerField(_('articles'), default=get_setting('LATEST_POSTS'),
|
||||
help_text=_('The number of latests '
|
||||
u'articles to be displayed.'))
|
||||
|
|
@ -290,7 +290,6 @@ class LatestPostsPlugin(BasePostPlugin):
|
|||
|
||||
|
||||
class AuthorEntriesPlugin(BasePostPlugin):
|
||||
app_config = AppHookConfigField(BlogConfig, verbose_name=_('app. config'), blank=True)
|
||||
authors = models.ManyToManyField(
|
||||
dj_settings.AUTH_USER_MODEL, verbose_name=_('authors'),
|
||||
limit_choices_to={'djangocms_blog_post_author__publish': True}
|
||||
|
|
@ -324,7 +323,6 @@ class AuthorEntriesPlugin(BasePostPlugin):
|
|||
|
||||
|
||||
class GenericBlogPlugin(BasePostPlugin):
|
||||
app_config = AppHookConfigField(BlogConfig, verbose_name=_('app. config'), blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return _('generic blog plugin')
|
||||
class Meta:
|
||||
abstract = False
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import os.path
|
|||
|
||||
from aldryn_apphooks_config.mixins import AppConfigMixin
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import get_language
|
||||
from django.views.generic import DetailView, ListView
|
||||
|
|
@ -18,6 +20,19 @@ User = get_user_model()
|
|||
|
||||
class BaseBlogView(AppConfigMixin, ViewUrlMixin):
|
||||
|
||||
def get_view_url(self):
|
||||
if not self.view_url_name:
|
||||
raise ImproperlyConfigured(
|
||||
'Missing `view_url_name` attribute on {0}'.format(self.__class__.__name__)
|
||||
)
|
||||
|
||||
return reverse(
|
||||
self.view_url_name,
|
||||
args=self.args,
|
||||
kwargs=self.kwargs,
|
||||
current_app=self.namespace
|
||||
)
|
||||
|
||||
def get_queryset(self):
|
||||
language = get_language()
|
||||
queryset = self.model._default_manager.namespace(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue