Code cleanup

This commit is contained in:
Iacopo Spalletti 2015-09-26 10:38:57 +02:00
parent 35a0f621b8
commit a1497360b1
8 changed files with 38 additions and 56 deletions

View file

@ -125,8 +125,8 @@ class BlogConfigAdmin(BaseAppHookConfig, TranslatableAdmin):
def get_config_fields(self): def get_config_fields(self):
return ( return (
'app_title', 'paginate_by', 'set_author', 'config.default_published', 'app_title', 'config.paginate_by', 'config.set_author', 'config.default_published',
'config.use_placeholder' 'config.use_placeholder', 'config.use_abstract',
) )
admin.site.register(BlogCategory, BlogCategoryAdmin) admin.site.register(BlogCategory, BlogCategoryAdmin)

View file

@ -56,7 +56,6 @@ class BlogAuthorPostsPlugin(BlogPlugin):
module = _('Blog') module = _('Blog')
name = _('Author Blog Articles') name = _('Author Blog Articles')
model = AuthorEntriesPlugin model = AuthorEntriesPlugin
form = LatestEntriesForm
render_template = 'djangocms_blog/plugins/authors.html' render_template = 'djangocms_blog/plugins/authors.html'
filter_horizontal = ['authors'] filter_horizontal = ['authors']

View file

@ -4,7 +4,6 @@ from __future__ import unicode_literals
import aldryn_apphooks_config.fields import aldryn_apphooks_config.fields
import app_data.fields import app_data.fields
import djangocms_text_ckeditor.fields import djangocms_text_ckeditor.fields
from cms.models import Page from cms.models import Page
from cms.utils.conf import get_languages from cms.utils.conf import get_languages
from django.db import models, migrations from django.db import models, migrations
@ -114,5 +113,10 @@ class Migration(migrations.Migration):
name='blogconfigtranslation', name='blogconfigtranslation',
unique_together=set([('language_code', 'master')]), unique_together=set([('language_code', 'master')]),
), ),
migrations.AlterField(
model_name='post',
name='sites',
field=models.ManyToManyField(to='sites.Site', help_text='Select sites in which to show the post. If none is set it will be visible in all the configured sites.', blank=True, verbose_name='Site(s)'),
),
migrations.RunPython(forwards, backwards) migrations.RunPython(forwards, backwards)
] ]

View file

