Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

add redirect handler for notebooks by name #3058

Merged
merged 2 commits into from Apr 12, 2013

Conversation

Projects
None yet
6 participants
Owner

minrk commented Mar 23, 2013

Now you can visit localhost:8888/My Notebook.ipynb, and it will redirect you to the UUID url. This allows cross-notebook links, etc. with [other notebook](Notebook Name.ipynb).
It does not introduce any of the problems associated with 'real' persistent URLs,
since these are only written by humans, and only redirect to real URLs.
A rename breaks such a link, exactly as you would expect.

see #3056

@minrk minrk referenced this pull request Mar 23, 2013

Closed

links across notebooks #3056

Owner

ellisonbg commented Mar 23, 2013

Awesome! We really need this and I think this is a good start. I will try to get going on some code reviews...

Owner

minrk commented Mar 23, 2013

My first draft had this as a special nb/Notebook Name url, rather than top-level and without the .ipynb, but if we do it this way, the links should still work in nbviewer without modification.

@damianavila damianavila and 1 other commented on an outdated diff Mar 23, 2013

IPython/frontend/html/notebook/handlers.py
@@ -609,6 +609,21 @@ def on_close(self):
# Notebook web service handlers
#-----------------------------------------------------------------------------
+class NotebookRedirectHandler(AuthenticatedHandler):
+
+ @authenticate_unless_readonly
+ def get(self, notebook_name):
+ app = self.application
+ print notebook_name
@damianavila

damianavila Mar 23, 2013

Contributor

There is no need to print the notebook_name, don't you think? The code looks good... This enhancement is really great for the generation of interlinked ipynb-based documents and to access to ipynb easily from iframes... I really like it!

@minrk

minrk Mar 23, 2013

Owner

No, certainly not - that's just my debug statement that I accidentally committed. Removed.

add redirect handler for notebooks by name
Now you can visit `localhost:8888/My Notebook.ipynb`,
and it will redirect you to the UUID url.
This allows cross-notebook links, etc. with `[other notebook](Notebook Name.ipynb)`
Owner

ellisonbg commented Mar 23, 2013

The main thing I think we need to think about is how this relates to the
upcoming work on changing directories:

  • How do you reference a notebook in a sub dir/parent dir?

Also, would it be more consistent to put these under the "files" handler.
Those notebooks are in that dir after all. But we really want to get this
right as we don't want to break everyones links by changes as we move to
the multiuser notebook (host://username/...) or multiple directory support.

On Fri, Mar 22, 2013 at 9:04 PM, Min RK notifications@github.com wrote:

My first draft had this as a special nb/Notebook Name url, rather than
top-level and without the .ipynb, but if we do it this way, the links
should still work in nbviewer without modification.


Reply to this email directly or view it on GitHubhttps://github.com/ipython/ipython/pull/3058#issuecomment-15331393
.

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

Owner

minrk commented Mar 23, 2013

  • How do you reference a notebook in a sub dir/parent dir?

We are going to need to figure out what the URL scheme looks like for notebooks elsewhere before we can think about this. We may want another special redirect that can take more information, but the important thing here is that a relative link to an adjacent notebook resolves.

Also, would it be more consistent to put these under the "files" handler.

It would not. a files url is strictly for serving static files - a link to a live notebook is decidedly not serving a static file. Specifically, requesting files/Notebook Name.ipynb always has worked, but this results in downloading the notebook file (as it should, being served as a static file), not loading the file in an active notebook.

What should work, given what we have now:

  • linking to an adjacent notebook with simple relative notebook.ipynb URL.

What may need more work (or may never work, depending how we do things):

  • linking to notebooks in other directories

But we can't begin to think about this one until we have our url scheme for notebooks in other directories.
One thing that may change is that notebooks get /, such that starting from notebook U-U-I-D

right now:

link Notebook.ipynb on page /root/U-U-I-D resolves to /root/Notebook.ipynb. If we end up going with simple UUID urls for notebooks even after we have multiple directory support, it may make more sense for the notebook URLs to have trailing slash, so a single notebook would be /root/U-U-I-D/, in which case the relative Notebook.ipynb url would instead resolve to /root/U-U-I-D/Notebook.ipynb, which we would then have to interpret as "Notebook.ipynb that is adjacent to notebook with id U-U-I-D". In either case, the link scheme is the same - as long as people stick to relative URLs.

If we end up with per-directory project UUIDs, such that each notebook would have a url like /root/projectUUID/nbUUID, then there's no problem again, because it is unambiguous which project where the notebook resides. For linking across projects, we may need to add another redirect for 'project-by-name', just like this one for notebook-by-name. In all of these cases so far, the redirect does not need to change.

@ellisonbg ellisonbg commented on an outdated diff Apr 12, 2013

IPython/frontend/html/notebook/handlers.py
@@ -609,6 +609,20 @@ def on_close(self):
# Notebook web service handlers
#-----------------------------------------------------------------------------
+class NotebookRedirectHandler(AuthenticatedHandler):
+
+ @authenticate_unless_readonly
+ def get(self, notebook_name):
+ app = self.application
+ if notebook_name.endswith('.ipynb'):
@ellisonbg

ellisonbg Apr 12, 2013

Owner

Given the regular expression used, this check is not needed. IOW, the notebook_name will always end with .ipynb.

Owner

ellisonbg commented Apr 12, 2013

OK I am convinced that this PR is a good idea. I think we can merge it - the only question on the code is whether we really need to test if the notebook_name ends with .ipynb.

ellisonbg added a commit that referenced this pull request Apr 12, 2013

Merge pull request #3058 from minrk/redirect
add redirect handler for notebooks by name

@ellisonbg ellisonbg merged commit c07e21f into ipython:master Apr 12, 2013

Contributor

damianavila commented Apr 13, 2013

Great! Very useful! Thanks for your work on this...

@minrk minrk deleted the minrk:redirect branch Apr 15, 2013

mprat commented Nov 21, 2013

Thank you thank you! This is amazing when developing teaching lesson plans!

I still don't understand how to use this feature. Who can give me an example how to redirect to a head cell?

edit: I found a detailed explanation, follow this link
http://python.6.x6.nabble.com/How-to-use-anchors-td5034324.html

Owner

Carreau commented Jan 8, 2014

let say you are on notebook MyNotebook.ipynb, you click on my header 1 . url should become something like http://localost:8888/ctf56ab86c36->http://localost:8888/ctf56ab86c36#my_hedear_1 (the #my_header_1 part is important. You shoudl now be able to link to your notebook as href="MyNotebook.ipynb#my_header_1" That is to say, if you enter the url http://localost:8888/MyNotebook.ipynb#my_hedear_1 in your adresse bar, you should be redirected to http://localost:8888/ctf56ab86c36#my_hedear_1 with My Header 1 on top of the page.

This of course only for 1.0/1.1 as it is not relevant on master anymore as we got rid of UUID in URL.

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014

Merge pull request #3058 from minrk/redirect
add redirect handler for notebooks by name

@caynan caynan referenced this pull request in econchick/new-coder Jan 20, 2015

Open

Put all tutorials in IPython notebooks #126

0 of 6 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment