Cleanup code
This commit is contained in:
parent
7e2a7a5387
commit
8657190c87
14 changed files with 57 additions and 65 deletions
|
@ -2,14 +2,14 @@
|
|||
from copy import deepcopy
|
||||
|
||||
from admin_enhancer.admin import EnhancedModelAdminMixin
|
||||
from cms.admin.placeholderadmin import PlaceholderAdminMixin, FrontendEditableAdminMixin
|
||||
from cms.admin.placeholderadmin import FrontendEditableAdminMixin, PlaceholderAdminMixin
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth import get_user_model
|
||||
from parler.admin import TranslatableAdmin
|
||||
|
||||
from .models import Post, BlogCategory
|
||||
from .models import BlogCategory, Post
|
||||
from .settings import get_setting
|
||||
|
||||
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from cms.models.pluginmodel import CMSPlugin
|
||||
from cms.plugin_base import CMSPluginBase
|
||||
from cms.plugin_pool import plugin_pool
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from .models import AuthorEntriesPlugin, LatestPostsPlugin, Post, BlogCategory
|
||||
from .forms import LatestEntriesForm
|
||||
from .models import AuthorEntriesPlugin, BlogCategory, LatestPostsPlugin, Post
|
||||
from .settings import get_setting
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ from cms.toolbar_pool import toolbar_pool
|
|||
from django.core.urlresolvers import reverse
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
from .models import BLOG_CURRENT_POST_IDENTIFIER
|
||||
|
||||
|
||||
|
@ -32,7 +31,7 @@ class BlogToolbar(CMSToolbar):
|
|||
if current_post and self.request.user.has_perm('djangocms_blog.change_post'): # pragma: no cover
|
||||
# removing page meta menu, if present, to avoid confusion
|
||||
try: # pragma: no cover
|
||||
import djangocms_page_meta
|
||||
import djangocms_page_meta # NOQA
|
||||
menu = self.request.toolbar.get_or_create_menu('page')
|
||||
pagemeta = menu.get_or_create_menu('pagemeta', 'meta')
|
||||
menu.remove_item(pagemeta)
|
||||
|
@ -40,7 +39,7 @@ class BlogToolbar(CMSToolbar):
|
|||
pass
|
||||
# removing page tags menu, if present, to avoid confusion
|
||||
try: # pragma: no cover
|
||||
import djangocms_page_tags
|
||||
import djangocms_page_tags # NOQA
|
||||
menu = self.request.toolbar.get_or_create_menu('page')
|
||||
pagetags = menu.get_or_create_menu('pagetags', 'tags')
|
||||
menu.remove_item(pagetags)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from operator import itemgetter
|
||||
from heapq import nlargest
|
||||
from itertools import repeat, ifilter
|
||||
from itertools import ifilter, repeat
|
||||
from operator import itemgetter
|
||||
|
||||
|
||||
class Counter(dict):
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import django
|
||||
from django.contrib.sites.models import Site
|
||||
from django.db.models import Q
|
||||
|
||||
try:
|
||||
from collections import Counter
|
||||
except ImportError:
|
||||
from .compat import Counter
|
||||
|
||||
import django
|
||||
from django.contrib.sites.models import Site
|
||||
from django.db import models
|
||||
from django.utils.timezone import now
|
||||
from parler.managers import TranslationManager, TranslatableQuerySet
|
||||
from parler.managers import TranslatableQuerySet, TranslationManager
|
||||
|
||||
|
||||
class TaggedFilterItem(object):
|
||||
|
@ -78,7 +76,8 @@ class GenericDateQuerySet(TranslatableQuerySet):
|
|||
publish_field = 'publish'
|
||||
|
||||
def on_site(self):
|
||||
return self.filter(Q(sites__isnull=True) | Q(sites=Site.objects.get_current().pk))
|
||||
return self.filter(models.Q(sites__isnull=True) |
|
||||
models.Q(sites=Site.objects.get_current().pk))
|
||||
|
||||
def published(self):
|
||||
queryset = self.published_future()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from cms.models import PlaceholderField, CMSPlugin
|
||||
from cms.models import CMSPlugin, PlaceholderField
|
||||
from cmsplugin_filer_image.models import ThumbnailOption
|
||||
from django.conf import settings as dj_settings
|
||||
from django.contrib.sites.models import Site
|
||||
|
@ -7,18 +7,19 @@ from django.core.urlresolvers import reverse
|
|||
from django.db import models
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import force_text, python_2_unicode_compatible
|
||||
from django.utils.html import strip_tags, escape
|
||||
from django.utils.html import escape, strip_tags
|
||||
from django.utils.text import slugify
|
||||
from django.utils.translation import ugettext_lazy as _, get_language
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import get_language
|
||||
from djangocms_text_ckeditor.fields import HTMLField
|
||||
from filer.fields.image import FilerImageField
|
||||
from meta_mixin.models import ModelMeta
|
||||
from parler.models import TranslatableModel, TranslatedFields
|
||||
from parler.managers import TranslationManager
|
||||
from parler.models import TranslatableModel, TranslatedFields
|
||||
from taggit_autosuggest.managers import TaggableManager
|
||||
|
||||
from .settings import get_setting
|
||||
from .managers import GenericDateTaggedManager
|
||||
from .settings import get_setting
|
||||
|
||||
BLOG_CURRENT_POST_IDENTIFIER = 'djangocms_post_current'
|
||||
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from django.conf.urls import patterns, url
|
||||
|
||||
from .views import (PostListView, PostDetailView, TaggedListView,
|
||||
AuthorEntriesView, PostArchiveView, CategoryEntriesView)
|
||||
from .feeds import LatestEntriesFeed, TagFeed
|
||||
|
||||
from .views import (AuthorEntriesView, CategoryEntriesView, PostArchiveView, PostDetailView,
|
||||
PostListView, TaggedListView)
|
||||
|
||||
urlpatterns = patterns(
|
||||
'',
|
||||
|
|
|
@ -3,11 +3,10 @@ from django.contrib.auth import get_user_model
|
|||
from django.core.urlresolvers import resolve
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import get_language
|
||||
from django.views.generic import ListView, DetailView
|
||||
from django.views.generic import DetailView, ListView
|
||||
from parler.views import TranslatableSlugMixin, ViewUrlMixin
|
||||
|
||||
from parler.views import ViewUrlMixin, TranslatableSlugMixin
|
||||
|
||||
from .models import Post, BlogCategory, BLOG_CURRENT_POST_IDENTIFIER
|
||||
from .models import BLOG_CURRENT_POST_IDENTIFIER, BlogCategory, Post
|
||||
from .settings import get_setting
|
||||
|
||||
User = get_user_model()
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from copy import deepcopy
|
||||
|
||||
import parler
|
||||
from cms.api import add_plugin
|
||||
from cms.utils.copy_plugins import copy_plugins_to
|
||||
from cms.utils.plugins import downcast_plugins
|
||||
from copy import deepcopy
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.contrib.messages.middleware import MessageMiddleware
|
||||
|
@ -10,15 +12,13 @@ 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
|
||||
import parler
|
||||
from taggit.models import Tag
|
||||
|
||||
from djangocms_blog.models import Post
|
||||
from djangocms_blog.settings import get_setting
|
||||
from taggit.models import Tag
|
||||
|
||||
from djangocms_helper.utils import CMS_30
|
||||
|
||||
from . import BaseTest
|
||||
from djangocms_helper.utils import CMS_30
|
||||
|
||||
|
||||
class AdminTest(BaseTest):
|
||||
|
@ -199,7 +199,7 @@ class ModelsTest(BaseTest):
|
|||
self.assertEqual(len(Post.objects.available()), 1)
|
||||
|
||||
# If post is published but publishing date is in the future
|
||||
post2.date_published = now().replace(year=now().year+1, month=now().month, day=1)
|
||||
post2.date_published = now().replace(year=now().year + 1, month=now().month, day=1)
|
||||
post2.publish = True
|
||||
post2.save()
|
||||
self.assertEqual(len(Post.objects.available()), 2)
|
||||
|
@ -207,15 +207,15 @@ class ModelsTest(BaseTest):
|
|||
self.assertEqual(len(Post.objects.archived()), 0)
|
||||
|
||||
# If post is published but end publishing date is in the past
|
||||
post2.date_published = now().replace(year=now().year-2, month=now().month, day=1)
|
||||
post2.date_published_end = now().replace(year=now().year-1, month=now().month, day=1)
|
||||
post2.date_published = now().replace(year=now().year - 2, month=now().month, day=1)
|
||||
post2.date_published_end = now().replace(year=now().year - 1, month=now().month, day=1)
|
||||
post2.save()
|
||||
self.assertEqual(len(Post.objects.available()), 2)
|
||||
self.assertEqual(len(Post.objects.published()), 1)
|
||||
self.assertEqual(len(Post.objects.archived()), 1)
|
||||
|
||||
# counting with language fallback enabled
|
||||
post = self._get_post(self.data['it'][0], post1, 'it')
|
||||
self._get_post(self.data['it'][0], post1, 'it')
|
||||
self.assertEqual(len(Post.objects.filter_by_language('it')), 2)
|
||||
|
||||
# No fallback
|
||||
|
@ -264,7 +264,7 @@ class ModelsTest(BaseTest):
|
|||
|
||||
def test_plugin_latest(self):
|
||||
post1 = self._get_post(self.data['en'][0])
|
||||
post2 = self._get_post(self.data['en'][1])
|
||||
self._get_post(self.data['en'][1])
|
||||
post1.tags.add('tag 1')
|
||||
post1.save()
|
||||
request = self.get_page_request('/', AnonymousUser(), r'/en/blog/', edit=False)
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
|
||||
from cms.api import add_plugin
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.template import RequestContext
|
||||
from django.utils.timezone import now
|
||||
from djangocms_blog.models import BlogCategory
|
||||
from taggit.models import Tag
|
||||
|
||||
from . import BaseTest
|
||||
from djangocms_blog.models import BlogCategory
|
||||
|
||||
|
||||
class PluginTest(BaseTest):
|
||||
|
@ -33,7 +34,6 @@ class PluginTest(BaseTest):
|
|||
self.assertTrue(rendered.find('<article id="post-first-post"') > -1)
|
||||
self.assertTrue(rendered.find(post1.get_absolute_url()) > -1)
|
||||
|
||||
|
||||
category_2 = BlogCategory.objects.create(name=u'category 2')
|
||||
category_2.set_current_language('it', initialize=True)
|
||||
category_2.name = u'categoria 2'
|
||||
|
|
|
@ -3,7 +3,6 @@ from cms.toolbar.items import ModalItem
|
|||
from django.core.urlresolvers import reverse
|
||||
from djangocms_blog.models import BLOG_CURRENT_POST_IDENTIFIER
|
||||
|
||||
|
||||
from . import BaseTest
|
||||
|
||||
|
||||
|
@ -24,4 +23,3 @@ class ToolbarTest(BaseTest):
|
|||
self.assertEqual(len(blog_menu.find_items(ModalItem, url=reverse('admin:djangocms_blog_post_changelist'))), 1)
|
||||
self.assertEqual(len(blog_menu.find_items(ModalItem, url=reverse('admin:djangocms_blog_post_add'))), 1)
|
||||
self.assertEqual(len(blog_menu.find_items(ModalItem, url=reverse('admin:djangocms_blog_post_change', args=(post.pk,)))), 1)
|
||||
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from django.utils.translation import ugettext_lazy as _
|
|
@ -1,28 +1,28 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from cms.utils.conf import get_cms_setting
|
||||
from django.conf import settings
|
||||
from django.conf.urls import patterns, include, url
|
||||
from django.contrib import admin
|
||||
from django.conf.urls import include, patterns, url
|
||||
from django.conf.urls.i18n import i18n_patterns
|
||||
|
||||
|
||||
from django.contrib import admin
|
||||
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
||||
|
||||
admin.autodiscover()
|
||||
|
||||
urlpatterns = patterns('',
|
||||
#(r'', include('django.contrib.staticfiles.urls')),
|
||||
urlpatterns = patterns(
|
||||
'',
|
||||
url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
|
||||
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
|
||||
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
|
||||
url(r'^media/cms/(?P<path>.*)$', 'django.views.static.serve',
|
||||
{'document_root': get_cms_setting('MEDIA_ROOT'), 'show_indexes': True}),
|
||||
{'document_root': get_cms_setting('MEDIA_ROOT'), 'show_indexes': True}),
|
||||
url(r'^jsi18n/(?P<packages>\S+?)/$', 'django.views.i18n.javascript_catalog'),
|
||||
url(r'^taggit_autosuggest/', include('taggit_autosuggest.urls')),
|
||||
)
|
||||
|
||||
urlpatterns += staticfiles_urlpatterns()
|
||||
|
||||
urlpatterns += i18n_patterns('',
|
||||
urlpatterns += i18n_patterns(
|
||||
'',
|
||||
url(r'^admin/', include(admin.site.urls)),
|
||||
url(r'^blog/', include('djangocms_blog.urls', namespace='djangocms_blog')),
|
||||
url(r'^', include('cms.urls')),
|
||||
)
|
||||
)
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.http import Http404
|
||||
from django.utils.translation import activate
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import activate
|
||||
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
|
||||
from djangocms_blog.feeds import LatestEntriesFeed, TagFeed
|
||||
from djangocms_blog.sitemaps import BlogSitemap
|
||||
from djangocms_blog.views import (PostListView, PostDetailView,
|
||||
PostArchiveView, CategoryEntriesView,
|
||||
AuthorEntriesView, TaggedListView)
|
||||
|
||||
from . import BaseTest
|
||||
|
||||
|
@ -68,7 +67,7 @@ class ViewTest(BaseTest):
|
|||
1: (
|
||||
{'code': 'en'},
|
||||
{'code': 'it'},
|
||||
{'code': 'fr', 'hide_untranslated': True,},
|
||||
{'code': 'fr', 'hide_untranslated': True},
|
||||
),
|
||||
'default': {
|
||||
'fallback': 'en',
|
||||
|
@ -82,7 +81,7 @@ class ViewTest(BaseTest):
|
|||
view_obj.request = request
|
||||
view_obj.kwargs = {}
|
||||
view_obj.object_list = view_obj.get_queryset()
|
||||
context = view_obj.get_context_data(object_list=view_obj.object_list)
|
||||
view_obj.get_context_data(object_list=view_obj.object_list)
|
||||
self.assertEqual(view_obj.get_queryset().count(), 2)
|
||||
|
||||
PARLER_FALLBACK = add_default_language_settings(PARLER_FALLBACK)
|
||||
|
@ -94,7 +93,7 @@ class ViewTest(BaseTest):
|
|||
view_obj.request = request
|
||||
view_obj.kwargs = {}
|
||||
view_obj.object_list = view_obj.get_queryset()
|
||||
context = view_obj.get_context_data(object_list=view_obj.object_list)
|
||||
view_obj.get_context_data(object_list=view_obj.object_list)
|
||||
self.assertEqual(view_obj.get_queryset().count(), 0)
|
||||
|
||||
def test_post_detail_view(self):
|
||||
|
@ -147,7 +146,7 @@ class ViewTest(BaseTest):
|
|||
view_obj.object_list = qs
|
||||
context = view_obj.get_context_data(object_list=view_obj.object_list)
|
||||
self.assertEqual(context['archive_date'].date(), now().replace(year=now().year, month=now().month, day=1).date())
|
||||
|
||||
|
||||
def test_category_entries_view(self):
|
||||
page1, page2 = self.get_pages()
|
||||
post1, post2 = self.get_posts()
|
||||
|
@ -247,7 +246,7 @@ class ViewTest(BaseTest):
|
|||
|
||||
feed = TagFeed()
|
||||
self.assertEqual(list(feed.items('tag-2')), [post1])
|
||||
|
||||
|
||||
def test_sitemap(self):
|
||||
post1, post2 = self.get_posts()
|
||||
post1.tags.add('tag 1', 'tag 2', 'tag 3', 'tag 4')
|
||||
|
@ -256,7 +255,7 @@ class ViewTest(BaseTest):
|
|||
post2.publish = True
|
||||
post2.save()
|
||||
post1.set_current_language('en')
|
||||
|
||||
|
||||
sitemap = BlogSitemap()
|
||||
self.assertEqual(sitemap.items().count(), 2)
|
||||
for item in sitemap.items():
|
||||
|
|
Loading…
Reference in a new issue