Skip to content

Freeze read only feature fixed for Jupyter 5.x (and compatible with Jupyter 4.x)#958

Closed
tnarik wants to merge 14 commits intoipython-contrib:masterfrom
tnarik:freeze_read_only
Closed

Freeze read only feature fixed for Jupyter 5.x (and compatible with Jupyter 4.x)#958
tnarik wants to merge 14 commits intoipython-contrib:masterfrom
tnarik:freeze_read_only

Conversation

@tnarik
Copy link
Copy Markdown
Contributor

@tnarik tnarik commented Apr 13, 2017

Proposed fix for #940.

@jcb91
Copy link
Copy Markdown
Member

jcb91 commented Apr 14, 2017

Thanks for this, it looks good to me. As noted in #885 (comment), there's also a cell.metadata.deletable attribute, though it seems that non-editable cells are implicitly non-deletable, so I guess we don't need to set that as well. However, it might be good to migrate & remove the old metadata values?

@tnarik
Copy link
Copy Markdown
Contributor Author

tnarik commented Apr 14, 2017 via email

tnarik added 4 commits April 18, 2017 10:29
…re compatibility with notebooks modified using previous versions of the freeze extention.

Updated compatibility property
@tnarik
Copy link
Copy Markdown
Contributor Author

tnarik commented Apr 18, 2017

Updated the notebook to read old format ('run_control>read_only') metadata.
Also fixed an issue by which, once touched by the plugin, the 'editable' metadata was set to 'false' (because in Jupyter 5.x editable = true means the flag won't be persisted to file).

continue;
}
var state = 'normal';
// Old metadata format
Copy link
Copy Markdown
Member

@jcb91 jcb91 Apr 18, 2017

Choose a reason for hiding this comment

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

Oh, I was thinking of something more like

if (cell.metadata.run_control && cell.metadata.run_control.read_only !== undefined) {
    if (cell.metadata.run_control.read_only) {
        cell.metadata.editable = false;
    }
    delete cell.metadata.run_control.read_only;
}

so that we adopt the new metadata just by loading the notebook - make sense?

@tnarik
Copy link
Copy Markdown
Contributor Author

tnarik commented Apr 18, 2017 via email

@jcb91
Copy link
Copy Markdown
Member

jcb91 commented Apr 19, 2017

I just didn't want to change much the existing code, even if refactoring could make sense.

Fair enough, that's a reasonable approach 😄

Opening the notebook will immediately take care of the "upgrade" because
loading the extension triggers the initialization of the cell states and
the setting of the cell metadata (via set_state).

Yes, it will work ok, in the sense that the new metadata.editable will be set correctly, but it will also leave behind the old metadata.run_control.read_only value, which will override the metadata.editable each time the nbextension loads. I think it'd be neater to remove the old-style metadata attribute once it's been transferred to the new editable attribute. Does that make more sense?

@tnarik
Copy link
Copy Markdown
Contributor Author

tnarik commented Apr 19, 2017

Ah, sorry. Yes, it makes perfect sense. I thought I tested that but I didn't.

…e plugin in use, as we are setting a fresh one during set_state.
@tnarik tnarik closed this Apr 22, 2017
@tnarik tnarik deleted the freeze_read_only branch April 22, 2017 09:25
@tnarik
Copy link
Copy Markdown
Contributor Author

tnarik commented Apr 22, 2017

Created a new pull request, #968, instead of this one.

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.

3 participants