Fix code style
This commit is contained in:
parent
01869047ae
commit
c6ae227adf
14 changed files with 74 additions and 45 deletions
|
@ -1,6 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import sys
|
||||
from tempfile import mkdtemp
|
||||
|
||||
gettext = lambda s: s
|
||||
|
|
|
@ -21,14 +21,14 @@ class BlogToolbar(CMSToolbar):
|
|||
admin_menu.add_modal_item(_('Add post'), url=url)
|
||||
|
||||
current_post = getattr(self.request, BLOG_CURRENT_POST_IDENTIFIER, None)
|
||||
if current_post and self.request.user.has_perm('djangocms_blog.change_post'): # pragma: no cover
|
||||
if current_post and self.request.user.has_perm('djangocms_blog.change_post'): # pragma: no cover # NOQA
|
||||
admin_menu.add_modal_item(_('Edit Post'), reverse(
|
||||
'admin:djangocms_blog_post_change', args=(current_post.pk,)),
|
||||
active=True)
|
||||
|
||||
def post_template_populate(self):
|
||||
current_post = getattr(self.request, BLOG_CURRENT_POST_IDENTIFIER, None)
|
||||
if current_post and self.request.user.has_perm('djangocms_blog.change_post'): # pragma: no cover
|
||||
if current_post and self.request.user.has_perm('djangocms_blog.change_post'): # pragma: no cover # NOQA
|
||||
# removing page meta menu, if present, to avoid confusion
|
||||
try: # pragma: no cover
|
||||
import djangocms_page_meta # NOQA
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
try:
|
||||
from collections import Counter
|
||||
except ImportError:
|
||||
from .compat import Counter
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import django
|
||||
from django.contrib.sites.models import Site
|
||||
|
@ -10,6 +7,11 @@ from django.db import models
|
|||
from django.utils.timezone import now
|
||||
from parler.managers import TranslatableQuerySet, TranslationManager
|
||||
|
||||
try:
|
||||
from collections import Counter
|
||||
except ImportError:
|
||||
from .compat import Counter
|
||||
|
||||
|
||||
class TaggedFilterItem(object):
|
||||
|
||||
|
@ -34,8 +36,12 @@ class TaggedFilterItem(object):
|
|||
filtro.update(item.tags.all())
|
||||
filtro = set([tag.id for tag in filtro])
|
||||
elif other_model is not None:
|
||||
filtro = 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))
|
||||
filtro = 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)
|
||||
return list(tags)
|
||||
|
@ -144,7 +150,8 @@ class GenericDateTaggedManager(TaggedFilterItem, TranslationManager):
|
|||
|
||||
def get_months(self, queryset=None):
|
||||
"""
|
||||
Get months with aggregate count (how much posts is in the month). Results are ordered by date.
|
||||
Get months with aggregate count (how much posts is in the month).
|
||||
Results are ordered by date.
|
||||
"""
|
||||
if queryset is None:
|
||||
queryset = self.get_queryset()
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from cms.menu_bases import CMSAttachMenu
|
||||
from django.db.models.signals import post_delete, post_save
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import get_language
|
||||
from django.utils.translation import get_language, ugettext_lazy as _
|
||||
from menus.base import Modifier, NavigationNode
|
||||
from menus.menu_pool import menu_pool
|
||||
|
||||
|
|
|
@ -7,8 +7,7 @@ from django.utils import timezone
|
|||
from django.utils.encoding import force_text, python_2_unicode_compatible
|
||||
from django.utils.html import escape, strip_tags
|
||||
from django.utils.text import slugify
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import get_language
|
||||
from django.utils.translation import get_language, ugettext_lazy as _
|
||||
from djangocms_text_ckeditor.fields import HTMLField
|
||||
from filer.fields.image import FilerImageField
|
||||
from meta_mixin.models import ModelMeta
|
||||
|
@ -241,12 +240,15 @@ class BasePostPlugin(CMSPlugin):
|
|||
class LatestPostsPlugin(BasePostPlugin):
|
||||
|
||||
latest_posts = models.IntegerField(_(u'articles'), default=get_setting('LATEST_POSTS'),
|
||||
help_text=_(u'The number of latests articles to be displayed.'))
|
||||
help_text=_(u'The number of latests '
|
||||
u'articles to be displayed.'))
|
||||
tags = TaggableManager(_(u'filter by tag'), blank=True,
|
||||
help_text=_(u'Show only the blog articles tagged with chosen tags.'),
|
||||
related_name='djangocms_blog_latest_post')
|
||||
categories = models.ManyToManyField('djangocms_blog.BlogCategory', blank=True, verbose_name=_(u'filter by category'),
|
||||
help_text=_(u'Show only the blog articles tagged with chosen categories.'))
|
||||
categories = models.ManyToManyField('djangocms_blog.BlogCategory', blank=True,
|
||||
verbose_name=_(u'filter by category'),
|
||||
help_text=_(u'Show only the blog articles tagged '
|
||||
u'with chosen categories.'))
|
||||
|
||||
def __str__(self):
|
||||
return _(u'%s latest articles by tag') % self.latest_posts
|
||||
|
|
|
@ -2,18 +2,29 @@
|
|||
from django.conf.urls import patterns, url
|
||||
|
||||
from .feeds import LatestEntriesFeed, TagFeed
|
||||
from .views import (AuthorEntriesView, CategoryEntriesView, PostArchiveView, PostDetailView,
|
||||
PostListView, TaggedListView)
|
||||
from .views import (
|
||||
AuthorEntriesView, CategoryEntriesView, PostArchiveView, PostDetailView, PostListView,
|
||||
TaggedListView,
|
||||
)
|
||||
|
||||
urlpatterns = patterns(
|
||||
'',
|
||||
url(r'^$', PostListView.as_view(), name='posts-latest'),
|
||||
url(r'^feed/$', LatestEntriesFeed(), name='posts-latest-feed'),
|
||||
url(r'^(?P<year>\d{4})/$', PostArchiveView.as_view(), name='posts-archive'),
|
||||
url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/$', PostArchiveView.as_view(), name='posts-archive'),
|
||||
url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/(?P<slug>\w[-\w]*)/$', PostDetailView.as_view(), name='post-detail'),
|
||||
url(r'^author/(?P<username>[\w\.@+-]+)/$', AuthorEntriesView.as_view(), name='posts-author'),
|
||||
url(r'^category/(?P<category>[\w\.@+-]+)/$', CategoryEntriesView.as_view(), name='posts-category'),
|
||||
url(r'^tag/(?P<tag>[-\w]+)/$', TaggedListView.as_view(), name='posts-tagged'),
|
||||
url(r'^tag/(?P<tag>[-\w]+)/feed/$', TagFeed(), name='posts-tagged-feed'),
|
||||
url(r'^$',
|
||||
PostListView.as_view(), name='posts-latest'),
|
||||
url(r'^feed/$',
|
||||
LatestEntriesFeed(), name='posts-latest-feed'),
|
||||
url(r'^(?P<year>\d{4})/$',
|
||||
PostArchiveView.as_view(), name='posts-archive'),
|
||||
url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/$',
|
||||
PostArchiveView.as_view(), name='posts-archive'),
|
||||
url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/(?P<slug>\w[-\w]*)/$',
|
||||
PostDetailView.as_view(), name='post-detail'),
|
||||
url(r'^author/(?P<username>[\w\.@+-]+)/$',
|
||||
AuthorEntriesView.as_view(), name='posts-author'),
|
||||
url(r'^category/(?P<category>[\w\.@+-]+)/$',
|
||||
CategoryEntriesView.as_view(), name='posts-category'),
|
||||
url(r'^tag/(?P<tag>[-\w]+)/$',
|
||||
TaggedListView.as_view(), name='posts-tagged'),
|
||||
url(r'^tag/(?P<tag>[-\w]+)/feed/$',
|
||||
TagFeed(), name='posts-tagged-feed'),
|
||||
)
|
||||
|
|
|
@ -144,7 +144,9 @@ class CategoryEntriesView(BaseBlogView, ListView):
|
|||
@property
|
||||
def category(self):
|
||||
if not self._category:
|
||||
self._category = BlogCategory.objects.active_translations(get_language(), slug=self.kwargs['category']).latest('pk')
|
||||
self._category = BlogCategory.objects.active_translations(
|
||||
get_language(), slug=self.kwargs['category']
|
||||
).get()
|
||||
return self._category
|
||||
|
||||
def get(self, *args, **kwargs):
|
||||
|
|
11
setup.cfg
11
setup.cfg
|
@ -1,6 +1,5 @@
|
|||
[flake8]
|
||||
exclude = .git,*.egg-info,build,dist,.tox,djangocms_blog/migrations/*,djangocms_blog/south_migrations/*
|
||||
ignore = E501
|
||||
exclude = *.egg-info,.git,.settings,.tox,build,dist,docs,requirements,tmp,*migrations*,*south_migrations*,tests,data
|
||||
max-line-length = 99
|
||||
|
||||
[metadata]
|
||||
|
@ -11,4 +10,10 @@ universal = 1
|
|||
|
||||
[isort]
|
||||
line_length = 99
|
||||
skip = migrations, south_migrations
|
||||
skip = migrations, south_migrations
|
||||
combine_as_imports = true
|
||||
default_section = THIRDPARTY
|
||||
include_trailing_comma = true
|
||||
known_first_party = djangocms_blog
|
||||
multi_line_output = 5
|
||||
not_skip = __init__.py
|
|
@ -2,10 +2,11 @@
|
|||
import copy
|
||||
|
||||
from django.utils.translation import activate
|
||||
from djangocms_blog.views import CategoryEntriesView, PostDetailView
|
||||
from menus.menu_pool import menu_pool
|
||||
from parler.utils.context import switch_language
|
||||
|
||||
from djangocms_blog.views import CategoryEntriesView, PostDetailView
|
||||
|
||||
from . import BaseTest
|
||||
|
||||
|
||||
|
|
|
@ -12,11 +12,12 @@ from django.contrib.sites.models import Site
|
|||
from django.core.urlresolvers import reverse
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import get_language, override
|
||||
from djangocms_blog.models import Post
|
||||
from djangocms_blog.settings import get_setting
|
||||
from djangocms_helper.utils import CMS_30
|
||||
from taggit.models import Tag
|
||||
|
||||
from djangocms_blog.models import Post
|
||||
from djangocms_blog.settings import get_setting
|
||||
|
||||
from . import BaseTest
|
||||
|
||||
|
||||
|
|
|
@ -2,14 +2,12 @@
|
|||
import re
|
||||
|
||||
from cms.api import add_plugin
|
||||
from cms.plugin_rendering import PluginContext, render_placeholder
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.template import RequestContext
|
||||
from django.template.loader import get_template
|
||||
from django.utils.timezone import now
|
||||
from djangocms_blog.models import BlogCategory
|
||||
from taggit.models import Tag
|
||||
|
||||
from djangocms_blog.models import BlogCategory
|
||||
|
||||
from . import BaseTest
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from cms.toolbar.items import ModalItem
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
from djangocms_blog.models import BLOG_CURRENT_POST_IDENTIFIER
|
||||
|
||||
from . import BaseTest
|
||||
|
|
|
@ -2,13 +2,16 @@
|
|||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.http import Http404
|
||||
from django.utils.timezone import now
|
||||
from djangocms_blog.feeds import LatestEntriesFeed, TagFeed
|
||||
from djangocms_blog.sitemaps import BlogSitemap
|
||||
from djangocms_blog.views import (AuthorEntriesView, CategoryEntriesView, PostArchiveView,
|
||||
PostDetailView, PostListView, TaggedListView)
|
||||
from parler.tests.utils import override_parler_settings
|
||||
from parler.utils.conf import add_default_language_settings
|
||||
from parler.utils.context import switch_language, smart_override
|
||||
from parler.utils.context import smart_override, switch_language
|
||||
|
||||
from djangocms_blog.feeds import LatestEntriesFeed, TagFeed
|
||||
from djangocms_blog.sitemaps import BlogSitemap
|
||||
from djangocms_blog.views import (
|
||||
AuthorEntriesView, CategoryEntriesView, PostArchiveView, PostDetailView, PostListView,
|
||||
TaggedListView,
|
||||
)
|
||||
|
||||
from . import BaseTest
|
||||
|
||||
|
|
2
tox.ini
2
tox.ini
|
@ -17,7 +17,7 @@ deps =
|
|||
|
||||
[testenv:isort]
|
||||
deps = isort
|
||||
commands = isort -c -rc djangocms_blog tests
|
||||
commands = isort -c -rc -df djangocms_blog tests
|
||||
skip_install = true
|
||||
|
||||
[testenv:pep8]
|
||||
|
|
Loading…
Reference in a new issue