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

add redirect handler for notebooks by name #3058

Merged
merged 2 commits into from Apr 12, 2013
Merged

Conversation

minrk
Copy link
Member

@minrk 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 mentioned this pull request Mar 23, 2013
@ellisonbg
Copy link
Member

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

@minrk
Copy link
Member Author

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.

@authenticate_unless_readonly
def get(self, notebook_name):
app = self.application
print notebook_name
Copy link
Member

Choose a reason for hiding this comment

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

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!

Copy link
Member Author

Choose a reason for hiding this comment

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

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

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)`
@ellisonbg
Copy link
Member

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//pull/3058#issuecomment-15331393
.

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

@minrk
Copy link
Member Author

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.

@authenticate_unless_readonly
def get(self, notebook_name):
app = self.application
if notebook_name.endswith('.ipynb'):
Copy link
Member

Choose a reason for hiding this comment

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

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

@ellisonbg
Copy link
Member

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.

regex already guarantees it
ellisonbg added a commit that referenced this pull request Apr 12, 2013
add redirect handler for notebooks by name
@ellisonbg ellisonbg merged commit c07e21f into ipython:master Apr 12, 2013
@damianavila
Copy link
Member

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

@minrk minrk deleted the redirect branch April 15, 2013 21:13
@mprat
Copy link

mprat commented Nov 21, 2013

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

@chiwhalee
Copy link

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

@Carreau
Copy link
Member

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
add redirect handler for notebooks by name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants