Update auto_setup

This commit is contained in:
Iacopo Spalletti 2015-10-25 17:02:05 +01:00
parent f029608f0c
commit ba044b34aa
7 changed files with 40 additions and 29 deletions

View file

@ -17,11 +17,16 @@ class BlogApp(AutoCMSAppMixin, CMSConfigApp):
app_name = 'djangocms_blog' app_name = 'djangocms_blog'
app_config = BlogConfig app_config = BlogConfig
menus = [BlogCategoryMenu] menus = [BlogCategoryMenu]
auto_setup = get_setting('AUTO_SETUP') auto_setup = {
auto_app_title = get_setting('AUTO_APP_TITLE') 'enabled': get_setting('AUTO_SETUP'),
auto_home_title = get_setting('AUTO_HOME_TITLE') 'home title': get_setting('AUTO_HOME_TITLE'),
auto_page_title = get_setting('AUTO_BLOG_TITLE') 'page title': get_setting('AUTO_BLOG_TITLE'),
auto_namespace = get_setting('AUTO_NAMESPACE') 'namespace': get_setting('AUTO_NAMESPACE'),
'config_fields': {},
'config_translated_fields': {
'app_title': get_setting('AUTO_APP_TITLE'),
'object_name': get_setting('DEFAULT_OBJECT_NAME')
},
}
apphook_pool.register(BlogApp) apphook_pool.register(BlogApp)
BlogApp.setup() BlogApp.setup()

View file

@ -18,7 +18,9 @@ class BlogConfig(TranslatableModel, AppHookConfig):
""" """
translations = TranslatedFields( translations = TranslatedFields(
app_title=models.CharField(_('application title'), max_length=234), app_title=models.CharField(_('application title'), max_length=234),
object_name=models.CharField(_('object name'), max_length=234, default='Post'), object_name=models.CharField(
_('object name'), max_length=234, default=get_setting('DEFAULT_OBJECT_NAME')
),
) )
def get_app_title(self): def get_app_title(self):

View file

@ -1,2 +0,0 @@
# -*- coding: utf-8 -*-
from django.utils.translation import ugettext_lazy as _

View file

@ -4,6 +4,7 @@ from __future__ import unicode_literals
from django.db import migrations, models from django.db import migrations, models
import django.utils.timezone import django.utils.timezone
import aldryn_apphooks_config.fields import aldryn_apphooks_config.fields
from djangocms_blog.settings import get_setting
class Migration(migrations.Migration): class Migration(migrations.Migration):
@ -16,7 +17,7 @@ class Migration(migrations.Migration):
migrations.AddField( migrations.AddField(
model_name='blogconfigtranslation', model_name='blogconfigtranslation',
name='object_name', name='object_name',
field=models.CharField(verbose_name='object name', default='Post', max_length=234), field=models.CharField(verbose_name='object name', default=get_setting('DEFAULT_OBJECT_NAME'), max_length=234),
), ),
migrations.AlterField( migrations.AlterField(
model_name='authorentriesplugin', model_name='authorentriesplugin',

View file

@ -74,6 +74,7 @@ def get_setting(name):
'BLOG_DEFAULT_PUBLISHED': getattr(settings, 'BLOG_DEFAULT_PUBLISHED', False), 'BLOG_DEFAULT_PUBLISHED': getattr(settings, 'BLOG_DEFAULT_PUBLISHED', False),
'BLOG_AVAILABLE_PERMALINK_STYLES': getattr(settings, 'BLOG_AVAILABLE_PERMALINK_STYLES', PERMALINKS), # NOQA 'BLOG_AVAILABLE_PERMALINK_STYLES': getattr(settings, 'BLOG_AVAILABLE_PERMALINK_STYLES', PERMALINKS), # NOQA
'BLOG_PERMALINK_URLS': getattr(settings, 'BLOG_PERMALINK_URLS', PERMALINKS_URLS), 'BLOG_PERMALINK_URLS': getattr(settings, 'BLOG_PERMALINK_URLS', PERMALINKS_URLS),
'BLOG_DEFAULT_OBJECT_NAME': getattr(settings, 'BLOG_DEFAULT_OBJECT_NAME', 'Article'),
'BLOG_AUTO_SETUP': getattr(settings, 'BLOG_AUTO_SETUP', True), 'BLOG_AUTO_SETUP': getattr(settings, 'BLOG_AUTO_SETUP', True),
'BLOG_AUTO_HOME_TITLE': getattr(settings, 'BLOG_AUTO_HOME_TITLE', 'Home'), 'BLOG_AUTO_HOME_TITLE': getattr(settings, 'BLOG_AUTO_HOME_TITLE', 'Home'),

View file

@ -3,6 +3,7 @@ from south.utils import datetime_utils as datetime
from south.db import db from south.db import db
from south.v2 import SchemaMigration from south.v2 import SchemaMigration
from django.db import models from django.db import models
from djangocms_blog.settings import get_setting
class Migration(SchemaMigration): class Migration(SchemaMigration):
@ -10,7 +11,7 @@ class Migration(SchemaMigration):
def forwards(self, orm): def forwards(self, orm):
# Adding field 'BlogConfigTranslation.object_name' # Adding field 'BlogConfigTranslation.object_name'
db.add_column('djangocms_blog_blogconfig_translation', 'object_name', db.add_column('djangocms_blog_blogconfig_translation', 'object_name',
self.gf('django.db.models.fields.CharField')(default='Post', max_length=234), self.gf('django.db.models.fields.CharField')(default=get_setting('DEFAULT_OBJECT_NAME'), max_length=234),
keep_default=False) keep_default=False)
@ -218,4 +219,4 @@ class Migration(SchemaMigration):
} }
} }
complete_apps = ['djangocms_blog'] complete_apps = ['djangocms_blog']

