Skip to content
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

WIP wiki support for microsite templates #10623

Merged
merged 1 commit into from
Jan 12, 2016

Conversation

felipemontoya
Copy link
Member

This PR would allow the templates being rendered with the django_template engine, most notably the wiki, to support the templates override used for microsites. Specially the header and footer templates.

The way this PR addresses this issue is by creating a template tag that wrapps the microsite.get_template_path function used for finding the templates. Then it uses this templatetag inside the main_django.html template.

@openedx-webhooks
Copy link

Thanks for the pull request, @felipemontoya! I've created OSPR-949 to keep track of it in JIRA. JIRA is a place for product owners to prioritize feature reviews by the engineering development teams.

Feel free to add as much of the following information to the ticket:

  • supporting documentation
  • edx-code email threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will still be done via the GitHub pull request interface. As a reminder, our process documentation is here.

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U needs triage labels Nov 13, 2015
@felipemontoya
Copy link
Member Author

Hi @chrisndodge, some of my work this week led me to support the microsites template overrides on the wiki pages, so I put together this PR to discuss if this is upstream material.

@chrisndodge
Copy link
Contributor

Thanks @felipemontoya! I'll try this out. FYI, @singingwolfboy

@@ -33,19 +33,17 @@
{% if IS_EDX_DOMAIN %}
{% include "navigation-edx.html" %}
{% else %}
{% include "navigation.html" %}
{% include "navigation.html"|microsite_template_path %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nifty trick! I didn't know this was possible.

@chrisndodge chrisndodge added the waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. label Dec 2, 2015
@chrisndodge
Copy link
Contributor

Also, I don't think this branch is still active in your repository. I'm trying to pull from your repo to run this locally - to give it a whirl - but I'm not seeing it in: https://github.com/eduNEXT/edunext-platform

Am I looking in the right place?

@chrisndodge
Copy link
Contributor

I guess I could simply generate a .patch file from the PR and apply it locally...

@felipemontoya
Copy link
Member Author

Hi @chrisndodge, that is the repo we use for deployment, all the changes we submit to uptream are at the regular edx-platform repo. Here is the correct branch: https://github.com/eduNEXT/edx-platform/tree/fmo/wiki-support-for-microsites

@chrisndodge
Copy link
Contributor

@felipemontoya thanks, got it! Giving it a spin right now...

@chrisndodge
Copy link
Contributor

@felipemontoya hrm, I'm having trouble running that branch in my devstack. My devstack environment is close to upstream edX master, so it's likely an environment issue. I'll either need to provision a clean devstack or simple just apply the diff patch to my localdev. I'll probably do the latter to save some time and diskspace.

@chrisndodge
Copy link
Contributor

@felipemontoya thanks. Still trying to get your PR running, I'm having some devstack issues...

@chrisndodge chrisndodge removed the waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. label Dec 2, 2015
@chrisndodge
Copy link
Contributor

@felipemontoya OK, I'm seeing one problem. When I go to the wiki on one of our white label sites, I'm getting a template not found error. however I do have a <microsite_key>/templates/footer.html file defined (but it is a Mako template). I'll investigate, but do you have any tips?

@felipemontoya
Copy link
Member Author

The fact that it is a mako template should not make any difference. The footer I am currently using is also a mako template. The only thing I have seen here are rendering errors when the file does not have unix endings, but I don't think that is the case here.

Now, is the path literally /templates/footer.html, because the templatetag strips the leading / since the include tag would not take absolute paths.

@chrisndodge
Copy link
Contributor

thanks. still having trouble here. I do have a footer.html in my microsite, but I don't have a navigation.html (not overridden). The navigation.html loads fine from the base edx-platform, but footer.html fails.

I hate to throw out the Django1.8 card, but I'm running this on 1.8, are you? I'm not sure if there might be some template loader differences between the versions.

@felipemontoya
Copy link
Member Author

Django 1.8 might actually be the cause. I have this branch in an old devstack from django 1.4. I will launch a sandbox on a new devstack running from master and see if it works. It will probably take me a couple of hours.

@chrisndodge
Copy link
Contributor

thanks, sorry for the hassle. I'm not even sure it'll make a difference...

@felipemontoya
Copy link
Member Author

Hi @chrisndodge, I found the same issue on a new devstack running django 1.8. It has to do with the way the lms/startup.py:enable_microsite function works, but I'm still looking into it. I will update the PR with both a fix and the rebase to master when I make it work.

@felipemontoya felipemontoya force-pushed the fmo/wiki-support-for-microsites branch from 52a1ab8 to b5196f5 Compare December 3, 2015 21:04
@felipemontoya
Copy link
Member Author

@chrisndodge, basically, the MakoLoader in django1.8 has an engine which gets initialized with the TEMPLATE['DIRS'] before we had the chance to enable the microsites feature. I moved the enable_microsites to make it add the microsites_root_path before that happens.

@chrisndodge
Copy link
Contributor

@felipemontoya thanks!

@felipemontoya
Copy link
Member Author

The test env clearly didn't like the change, now I'm wondering if that is a missing configuration on the test env. Did you tried the change in your devstack to see if it works for you?

@chrisndodge
Copy link
Contributor

I should be able to try locally in a few hours. Thanks!

@chrisndodge
Copy link
Contributor

@felipemontoya @mattdrayer I pulled this down tonight and applied it locally. In general, it seems to work, but there seems to need some changes in edX's production microsites for this to fully work:

  1. We need to add a ## mako statement at the top of our header.html file defined in our microsites
  2. The .css override file needs to be added to the Wiki page (otherwise styling is kinda broken)

I'm going to have to dig in a bit here to see how we can pull this in without causing visual regressions in our white labels.

@mattdrayer
Copy link
Contributor

@felipemontoya let us know if you need a hand with this PR -- we have a ticket in our backlog (WL-247) reserved for providing support.

@felipemontoya
Copy link
Member Author

Hi @mattdrayer and @chrisndodge. I has out for the holidays, but I'm back at the office now.

Obviously I have no access to the repository where you keep your microsites, but I could easily add the css override to the django_main, the same way we did it at our repo. We did this so long ago that I did not even notice that it wasn't in the upstream repo. Now, since Chris mentioned the visual regressions in your white labels I will wait a word from you before I do that.

P.S: I think I'm not allowed to see WL-247.

@@ -28,14 +28,14 @@
<div class="window-wrap" dir="${static.dir_rtl()}">
<a class="nav-skip" href="{% block nav_skip %}#content{% endblock %}">{% trans "Skip to main content" %}</a>
{% with course=request.course %}
{% include "header.html" %}
{% include "header.html"|microsite_template_path %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattdrayer @chrisndodge I investigated it on my side after pulling down this branch. It seems me, wiki page is based on Django templates rather than mako and after running the lms on this branch , It seems me header from microsite is not loading in wiki. You can see that templates/header.html is based on mako in microsite and main_django.html in wiki page is trying to load this microsite header file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felipemontoya if you can address this issue today, that would be great.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I understood what you mean, but the renderer is actually capable of including Mako templates from within a django_template. That is what the ## mako first line does. It helps the template engine to recognize mako templates to load them with the right library.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then It means, our microsite templates should have ## mako in first line.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, although not every single template needs it. It is only used when loading mako templates from inside django_templates. Some examples that do need it are header.html and footer.html. Once the templates is mako, it can include other mako templates without needing the ## mako line

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so I guess I'm not clear on what needs to happen next for this PR -- @asadiqbal08, do we need to update additional microsite templates in our repo with the mako tag prior to merging in order to avoid breakages?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattdrayer make tag ## mako is missing in our microsite repo (header.html) that is why there is a breakage in header section of wiki. I think we need to add up this in order to load headers.

@mattdrayer @felipemontoya It seems me that microsite css is not rendering in wiki. we need to override the microsite css. I just tested it after adding the {% microsite_css_overrides_file %} in main_django.html and styles are rendering OK.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asadiqbal08 -- okay, let's go ahead and make the necessary changes in the edx-microsites repository. Please log a WL ticket to track the job and add it to the current sprint.

@felipemontoya
Copy link
Member Author

That and also tell me if you also want to have me add the CSS overrides file. I would say yes to that, but you need to test it along with your microsites repo to see that the styles are rendering OK.

@mtyaka
Copy link
Contributor

mtyaka commented Jan 7, 2016

Thanks for working on this, it would be great to get microsites working correctly with django templates. I opened a very similar PR some time ago (before comprehensive theming landed).

@singingwolfboy suggested to use a custom django template loader rather than filters, see: https://github.com/edx/edx-platform/pull/9282#discussion_r37007674
I really like that idea, especially because having a dynamic django loader similar to the mako loader would also enable comprehensive theming to work on the wiki. Currently it doesn't work due to the same problem you ran into while working on this PR - when comprehensive theme startup code runs and adds new template paths to the TEMPLATES['DIRS'], default django template engine is already initialized and adding new folders to the 'DIRS' entry has no effect.

@felipemontoya
Copy link
Member Author

@mattdrayer and @asadiqbal08 I just updated the main_django file adding the css overrides. Which use to be there, but where removed at this point.

After I did that, I went back to the comp_theming readme file stating that you should now place this in the head-extra.html which currently does not exist in the main repository. There is however a header_extra.html file which is empty and has a note saying it is meant to be overriden by the templates in the microsite.

Putting everything togher I am now sure, that the css overrides should not longer be there (I'll remove it next thing), but instead, you also have to place ## mako tags on the head-extra.html files in your microsites to make sure they render correctly and in turn they will add the css_overrides_file.

@singingwolfboy could you please correct me if I'm wrong in the last paragraph or on this PR's code?

@singingwolfboy
Copy link
Contributor

@felipemontoya I believe you are correct. I've put in a PR to remove the unused header_extra.html file: https://github.com/edx/edx-platform/pull/11165

@felipemontoya
Copy link
Member Author

I tested my assumptions locally and it work, it required also that the head-extra.html import was filtered with the microsite_template_path tag. I updated the code accordingly

Again, the head-extra.html file in your microsite repo also needs the ## mako tag.

@mattdrayer
Copy link
Contributor

Okay, we've merged @asadiqbal08's mako tag update to our microsites repository, so I think we're good to go there. @felipemontoya @singingwolfboy @asadiqbal08 @mtyaka if there are no other changes you feel are necessary for this PR after having a chance to review the changeset I think we are good to move forward -- let me know.

@singingwolfboy
Copy link
Contributor

Looks fine to me. 👍

@mattdrayer
Copy link
Contributor

@felipemontoya I think the only other thing I would like to see here is a handful of unit tests which cover the new djangoapp operations and the settings check in startup.py -- would it be possible to include these in this PR?

@felipemontoya
Copy link
Member Author

@mattdrayer a pair of tests for the microsite_template_path filter should be easy. I'll add them in a while.

@mattdrayer
Copy link
Contributor

Hi @felipemontoya -- just pinging you re: the aforementioned tests -- once we have those I think this PR is good to go.

@felipemontoya
Copy link
Member Author

@mattdrayer, I added one simple test for the filter, to make sure those lines are being run during the test process. Do you reckon more complicated tests are in order there?

@felipemontoya felipemontoya force-pushed the fmo/wiki-support-for-microsites branch from 8ac45cc to f0c43a2 Compare January 11, 2016 16:20
@mattdrayer
Copy link
Contributor

jenkins run python

@mattdrayer
Copy link
Contributor

@felipemontoya -- thanks for adding the test -- I'm still a little fuzzy on exactly what is being covered here semantically, but Jenkins is happy and the diff coverage report is showing 100% so I guess in cold world of robots and LOCs we are looking good. If there are no other changes to be made then I'd say it's time to squash, verify one last time, and merge 👍

Stripping the leading / for the django_templates finder

Enabling the microsite configurations before running django.setup()

Adding only the templates directory before startup

Adding the missing overrides file at the django templates main

Using the comp_theming way of overriding css

Adding test for the microsite_template_path filter
@felipemontoya felipemontoya force-pushed the fmo/wiki-support-for-microsites branch from f0c43a2 to f2a6a27 Compare January 12, 2016 15:35
@felipemontoya
Copy link
Member Author

jenkins run bokchoy

@felipemontoya
Copy link
Member Author

@mattdrayer, squashed and tested. From my end we are ready.

@mattdrayer
Copy link
Contributor

Alright, let's do it! Thanks very much for this contribution, @felipemontoya -- merging now!

mattdrayer added a commit that referenced this pull request Jan 12, 2016
@mattdrayer mattdrayer merged commit b549adf into openedx:master Jan 12, 2016
@felipemontoya felipemontoya deleted the fmo/wiki-support-for-microsites branch October 22, 2019 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
engineering review open-source-contribution PR author is not from Axim or 2U
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants