Skip to content

Commit

Permalink
Cleanup (jupyter#1824)
Browse files Browse the repository at this point in the history
* Remove unecessary is_lab variable in formgrader static file

* Remove compatibility with NotebookApp

* Handle multiple courses with JupyterHub when using Notebook
  • Loading branch information
brichet authored Sep 1, 2023
1 parent 93db0b8 commit 6db3800
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 122 deletions.
8 changes: 4 additions & 4 deletions demos/demo_multiple_classes/jupyterhub_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@
'user': 'grader-course101',
'cwd': '/home/grader-course101',
'environment': {
# specify formgrader as default landing page
'JUPYTERHUB_DEFAULT_URL': '/formgrader'
# specify lab as default landing page
'JUPYTERHUB_DEFAULT_URL': '/lab'
},
'api_token': '{{course101_token}}',
},
Expand All @@ -116,8 +116,8 @@
'user': 'grader-course123',
'cwd': '/home/grader-course123',
'environment': {
# specify formgrader as default landing page
'JUPYTERHUB_DEFAULT_URL': '/formgrader'
# specify lab as default landing page
'JUPYTERHUB_DEFAULT_URL': '/lab'
},
'api_token': '{{course123_token}}',
},
Expand Down
4 changes: 2 additions & 2 deletions demos/demo_one_class_multiple_graders/jupyterhub_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
],
'user': 'grader-course101',
'environment': {
# specify formgrader as default landing page
'JUPYTERHUB_DEFAULT_URL': '/formgrader'
# specify lab as default landing page
'JUPYTERHUB_DEFAULT_URL': '/lab'
},
'cwd': '/home/grader-course101',
}
Expand Down
26 changes: 0 additions & 26 deletions demos/formgrader_workspace.json

This file was deleted.

4 changes: 0 additions & 4 deletions demos/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ setup_nbgrader () {
${runas} mkdir -p "${HOME}/.jupyter"
${runas} cp "${config}" "${HOME}/.jupyter/nbgrader_config.py"
${runas} chown "${USER}:${USER}" "${HOME}/.jupyter/nbgrader_config.py"

cp "/root/formgrader_workspace.json" "${HOME}/formgrader_workspace.json"
chown "${USER}:${USER}" "${HOME}/formgrader_workspace.json"
${runas} jupyter lab workspaces import "${HOME}/formgrader_workspace.json"
}