@ -113,10 +113,9 @@ class Post(ModelMeta, TranslatableModel):
enable_comments = models.BooleanField(verbose_name=_('enable comments on post'), enable_comments = models.BooleanField(verbose_name=_('enable comments on post'),
default=get_setting('ENABLE_COMMENTS')) default=get_setting('ENABLE_COMMENTS'))
sites = models.ManyToManyField('sites.Site', verbose_name=_('Site(s)'), blank=True, sites = models.ManyToManyField('sites.Site', verbose_name=_('Site(s)'), blank=True,
null=True,
help_text=_('Select sites in which to show the post. ' help_text=_('Select sites in which to show the post. '
u'If none is set it will be ' 'If none is set it will be '
u'visible in all the configured sites.')) 'visible in all the configured sites.'))
app_config = AppHookConfigField(BlogConfig, verbose_name=_('app. config')) app_config = AppHookConfigField(BlogConfig, verbose_name=_('app. config'))
translations = TranslatedFields( translations = TranslatedFields(

View file

@ -127,19 +127,6 @@ class BaseTest(BaseTestCase):
cls.category_1.save() cls.category_1.save()
cls.site_2 = Site.objects.create(domain='http://example2.com', name='example 2') cls.site_2 = Site.objects.create(domain='http://example2.com', name='example 2')
def setUp(self):
super(BaseTest, self).setUp()
self.img = self.create_filer_image_object()
def tearDown(self):
Post.objects.all().delete()
super(BaseTest, self).tearDown()
@classmethod
def tearDownClass(cls):
BlogConfig.objects.all().delete()
super(BaseTest, cls).tearDownClass()
def _get_category(self, data, category=None, lang='en'): def _get_category(self, data, category=None, lang='en'):
data = deepcopy(data) data = deepcopy(data)
for k, v in data.items(): for k, v in data.items():
@ -188,7 +175,7 @@ class BaseTest(BaseTestCase):
post1 = self._get_post(post['en'], sites=sites) post1 = self._get_post(post['en'], sites=sites)
post1 = self._get_post(post['it'], post=post1, lang='it') post1 = self._get_post(post['it'], post=post1, lang='it')
post1.publish = post['en']['publish'] post1.publish = post['en']['publish']
post1.main_image = self.img post1.main_image = self.create_filer_image_object()
post1.save() post1.save()
posts.append(post1) posts.append(post1)
return posts return posts

View file

@ -147,7 +147,7 @@ class ModelsTest(BaseTest):
def test_model_attributes(self): def test_model_attributes(self):
post = self._get_post(self._post_data[0]['en']) post = self._get_post(self._post_data[0]['en'])
post = self._get_post(self._post_data[0]['it'], post, 'it') post = self._get_post(self._post_data[0]['it'], post, 'it')
post.main_image = self.img post.main_image = self.create_filer_image_object()
post.save() post.save()
post.set_current_language('en') post.set_current_language('en')
meta_en = post.as_meta() meta_en = post.as_meta()

View file

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals from __future__ import absolute_import, print_function, unicode_literals
from aldryn_apphooks_config.utils import get_app_instance
from django.contrib.auth.models import AnonymousUser from django.contrib.auth.models import AnonymousUser
from django.http import Http404 from django.http import Http404
@ -24,24 +25,25 @@ class ViewTest(BaseTest):
posts = self.get_posts() posts = self.get_posts()
pages = self.get_pages() pages = self.get_pages()
request = self.get_page_request(pages[0], AnonymousUser(), r'/en/blog/', edit=False) request = self.get_request(pages[1], 'en', AnonymousUser())
with smart_override('en'): with smart_override('en'):
view_obj = PostListView() view_obj = PostListView()
view_obj.request = request view_obj.request = request
view_obj.namespace = self.app_config_1.namespace view_obj.namespace, view_obj.config = get_app_instance(request)
view_obj.config = self.app_config_1
self.assertEqual(list(view_obj.get_queryset()), [posts[0]]) self.assertEqual(list(view_obj.get_queryset()), [posts[0]])
request = self.get_page_request(pages[1], self.user, edit=False) request = self.get_page_request(pages[1], self.user, lang='en', edit=False)
view_obj.namespace, view_obj.config = get_app_instance(request)
view_obj.request = request view_obj.request = request
view_obj.kwargs = {} view_obj.kwargs = {}
qs = view_obj.get_queryset() qs = view_obj.get_queryset()
self.assertEqual(qs.count(), 1) self.assertEqual(qs.count(), 1)
self.assertEqual(set(qs), set([posts[0]])) self.assertEqual(set(qs), set([posts[0]]))
request = self.get_page_request(pages[1], self.user, edit=True) request = self.get_page_request(pages[1], self.user, lang='en', edit=True)
view_obj.namespace, view_obj.config = get_app_instance(request)
view_obj.request = request view_obj.request = request
self.assertEqual(set(view_obj.get_queryset()), set([posts[0], posts[1], posts[2]])) self.assertEqual(set(view_obj.get_queryset()), set([posts[0], posts[1], posts[2]]))
@ -58,6 +60,7 @@ class ViewTest(BaseTest):
with smart_override('it'): with smart_override('it'):
request = self.get_page_request(pages[1], self.user, lang='it', edit=True) request = self.get_page_request(pages[1], self.user, lang='it', edit=True)
view_obj.namespace, view_obj.config = get_app_instance(request)
view_obj.request = request view_obj.request = request
view_obj.object_list = view_obj.get_queryset() view_obj.object_list = view_obj.get_queryset()
context = view_obj.get_context_data(object_list=view_obj.object_list) context = view_obj.get_context_data(object_list=view_obj.object_list)
@ -83,10 +86,9 @@ class ViewTest(BaseTest):
with smart_override('fr'): with smart_override('fr'):
view_obj = PostListView() view_obj = PostListView()
request = self.get_page_request(pages[0], self.user, r'/fr/blog/', lang='fr', edit=True) request = self.get_page_request(pages[1], self.user, lang='fr', edit=True)
view_obj.request = request view_obj.request = request
view_obj.namespace = self.app_config_1.namespace view_obj.namespace, view_obj.config = get_app_instance(request)
view_obj.config = self.app_config_1
view_obj.kwargs = {} view_obj.kwargs = {}
view_obj.object_list = view_obj.get_queryset() view_obj.object_list = view_obj.get_queryset()
view_obj.get_context_data(object_list=view_obj.object_list) view_obj.get_context_data(object_list=view_obj.object_list)
@ -96,10 +98,9 @@ class ViewTest(BaseTest):
with override_parler_settings(PARLER_LANGUAGES=PARLER_FALLBACK): with override_parler_settings(PARLER_LANGUAGES=PARLER_FALLBACK):
view_obj = PostListView() view_obj = PostListView()
request = self.get_page_request(pages[0], self.user, r'/fr/blog/', lang='fr', edit=True) request = self.get_page_request(pages[1], self.user, lang='fr', edit=True)
view_obj.request = request view_obj.request = request
view_obj.namespace = self.app_config_1.namespace view_obj.namespace, view_obj.config = get_app_instance(request)
view_obj.config = self.app_config_1
view_obj.kwargs = {} view_obj.kwargs = {}
view_obj.object_list = view_obj.get_queryset() view_obj.object_list = view_obj.get_queryset()
view_obj.get_context_data(object_list=view_obj.object_list) view_obj.get_context_data(object_list=view_obj.object_list)
@ -111,11 +112,10 @@ class ViewTest(BaseTest):
with smart_override('en'): with smart_override('en'):
with switch_language(posts[0], 'en'): with switch_language(posts[0], 'en'):
request = self.get_page_request(pages[0], AnonymousUser(), r'/en/blog/', edit=False) request = self.get_page_request(pages[1], AnonymousUser(), lang='en', edit=False)
view_obj = PostDetailView() view_obj = PostDetailView()
view_obj.request = request view_obj.request = request
view_obj.namespace = self.app_config_1.namespace view_obj.namespace, view_obj.config = get_app_instance(request)
view_obj.config = self.app_config_1
with self.assertRaises(Http404): with self.assertRaises(Http404):
view_obj.kwargs = {'slug': 'not-existing'} view_obj.kwargs = {'slug': 'not-existing'}
@ -128,11 +128,10 @@ class ViewTest(BaseTest):
with smart_override('it'): with smart_override('it'):
with switch_language(posts[0], 'it'): with switch_language(posts[0], 'it'):
request = self.get_page_request(pages[0], AnonymousUser(), r'/it/blog/', lang='it', edit=False) request = self.get_page_request(pages[1], AnonymousUser(), lang='it', edit=False)
view_obj = PostDetailView() view_obj = PostDetailView()
view_obj.request = request view_obj.request = request
view_obj.namespace = self.app_config_1.namespace view_obj.namespace, view_obj.config = get_app_instance(request)
view_obj.config = self.app_config_1
view_obj.kwargs = {'slug': posts[0].slug} view_obj.kwargs = {'slug': posts[0].slug}
post_obj = view_obj.get_object() post_obj = view_obj.get_object()
@ -150,11 +149,10 @@ class ViewTest(BaseTest):
pages = self.get_pages() pages = self.get_pages()
with smart_override('en'): with smart_override('en'):
request = self.get_page_request(pages[0], AnonymousUser(), r'/en/blog/', edit=False) request = self.get_page_request(pages[1], AnonymousUser(), lang='en', edit=False)
view_obj = PostArchiveView() view_obj = PostArchiveView()
view_obj.request = request view_obj.request = request
view_obj.namespace = self.app_config_1.namespace view_obj.namespace, view_obj.config = get_app_instance(request)
view_obj.config = self.app_config_1
view_obj.kwargs = {'year': now().year, 'month': now().month} view_obj.kwargs = {'year': now().year, 'month': now().month}
# One post only, anonymous request # One post only, anonymous request
@ -171,11 +169,10 @@ class ViewTest(BaseTest):
pages = self.get_pages() pages = self.get_pages()
with smart_override('en'): with smart_override('en'):
request = self.get_page_request(pages[0], self.user, r'/en/blog/', edit=True) request = self.get_page_request(pages[1], self.user, lang='en', edit=True)
view_obj = CategoryEntriesView() view_obj = CategoryEntriesView()
view_obj.request = request view_obj.request = request
view_obj.namespace = self.app_config_1.namespace view_obj.namespace, view_obj.config = get_app_instance(request)
view_obj.config = self.app_config_1
view_obj.kwargs = {'category': 'category-1'} view_obj.kwargs = {'category': 'category-1'}
qs = view_obj.get_queryset() qs = view_obj.get_queryset()
self.assertEqual(qs.count(), 3) self.assertEqual(qs.count(), 3)
@ -201,10 +198,9 @@ class ViewTest(BaseTest):
pages = self.get_pages() pages = self.get_pages()
with smart_override('en'): with smart_override('en'):
request = self.get_page_request(pages[1], self.user, edit=True) request = self.get_page_request(pages[1], self.user, lang='en', edit=True)
view_obj = AuthorEntriesView() view_obj = AuthorEntriesView()
view_obj.namespace = self.app_config_1.namespace view_obj.namespace, view_obj.config = get_app_instance(request)
view_obj.config = self.app_config_1
view_obj.request = request view_obj.request = request
view_obj.kwargs = {'username': self.user.get_username()} view_obj.kwargs = {'username': self.user.get_username()}
qs = view_obj.get_queryset() qs = view_obj.get_queryset()
@ -235,11 +231,10 @@ class ViewTest(BaseTest):
posts[1].save() posts[1].save()
with smart_override('en'): with smart_override('en'):
request = self.get_page_request(pages[1], self.user, edit=True) request = self.get_page_request(pages[1], self.user, lang='en', edit=True)
view_obj = TaggedListView() view_obj = TaggedListView()
view_obj.request = request view_obj.request = request
view_obj.namespace = self.app_config_1.namespace view_obj.namespace, view_obj.config = get_app_instance(request)
view_obj.config = self.app_config_1
view_obj.kwargs = {'tag': 'tag-2'} view_obj.kwargs = {'tag': 'tag-2'}
qs = view_obj.get_queryset() qs = view_obj.get_queryset()
self.assertEqual(qs.count(), 2) self.assertEqual(qs.count(), 2)
@ -269,8 +264,7 @@ class ViewTest(BaseTest):
request = self.get_page_request(pages[1], self.user, path=posts[0].get_absolute_url()) request = self.get_page_request(pages[1], self.user, path=posts[0].get_absolute_url())
feed = LatestEntriesFeed() feed = LatestEntriesFeed()
feed.namespace = self.app_config_1.namespace feed.namespace, feed.config = get_app_instance(request)
feed.config = self.app_config_1
self.assertEqual(list(feed.items()), [posts[0]]) self.assertEqual(list(feed.items()), [posts[0]])
self.reload_urlconf() self.reload_urlconf()
xml = feed(request) xml = feed(request)
@ -280,8 +274,7 @@ class ViewTest(BaseTest):
with smart_override('it'): with smart_override('it'):
with switch_language(posts[0], 'it'): with switch_language(posts[0], 'it'):
feed = LatestEntriesFeed() feed = LatestEntriesFeed()
feed.namespace = self.app_config_1.namespace feed.namespace, feed.config = get_app_instance(request)
feed.config = self.app_config_1
self.assertEqual(list(feed.items()), [posts[0]]) self.assertEqual(list(feed.items()), [posts[0]])
request = self.get_page_request(pages[1], self.user, path=posts[0].get_absolute_url()) request = self.get_page_request(pages[1], self.user, path=posts[0].get_absolute_url())
xml = feed(request) xml = feed(request)

View file

@ -2,7 +2,7 @@
envlist = py{26}-django16-cms{30,31},py{27,33,34}-django{16,17}-cms{30,31,32},py{27,33,34}-django{18,19}-cms{31,32},pep8,isort envlist = py{26}-django16-cms{30,31},py{27,33,34}-django{16,17}-cms{30,31,32},py{27,33,34}-django{18,19}-cms{31,32},pep8,isort
[testenv] [testenv]
commands = {env:COMMAND:python} setup.py test commands = {env:COMMAND:python} cms_helper.py test djangocms_blog --no-migrate
deps = deps =
django16: Django>=1.6,<1.7 django16: Django>=1.6,<1.7
django17: Django>=1.7,<1.8 django17: Django>=1.7,<1.8