Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix inheritance #2731

Merged
merged 10 commits into from

3 participants

@daegun

see pr #2615

@daegun daegun referenced this pull request
Closed

Inheritance fix #2615

@daegun daegun closed this
@daegun daegun deleted the daegun:fixInheritance branch
@coveralls

Coverage Status

Coverage increased (+0.0%) when pulling 406229d on daegun:fixInheritance into 41dea10 on divio:develop.

@digi604
Collaborator

was this closed accidentally?

@daegun
@daegun

Actually I'm not sure why this one is closed. I don't remember closing it.

@digi604
Collaborator

can you reopen it?

@daegun daegun restored the daegun:fixInheritance branch
@daegun daegun reopened this
@daegun

Sorry about that. A little too quick on branch cleanup.

@daegun

Also, I couldn't find a good way to test the default value for creating pages so the only test I have in there checks to see if INHERIT is in the template list or not depending on the toggle.

@digi604 digi604 commented on the diff
cms/tests/settings.py
@@ -27,3 +28,22 @@ def test_invalid_language_code(self):
ImproperlyConfigured,
get_cms_setting, 'LANGUAGES'
)
+
+ def test_create_page_with_inheritance_override(self):
+ with SettingsOverride(CMS_TEMPLATE_INHERITANCE=True):
+ for template in get_cms_setting('TEMPLATES'):
+ if (template[0] == constants.TEMPLATE_INHERITANCE_MAGIC):
+ return
@digi604 Collaborator
digi604 added a note

not sure this test works as intended because of the return. use self.assert... something here.

@daegun
daegun added a note
@digi604 Collaborator
digi604 added a note

you can do a self.assertTrue(constants.TEMPLATE_INHERITANCE_MAGIC in get_cms_setting('TEMPLATES'))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@digi604 digi604 commented on the diff
cms/tests/settings.py
((4 lines not shown))
+
+ def test_create_page_with_inheritance_override(self):
+ with SettingsOverride(CMS_TEMPLATE_INHERITANCE=True):
+ for template in get_cms_setting('TEMPLATES'):
+ if (template[0] == constants.TEMPLATE_INHERITANCE_MAGIC):
+ return
+ self.assertRaises(
+ ImproperlyConfigured,
+ get_cms_setting, 'TEMPLATES'
+ )
+
+ def test_create_page_without_inheritance_override(self):
+ with SettingsOverride(CMS_TEMPLATE_INHERITANCE=False):
+ for template in get_cms_setting('TEMPLATES'):
+ if (template[0] == constants.TEMPLATE_INHERITANCE_MAGIC):
+ self.assertRaises(
@digi604 Collaborator
digi604 added a note

same here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@coveralls

Coverage Status

Coverage increased (+0.0%) when pulling 406229d on daegun:fixInheritance into 41dea10 on divio:develop.

@daegun
@daegun

after looking over the tests, it would be best to leave them as they are. my guess that 'assert INHERIT in x for x in cms.settings' was wrong, and a simple 'self.assertTrue(constants.TEMPLATE_INHERITANCE_MAGIC in get_cms_setting('TEMPLATES'))' doesn't work because get_cms_setting('TEMPLATES') returns a lists of templates within a tuple (ie. [('col_two.html', 'two columns'), ('col_three.html', 'three columns'), ('nav_playground.html', 'navigation examples'), ('simple.html', 'simple'), ('static.html', 'static placeholders')]).

there is an assertion in both tests, as one fails when the loop is completed, and the other stops running the test when constants.TEMPLATE_INHERITANCE_MAGIC is found in the code. I've tested the negative cases and the tests work as written.

@digi604 digi604 merged commit 57bdab7 into divio:develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 10, 2014
  1. @daegun

    Merge pull request #1 from divio/develop

    daegun authored
    updating fork from master
  2. @daegun
  3. @daegun
Commits on Feb 11, 2014
  1. @daegun
  2. @daegun

    Merge pull request #2 from daegun/removeSpaceless

    daegun authored
    removing the spaceless tags as it mucks with html output
  3. @daegun

    Merge pull request #3 from divio/develop

    daegun authored
    merging main fork into personal fork
Commits on Feb 26, 2014
  1. @daegun
  2. @daegun

    Merge pull request #5 from daegun/test

    daegun authored
    merging main develop branch
  3. @daegun
  4. @daegun

    adding tests

    daegun authored
This page is out of date. Refresh to see the latest.
View
3  cms/models/pagemodel.py
@@ -38,6 +38,7 @@ class Page(with_metaclass(PageMetaClass, MPTTModel)):
(1, _('for logged in users only')),
(2, _('for anonymous users only')),
)
+ TEMPLATE_DEFAULT = TEMPLATE_INHERITANCE_MAGIC if get_cms_setting('TEMPLATE_INHERITANCE') else get_cms_setting('TEMPLATES')[0][0]
X_FRAME_OPTIONS_INHERIT = 0
X_FRAME_OPTIONS_DENY = 1
@@ -65,7 +66,7 @@ class Page(with_metaclass(PageMetaClass, MPTTModel)):
navigation_extenders = models.CharField(_("attached menu"), max_length=80, db_index=True, blank=True, null=True)
template = models.CharField(_("template"), max_length=100, choices=template_choices,
help_text=_('The template used to render the content.'),
- default=TEMPLATE_INHERITANCE_MAGIC)
+ default=TEMPLATE_DEFAULT)
site = models.ForeignKey(Site, help_text=_('The site the page is accessible at.'), verbose_name=_("site"),
related_name='djangocms_pages')
View
20 cms/tests/settings.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import with_statement
+from cms import constants
from cms.test_utils.testcases import CMSTestCase
from cms.test_utils.util.context_managers import SettingsOverride
from cms.utils import get_cms_setting
@@ -27,3 +28,22 @@ def test_invalid_language_code(self):
ImproperlyConfigured,
get_cms_setting, 'LANGUAGES'
)
+
+ def test_create_page_with_inheritance_override(self):
+ with SettingsOverride(CMS_TEMPLATE_INHERITANCE=True):
+ for template in get_cms_setting('TEMPLATES'):
+ if (template[0] == constants.TEMPLATE_INHERITANCE_MAGIC):
+ return
@digi604 Collaborator
digi604 added a note

not sure this test works as intended because of the return. use self.assert... something here.

@daegun
daegun added a note
@digi604 Collaborator
digi604 added a note

you can do a self.assertTrue(constants.TEMPLATE_INHERITANCE_MAGIC in get_cms_setting('TEMPLATES'))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ self.assertRaises(
+ ImproperlyConfigured,
+ get_cms_setting, 'TEMPLATES'
+ )
+
+ def test_create_page_without_inheritance_override(self):
+ with SettingsOverride(CMS_TEMPLATE_INHERITANCE=False):
+ for template in get_cms_setting('TEMPLATES'):
+ if (template[0] == constants.TEMPLATE_INHERITANCE_MAGIC):
+ self.assertRaises(
@digi604 Collaborator
digi604 added a note

same here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ ImproperlyConfigured,
+ get_cms_setting, 'TEMPLATES'
+ )
View
3  cms/utils/conf.py
@@ -78,7 +78,8 @@ def get_media_url():
def get_templates():
templates = list(getattr(settings, 'CMS_TEMPLATES', []))
- templates.append((constants.TEMPLATE_INHERITANCE_MAGIC, _('Inherit the template of the nearest ancestor')))
+ if get_cms_setting('TEMPLATE_INHERITANCE'):
+ templates.append((constants.TEMPLATE_INHERITANCE_MAGIC, _('Inherit the template of the nearest ancestor')))
return templates
Something went wrong with that request. Please try again.