setup_jupyterhub () {
Expand Down
6 changes: 1 addition & 5 deletions nbgrader/server_extensions/assignment_list/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,7 @@ def load_jupyter_server_extension(nbapp):
webapp = nbapp.web_app
webapp.settings['assignment_list_manager'] = AssignmentList(parent=nbapp)

# compatibility between notebook.notebookapp.NotebookApp and jupyter_server.serverapp.ServerApp
if nbapp.name == 'jupyter-notebook':
webapp.settings['assignment_list_manager'].root_dir = nbapp.notebook_dir
else:
webapp.settings['assignment_list_manager'].root_dir = nbapp.root_dir
webapp.settings['assignment_list_manager'].root_dir = nbapp.root_dir

base_url = webapp.settings['base_url']
webapp.add_handlers(".*$", [
Expand Down
14 changes: 5 additions & 9 deletions nbgrader/server_extensions/course_list/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def check_for_local_formgrader(self, config):
if status:
raise gen.Return([{
'course_id': coursedir.course_id,
'url': base_url + '/formgrader',
'url': base_url + '/lab',
'kind': 'local'
}])

Expand All @@ -102,7 +102,7 @@ def check_for_noauth_jupyterhub_formgraders(self, config):
if not coursedir.course_id:
raise gen.Return([])

url = self.get_base_url() + "/services/" + coursedir.course_id + "/formgrader"
url = self.get_base_url() + "/services/" + coursedir.course_id
auth = get_jupyterhub_authorization()
http_client = AsyncHTTPClient()
try:
Expand All @@ -113,7 +113,7 @@ def check_for_noauth_jupyterhub_formgraders(self, config):

courses = [{
'course_id': coursedir.course_id,
'url': url,
'url': url + "/lab",
'kind': 'jupyterhub'
}]
raise gen.Return(courses)
Expand Down Expand Up @@ -156,7 +156,7 @@ def check_for_jupyterhub_formgraders(self, config):
service = services[course]
courses.append({
'course_id': course,
'url': self.get_base_url() + service['prefix'].rstrip('/') + "/formgrader",
'url': self.get_base_url() + service['prefix'].rstrip('/') + "/lab",
'kind': 'jupyterhub'
})

Expand Down Expand Up @@ -233,11 +233,7 @@ def load_jupyter_server_extension(nbapp):
webapp = nbapp.web_app
base_url = webapp.settings['base_url']

# compatibility between notebook.notebookapp.NotebookApp and jupyter_server.serverapp.ServerApp
if nbapp.name == 'jupyter-notebook':
webapp.settings['assignment_dir'] = nbapp.notebook_dir
else:
webapp.settings['assignment_dir'] = nbapp.root_dir
webapp.settings['assignment_dir'] = nbapp.root_dir

webapp.add_handlers(".*$", [
(ujoin(base_url, pat), handler)
Expand Down
9 changes: 1 addition & 8 deletions nbgrader/server_extensions/formgrader/formgrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,9 @@ def load_jupyter_server_extension(nbapp):
nbapp.log.info("Loading the formgrader nbgrader serverextension")
webapp = nbapp.web_app

# Save which kind of application is running : Jupyterlab like or classic Notebook
webapp.settings['is_jlab'] = not (nbapp.name == 'jupyter-notebook')

formgrader = FormgradeExtension(parent=nbapp)

# compatibility between notebook.notebookapp.NotebookApp and jupyter_server.serverapp.ServerApp
if nbapp.name == 'jupyter-notebook':
formgrader.root_dir = nbapp.notebook_dir
else:
formgrader.root_dir = nbapp.root_dir
formgrader.root_dir = nbapp.root_dir

formgrader.log = nbapp.log
formgrader.initialize([])
Expand Down
1 change: 0 additions & 1 deletion nbgrader/server_extensions/formgrader/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def get(self):
"manage_assignments.tpl",
url_prefix=self.url_prefix,
base_url=self.base_url,
is_lab=int(self.settings['is_jlab']),
windows=(sys.prefix == 'win32'),
course_id=self.api.course_id,
exchange=self.api.exchange_root,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ var AssignmentUI = Backbone.View.extend({
this.listenTo(this.model, "request", this.animateSaving);
this.listenTo(this.model, "sync", this.closeModal);

this.is_lab = options.is_lab || false;
this.render();
},

Expand Down Expand Up @@ -102,17 +101,17 @@ var AssignmentUI = Backbone.View.extend({
var name = this.model.get("name")
this.$name.attr("data-order", name);

/* Append link with :
* - href if this is a Notebook<7 environment
* - click listener to send message to iframe parent if this is Jupyter Lab environment
*/
// Append link with a listener to send message to iframe parent.
// NOTE: the formgrade UI is embedded in an iframe.
this.$name.append($("<a/>")
.text(name)
.attr("target", self.is_lab ? undefined : "_blank")
.attr("href", self.is_lab ? undefined : base_url + "/tree/" + url_prefix + "/" + this.model.get("source_path"))
.click(self.is_lab ? function(){
window.parent.postMessage(jlab_go_to_path(url_prefix + "/" + this_assignment.model.get("source_path")), '*');
} : undefined)
.attr("href", "#")
.click(function() {
window.parent.postMessage(
jlab_go_to_path(url_prefix + "/" + this_assignment.model.get("source_path")),
'*'
);
})
);

// duedate
Expand Down Expand Up @@ -141,32 +140,38 @@ var AssignmentUI = Backbone.View.extend({
.click(_.bind(this.openModal, this))
.append($("<span/>")
.addClass("glyphicon glyphicon-pencil")
.attr("aria-hidden", "true")));
.attr("aria-hidden", "true")
)
);

// generate student version
this.$assign.append($("<a/>")
.attr("href", "#")
.click(_.bind(this.assign, this))
.append($("<span/>")
.addClass("glyphicon glyphicon-education")
.attr("aria-hidden", "true")));
.attr("aria-hidden", "true")
)
);

// preview student version
var release_path = this.model.get("release_path");
if (release_path) {
/* Append link with :
* - href if this is a Notebook<7 environment
* - click listener to send message to iframe parent if this is Jupyter Lab environment
*/
// Append link with a listener to send message to iframe parent.
// NOTE: the formgrade UI is embedded in an iframe.
this.$preview.append($("<a/>")
.attr("target", self.is_lab ? undefined : "_blank")
.attr("href", self.is_lab ? undefined : base_url + "/tree/" + url_prefix + "/" + release_path)
.click(self.is_lab ? function(){
window.parent.postMessage(jlab_go_to_path(url_prefix + "/" + release_path), '*');
} : undefined)
.attr("href", "#")
.click(function() {
window.parent.postMessage(
jlab_go_to_path(url_prefix + "/" + release_path),
'*'
);
})
.append($("<span/>")
.addClass("glyphicon glyphicon-search")
.attr("aria-hidden", "true")));
.attr("aria-hidden", "true")
)
);
}

// release
Expand All @@ -178,14 +183,18 @@ var AssignmentUI = Backbone.View.extend({
.click(_.bind(this.release, this))
.append($("<span/>")
.addClass("glyphicon glyphicon-cloud-upload")
.attr("aria-hidden", "true")));
.attr("aria-hidden", "true")
)
);
} else {
this.$release.append($("<a/>")
.attr("href", "#")
.click(_.bind(this.unrelease, this))
.append($("<span/>")
.addClass("glyphicon glyphicon-remove")
.attr("aria-hidden", "true")));
.attr("aria-hidden", "true")
)
);
}
}

