-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add customizable announcement text on home,login,logout,spawn #1913
Conversation
share/jupyterhub/templates/home.html
Outdated
@@ -2,6 +2,13 @@ | |||
|
|||
{% block main %} | |||
|
|||
{% if announcement_home or announcement %} |
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.
Since this is on every page, perhaps it should be put in the page.html
template? I'm not 100% sure how to specify the extra variables, but perhaps:
{% if announcement_home %}
{% set announcement = announcement_home %}
{% endif %}
{{ super() }}
would work
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.
Nice idea. I was able to simplify a bit more even and it seems to work (pending tests). Another advantage is that there is now an announcement
block which can be inherited separately in other templates - so that option (0) using your own templates becomes even easier. Option (0) should also allow you to easily change the message without restarting!
aee0227
to
e1579e6
Compare
I think (untested) these latest changes should allow you to do the following, which is probably the easiest way to set a simple message using a template:
Before I go forward too much more, does this look good? |
share/jupyterhub/templates/page.html
Outdated
|
||
{% block announcement %} | ||
{% if announcement %} | ||
<div class="container text-center"> |
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.
Can this get the class 'announcement', too, for easier CSS? Then I think this is good to go.
e1579e6
to
aa47e13
Compare
I updated the PR. I started some tests (using the framework in |
Oh, also let me add documentation first... obviously. |
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.
Approved, pending docs. Thanks!
aa47e13
to
a2f0c6a
Compare
Re-pushed. The second commit adds tests, but the tests just don't work - I'm not doing the HTTP simulation correctly somehow. If you have hints, I can fix them, or I can just remove the tests. |
jupyterhub/tests/test_pages.py
Outdated
ann01 = 'ANNOUNCE01' | ||
ann02 = 'ANNOUNCE02' | ||
with mock.patch.dict(app.users.settings, | ||
{'template_vars': {'announcement': ann01}}): |
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.
Add the FormSpawner to the patch so that requesting spawn
renders the spawn page instead of triggering an automatic launch:
with mock.patch.dict(
app.users.settings,
{
'template_vars': {
'announcement': ann01,
},
'spawner_class': FormSpawner,
}
):
Then I think your tests will pass.
- Using the new template_vars setting (jupyterhub#1872), allow the variable `announcement` to create a header message on all the pages in the title, or the variables `announcement_{home,login,logout,spawn}` to set variables on these single pages. - This is not the most powerful method of putting an announcement into the templates, because it requires a server restart to change. But the invasiveness is very low, and allows minimal message without having to touch the templates themselves. - Closes: jupyterhub#1836
- Adds test_pages.py:test_page_contents, which currently tests just the page annoucement variables.
a2f0c6a
to
e7808b5
Compare
Finally got around to making the tests pass. It's a relatively large number of lines for a small change, but maybe this block can be reused for other template tests, too. Please also see if the docs updates are good - it's late and I should check them once more... |
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.
Looks good @rkdarst. A suggestion on docs and tests. Thank you ☀️
share/jupyterhub/templates/home.html
Outdated
@@ -1,4 +1,5 @@ | |||
{% extends "page.html" %} | |||
{% if announcement_home %}{% set announcement = announcement_home %}{% endif %} |
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.
A bit easier to read if these are broken into 3 lines.
jupyterhub/tests/test_pages.py
Outdated
|
||
|
||
@pytest.mark.gen_test | ||
def test_page_contents(app): |
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.
Probably more maintainable to break this into multiple tests.
docs/source/reference/templates.md
Outdated
@@ -59,3 +59,33 @@ text about the server starting up, place this content in a file named | |||
<p>Patience is a virtue.</p> | |||
{% endblock %} | |||
``` | |||
|
|||
## Simple configuration |
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.
## Page Announcements
To add announcements to be displayed on a page, you have two options:
- Extend the page templates as described above
- Use configuration variables
### Announcement Configuration Variables
for readability per review by willingc
per willingc review
Thanks @rkdarst for all your work on this 🎉 |
Thanks, all! I'm sorry I didn't get back to fixing up the patch - my work took me on a different path the last weeks and I didn't have time to think much. I have another JupyterHub deployment this summer, so hopefully I can do more then...
Congrats on 0.9 and thanks for all the hard work!
|
Thanks you @rkdarst. Your effort got us 90% there ☀️ |
announcement
to create a header message on all the pages in thetitle, or the variables
announcement_{home,login,logout,spawn}
toset variables on these single pages.
the templates, because it requires a server restart to change. But
the invasiveness is very low, and allows minimal message
without having to touch the templates themselves.
Usage:
This at least needs testing and documentation before it can be used. More importantly, needs consideration if it is a good idea. Also some designer could make it prettier and fit better. This idea could be in other places in the spirit of "make the default templates more customizable".
My big picture opinion is that this, or something like it, would be useful to include, but if people start going deep enough they would instead directly modify templates to do this. https://jupyterhub.readthedocs.io/en/latest/reference/templates.html#example is the alternative and I think it is clear enough now.