Allow theme template block overrides. - #16856
Conversation
|
Thanks for the pull request, @mtyaka! It looks like you're a member of a company that does contract work for edX. If you're doing this work as part of a paid contract with edX, you should talk to edX about who will review this pull request. If this work is not part of a paid contract with edX, then you should ensure that there is an OSPR issue to track this work in JIRA, so that we don't lose track of your pull request. |
clemente
left a comment
There was a problem hiding this comment.
@mtyaka Thanks! Great work! And yes, this is more complex than the initial PR.
I tested this in many ways (I'll write the list later) and it works.
In the strange cases it fails with the same errors as master (e.g. maximum recursion depth exceeded). I don't think we need tests for that. These include: invalid templates, inheriting from the wrong one, …
My comments are mainly to try to make the code easier to understand and you can do any other changes that help with that.
It would be much better if everything could be done from get_template, including knowing where to find the file (whether in theme or in standard theme), but I suppose you tried and couldn''t find it and therefore did the „marker class“. Maybe it's useful to add why it can't be done from get_template.
I didn't run the tests yet but I see they passed.
I'll test this more when I use it in some theme adaptation, but I hope I won't find major changes.
There was a problem hiding this comment.
In comments there are words „inherit“, „call“, „import“, though I think they refer to the same and it's confusing; would it improve by e.g. „importing“ → „inheriting from“? Or any other simplification.
Maybe the comments can mention a single example? Only if it helps. If adding more text makes it more confusing, then not.
There was a problem hiding this comment.
This method is called when a mako template either <%inherit>s or <%include>s another template.
I can see why the comments are confusing, I'll try to make them clearer.
There was a problem hiding this comment.
This part is also computed in line 109. Although now the flow is clear, I think the repeated part (and the comment in 108) can be computed earlier into a variable, to avoid duplication.
There was a problem hiding this comment.
Good idea - I put the repeated parts into a separate private method.
There was a problem hiding this comment.
At first I didn't understand self-inheritance; maybe it helps to mention that it's the same as before. 1-word fix: just saying „When this self-inheritance […]“ already links it to the description before.
There was a problem hiding this comment.
Why is HTML(…) needed, when we already have "h"?
There was a problem hiding this comment.
HTML is the reverse of h. <%page expression_filter="h"/> at the top of the template means all interpolated strings are HTML escaped by default, so you have to use HTML to 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.
There was a problem hiding this comment.
I think you should also self.assertContains(resp, "Explore courses") or similar, to check that we're getting the full dashboard with our modifications on top, not just a blank template with the content of the overridden blocks.
Same in the other „dashboard“ test. Or this could be in its own test.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Yes, the test_parent_content_in_self_inherited_template covers this case, but this test did not yet exist when @clemente made that comment, I added it later.
31e4917 to
a70a475
Compare
mtyaka
left a comment
There was a problem hiding this comment.
Thanks for the review @clemente!
It would be much better if everything could be done from get_template, including knowing where to find the file (whether in theme or in standard theme), but I suppose you tried and couldn''t find it and therefore did the „marker class“.
We cannot do it from get_template because we can't get access to the calling template uri in that method. Make does not pass the calling uri when calling get_template on the template loader.
There was a problem hiding this comment.
This method is called when a mako template either <%inherit>s or <%include>s another template.
I can see why the comments are confusing, I'll try to make them clearer.
There was a problem hiding this comment.
Good idea - I put the repeated parts into a separate private method.
There was a problem hiding this comment.
HTML is the reverse of h. <%page expression_filter="h"/> at the top of the template means all interpolated strings are HTML escaped by default, so you have to use HTML to 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.
clemente
left a comment
There was a problem hiding this comment.
👍
- I tested this:
- expectedly fails when defining two times the same block
- expectedly fails when including non-existing file
- expectedly fails when inheriting from two templates at the same time
- when defining unexisting block, its content appears
- I tried to copy/paste the original courses.html to a theme courses.html, still works
- I tried an include inside a block
- complex things and invalid values, like inheriting from a totally different template, fail the same as in the original code
- tests run
- I used this in one file of a client theme
- I read through the code
- I checked for accessibility issues: none
- Includes documentation, as comments in the code and functions/classes
@mtyaka everything works, thanks
|
@bderusha @tuchfarber This reimplements ability to override specific named block overrides from a theme template without having to copy the entire template, which was first introduced in https://github.com/edx/edx-platform/pull/15947, but later reverted in https://github.com/edx/edx-platform/pull/16729 after some issues were discovered. This PR fixes the issues and adds extra tests to cover some edge cases. BTW, the OSPR form currently doesn't work - I get a 500 error when I try to create a new OSPR issues for this PR. |
|
I've tested with the themes it previously broke on and them seem to be working now. Excellent work! Still need to go through the code though. |
There was a problem hiding this comment.
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.
This allows an overridding template from a theme to inherit from the same corresponding standard template. This is useful when you only want to override one or more named blocks, but otherwise make no modifications to the standard template.
|
Squash from a70a4755ed28c95898d29b3e18c7b50f7ee19319. |
a70a475 to
f6f29ca
Compare
|
Thanks @tuchfarber! I don't have permission to merge this, any chance you could do that after the build is green? |
|
EdX Release Notice: This PR has been deployed to the staging environment in preparation for a release to production on Thursday, December 28, 2017. |
|
EdX Release Notice: This PR has been deployed to the production environment. |
Rewritten most of the course_about.html template through blocks. This depends on the new template block inheritance system (merged at https://github.com/edx/edx-platform/pull/16856), and it requires the new blocks to be defined in edx-platform too.
|
EdX Release Notice: This PR has been rolled back from the production environment. |
This allows an overridding template from a theme to inherit from the same corresponding standard template.
This is useful when you only want to override one or more named blocks, but otherwise make no modifications to the standard template.
This functionality was already implemented in https://github.com/edx/edx-platform/pull/15947, but then reverted in https://github.com/edx/edx-platform/pull/16729 after some issues were discovered.
This PR fixes the issue and adds tests for it.
Dependencies: None
Sandbox URL:
Deployment targets: edx.org and edge.edx.org
Merge deadline: None
Testing instructions:
/edx/app/edxapp/themes/testtheme/edx/app/edxapp/themes/testtheme/lms/templates/dashboard.html, and put this content into it:Author notes and concerns:
Note: Some templates are cached, so if you don't see the changes, you can try wiping the cache by doing
rm -rf /tmp/mako_*andsudo service memcached restart.