Expand All @@ -197,7 +206,9 @@ var AssignmentUI = Backbone.View.extend({
.click(_.bind(this.collect, this))
.append($("<span/>")
.addClass("glyphicon glyphicon-cloud-download")
.attr("aria-hidden", "true")));
.attr("aria-hidden", "true")
)
);
}
}

Expand All @@ -209,27 +220,32 @@ var AssignmentUI = Backbone.View.extend({
} else {
this.$num_submissions.append($("<a/>")
.attr("href", base_url + "/formgrader/manage_submissions/" + this.model.get("name"))
.text(num_submissions));
.text(num_submissions)
);
}

// generate feedback
if (num_submissions > 0) {
this.$generate_feedback.append($("<a/>")
.attr("href", "#")
.attr("href", "#")
.click(_.bind(this.generate_feedback, this))
.append($("<span/>")
.addClass("glyphicon glyphicon-comment")
.attr("aria-hidden", "true")));
.append($("<span/>")
.addClass("glyphicon glyphicon-comment")
.attr("aria-hidden", "true")
)
);
}

// feedback
if (num_submissions > 0) {
this.$release_feedback.append($("<a/>")
.attr("href", "#")
.attr("href", "#")
.click(_.bind(this.release_feedback, this))
.append($("<span/>")
.addClass("glyphicon glyphicon-envelope")
.attr("aria-hidden", "true")));
.append($("<span/>")
.addClass("glyphicon glyphicon-envelope")
.attr("aria-hidden", "true")
)
);
}

},
Expand Down Expand Up @@ -579,7 +595,7 @@ var createAssignmentModal = function () {
modal = createModal("add-assignment-modal", "Add New Assignment", body, footer);
};

var loadAssignments = function (is_lab=false) {
var loadAssignments = function () {
var tbl = $("#main-table");

models = new Assignments();
Expand All @@ -591,8 +607,7 @@ var loadAssignments = function (is_lab=false) {
models.each(function (model) {
var view = new AssignmentUI({
"model": model,
"el": insertRow(tbl),
"is_lab": is_lab
"el": insertRow(tbl)
});
views.push(view);
});
Expand All @@ -605,8 +620,7 @@ var loadAssignments = function (is_lab=false) {
var models = undefined;
var views = [];

var is_lab = is_lab || false;

$(window).on('load', function () {
loadAssignments(is_lab);
loadAssignments();
});
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,12 @@ function jlab_open_notebook(notebook_path) {
<li><a href="{{ resources.base_url }}/formgrader/gradebook/{{ resources.assignment_id }}/{{ resources.notebook_id }}">{{ resources.notebook_id }}</a></li>
<li class="active live-notebook">
<a class="name-hidden" data-toggle="tooltip" data-placement="bottom" title="Open live notebook"
{%- if is_lab -%}
onclick='window.parent.postMessage(jlab_open_notebook("{{ resources.notebook_path }}"), "*");'
{%- else -%}
target="_blank" href="{{ resources.base_url }}/notebooks/{{ resources.notebook_path }}"
{%- endif -%}
>
Submission #{{ resources.index + 1 }}
</a>
<a class="name-shown" data-toggle="tooltip" data-placement="bottom" title="Open live notebook"
{%- if is_lab -%}
onclick='window.parent.postMessage(jlab_open_notebook("{{ resources.notebook_path }}"), "*"); '
{%- else -%}
target="_blank" href="{{ resources.base_url }}/notebooks/{{ resources.notebook_path }}"
{%- endif -%}
>
{%- if resources.last_name and resources.first_name -%}
{{ resources.last_name }}, {{ resources.first_name }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{%- block head -%}
<script>
var url_prefix = "{{ url_prefix }}";
var is_lab = {% if is_lab %}true{% else %}false{% endif %};
</script>

<script src="{{ base_url }}/formgrader/static/js/manage_assignments.js"></script>
Expand Down
6 changes: 1 addition & 5 deletions nbgrader/server_extensions/validate_assignment/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,7 @@ def load_jupyter_server_extension(nbapp):
webapp = nbapp.web_app
base_url = webapp.settings['base_url']

# compatibility between notebook.notebookapp.NotebookApp and jupyter_server.serverapp.ServerApp
if nbapp.name == 'jupyter-notebook':
webapp.settings['root_dir'] = nbapp.notebook_dir
else:
webapp.settings['root_dir'] = nbapp.root_dir
webapp.settings['root_dir'] = nbapp.root_dir

webapp.add_handlers(".*$", [
(ujoin(base_url, pat), handler)
Expand Down
Loading

0 comments on commit 6db3800

Please sign in to comment.