-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Allow theme template block overrides. #16856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <%page expression_filter="h"/> | ||
|
|
||
| # Include template which does not exist in the theme. | ||
| <%include file="/courseware/error-message.html" /> | ||
| # Include template which is overriden in the theme. | ||
| <%include file="/courseware/info.html" /> | ||
| # Include custom template which only exists in the theme. | ||
| <%include file="/courseware/test-theme-custom.html" /> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| <%page expression_filter="h"/> | ||
| <p>This overrides the courseware/info.html template.</p> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| <%page expression_filter="h"/> | ||
| <p>This is a custom template.</p> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <%page expression_filter="h"/> | ||
| <%! | ||
| from openedx.core.djangolib.markup import HTML | ||
| %> | ||
|
|
||
| <%inherit file="dashboard.html" /> | ||
| <%block name="pagetitle">Overridden Title!</%block> | ||
| ${HTML(parent.body())} | ||
| <%block name="bodyextra">Overriden Body Extra!</%block> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,81 @@ def test_logo_image(self): | |
| result = staticfiles.finders.find('test-theme/images/logo.png') | ||
| self.assertEqual(result, settings.TEST_THEME / 'lms/static/images/logo.png') | ||
|
|
||
| @with_comprehensive_theme("test-theme") | ||
| def test_override_block_in_parent(self): | ||
| """ | ||
| Test that theme title is used instead of parent title. | ||
| """ | ||
| self._login() | ||
| dashboard_url = reverse('dashboard') | ||
| resp = self.client.get(dashboard_url) | ||
| self.assertEqual(resp.status_code, 200) | ||
| # This string comes from the 'pagetitle' block of the overriding theme. | ||
| self.assertContains(resp, "Overridden Title!") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should also
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the test_parent_content_in_self_inherited_template test covers this case. They are testing the same theme with one test testing the overwritten fields and one testing the non overwritten fields.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the |
||
|
|
||
| @with_comprehensive_theme("test-theme") | ||
| def test_override_block_in_grandparent(self): | ||
| """ | ||
| Test that theme title is used instead of parent's parent's title. | ||
| """ | ||
| self._login() | ||
| dashboard_url = reverse('dashboard') | ||
| resp = self.client.get(dashboard_url) | ||
| self.assertEqual(resp.status_code, 200) | ||
| # This string comes from the 'bodyextra' block of the overriding theme. | ||
| self.assertContains(resp, "Overriden Body Extra!") | ||
|
|
||
| @with_comprehensive_theme("test-theme") | ||
| def test_parent_content_in_self_inherited_template(self): | ||
| """ | ||
| Test that parent's body is present in self inherited template. | ||
| """ | ||
| self._login() | ||
| dashboard_url = reverse('dashboard') | ||
| resp = self.client.get(dashboard_url) | ||
| self.assertEqual(resp.status_code, 200) | ||
| # This string comes from the default dashboard.html template. | ||
| self.assertContains(resp, "Explore courses") | ||
|
|
||
| @with_comprehensive_theme("test-theme") | ||
| def test_include_default_template(self): | ||
| """ | ||
| Test that theme template can include template which is not part of the theme. | ||
| """ | ||
| self._login() | ||
| courses_url = reverse('courses') | ||
| resp = self.client.get(courses_url) | ||
| self.assertEqual(resp.status_code, 200) | ||
| # The courses.html template includes the error-message.html template. | ||
| # Verify that the error message is included in the output. | ||
| self.assertContains(resp, "this module is temporarily unavailable") | ||
|
|
||
| @with_comprehensive_theme("test-theme") | ||
| def test_include_overridden_template(self): | ||
| """ | ||
| Test that theme template can include template which is overridden in the active theme. | ||
| """ | ||
| self._login() | ||
| courses_url = reverse('courses') | ||
| resp = self.client.get(courses_url) | ||
| self.assertEqual(resp.status_code, 200) | ||
| # The courses.html template includes the info.html file, which is overriden in the theme. | ||
| self.assertContains(resp, "This overrides the courseware/info.html template.") | ||
|
|
||
| @with_comprehensive_theme("test-theme") | ||
| def test_include_custom_template(self): | ||
| """ | ||
| Test that theme template can include template which is only present in the theme, but has no standard LMS | ||
| equivalent. | ||
| """ | ||
| self._login() | ||
| courses_url = reverse('courses') | ||
| resp = self.client.get(courses_url) | ||
| self.assertEqual(resp.status_code, 200) | ||
| # The courses.html template includes the test-theme.custom.html file. | ||
| # Verify its contents are present in the output. | ||
| self.assertContains(resp, "This is a custom template.") | ||
|
|
||
|
|
||
| @skip_unless_cms | ||
| class TestComprehensiveThemeCMS(TestCase): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is HTML(…) needed, when we already have "h"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HTMLis the reverse ofh.<%page expression_filter="h"/>at the top of the template means all interpolated strings are HTML escaped by default, so you have to useHTMLto explicitly disable that behavior.EdX quality scripts enforce that all mako templates have
<%page expression_filter="h"/>enabled, which is why I used it here even though it's technically unnecessary.