View file

@ -17,34 +17,37 @@ class SetupTest(BaseTest):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
# Skipping initialization to start with clean database
super(BaseTest, cls).setUpClass() super(BaseTest, cls).setUpClass()
def setUp(self):
super(SetupTest, self).setUp()
from cms.apphook_pool import apphook_pool
delete = [
'djangocms_blog',
'djangocms_blog.cms_app',
'djangocms_blog.cms_apps',
]
for module in delete:
if module in sys.modules:
del sys.modules[module]
BlogConfig.cmsapp = None
apphook_pool.clear()
def test_setup_from_url(self): def test_setup_from_url(self):
# Tests starts with no page and no config # Tests starts with no page and no config
self.assertFalse(Page.objects.exists()) self.assertFalse(Page.objects.exists())
self.assertFalse(BlogConfig.objects.exists()) self.assertFalse(BlogConfig.objects.exists())
# importing admin triggers the auto setup # importing cms_app triggers the auto setup
from djangocms_blog import cms_toolbar # NOQA from djangocms_blog import cms_app # NOQA
# Home and blog, published and draft # Home and blog, published and draft
self.assertEqual(Page.objects.count(), 4) self.assertEqual(Page.objects.count(), 4)
self.assertEqual(BlogConfig.objects.count(), 1) self.assertEqual(BlogConfig.objects.count(), 1)
def setUp(self):
from cms.toolbar_pool import toolbar_pool
from djangocms_blog import cms_toolbar
toolbar_pool.unregister(cms_toolbar.BlogToolbar)
delete = [
'djangocms_blog',
'djangocms_blog.cms_toolbar',
]
for module in delete:
if module in sys.modules:
del sys.modules[module]
def test_setup_filled(self): def test_setup_filled(self):
# Tests starts with no page and no config # Tests starts with no page and no config
@ -66,8 +69,8 @@ class SetupTest(BaseTest):
) )
home.publish(lang) home.publish(lang)
# importing admin triggers the auto setup # importing cms_app triggers the auto setup
from djangocms_blog import cms_toolbar # NOQA from djangocms_blog import cms_app # NOQA
# Home and blog, published and draft # Home and blog, published and draft
self.assertEqual(Page.objects.count(), 4) self.assertEqual(Page.objects.count(), 4)