Skip to content

Commit

Permalink
Update templates to conform to new nbconvert system
Browse files Browse the repository at this point in the history
  • Loading branch information
jhamrick committed Mar 18, 2021
1 parent eaf55f0 commit caec1e6
Show file tree
Hide file tree
Showing 23 changed files with 39 additions and 75 deletions.
9 changes: 4 additions & 5 deletions nbgrader/converters/generate_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ def _load_config(self, cfg, **kwargs):
def __init__(self, coursedir=None, **kwargs):
super(GenerateFeedback, self).__init__(coursedir=coursedir, **kwargs)
c = Config()
if 'template_file' not in self.config.HTMLExporter:
c.HTMLExporter.template_file = 'feedback.html.j2'
if 'template_path' not in self.config.HTMLExporter:
template_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'server_extensions', 'formgrader', 'templates'))
c.HTMLExporter.template_paths.extend(['.', template_path])
c.HTMLExporter.template_name = 'feedback'
c.HTMLExporter.template_file = 'feedback.html.j2'
template_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'server_extensions', 'formgrader', 'templates'))
c.HTMLExporter.extra_template_basedirs.append(template_path)
self.update_config(c)
3 changes: 3 additions & 0 deletions nbgrader/preprocessors/getgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def preprocess(self,
resources['nbgrader']['max_score'] = notebook.max_score
resources['nbgrader']['late_penalty'] = late_penalty

# Set title
nb['metadata']['title'] = resources['nbgrader']['notebook']

return nb, resources

def _get_comment(self, cell: NotebookNode, resources: ResourcesDict) -> None:
Expand Down
6 changes: 3 additions & 3 deletions nbgrader/server_extensions/formgrader/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@ def render(self, name, **ns):
def write_error(self, status_code, **kwargs):
if status_code == 500:
html = self.render(
'base_500.html.j2',
'pages/base_500.html.j2',
base_url=self.base_url,
error_code=500)

elif status_code == 502:
html = self.render(
'base_500.html.j2',
'pages/base_500.html.j2',
base_url=self.base_url,
error_code=502)

elif status_code == 403:
html = self.render(
'base_403.html.j2',
'pages/base_403.html.j2',
base_url=self.base_url,
error_code=403)

Expand Down
10 changes: 7 additions & 3 deletions nbgrader/server_extensions/formgrader/formgrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ def _classes_default(self):

def build_extra_config(self):
extra_config = super(FormgradeExtension, self).build_extra_config()
extra_config.HTMLExporter.template_file = 'formgrade'
extra_config.HTMLExporter.template_paths.append(handlers.template_path)
extra_config.HTMLExporter.template_name = 'formgrade'
extra_config.HTMLExporter.template_file = 'formgrade.html.j2'
extra_config.HTMLExporter.extra_template_basedirs.append(handlers.template_path)
return extra_config

def init_tornado_settings(self, webapp):
# Init jinja environment
jinja_env = Environment(loader=FileSystemLoader([handlers.template_path]))
jinja_env = Environment(loader=FileSystemLoader([
os.path.join(handlers.template_path, 'formgrade'),
os.path.join(handlers.template_path, 'pages')
]))

course_dir = self.coursedir.root
notebook_dir = self.parent.notebook_dir
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"base_template": "classic",
"mimetypes": {
"text/html": true
},
"preprocessors": {}
}
Original file line number Diff line number Diff line change
@@ -1,60 +1,12 @@
{%- extends 'classic/index.html.j2' -%}
{%- extends 'index.html.j2' -%}
{% from 'mathjax.html.j2' import mathjax %}

{%- block header -%}
<!DOCTYPE html>
<html>
<head>

<meta charset="utf-8" />
<title>{{ resources.nbgrader.notebook }}</title>

{% for css in resources.inlining.css -%}
<style type="text/css">
{{ css }}
</style>
{% endfor %}

<!-- Loading mathjax macro -->
{{ mathjax() }}

<style>
td.center, th.center {
text-align: center;
}
body {
overflow: visible;
font-size: 14px;
padding-top: 1em;
}
div#notebook {
overflow: visible;
border-top: none;
}
{%- block html_head_css -%}
<style type="text/css">
div#notebook-container {
width: 100%;
}
@media print {
div.cell {
display: block;
page-break-inside: avoid;
}
div.output_wrapper {
display: block;
page-break-inside: avoid;
}
div.output {
display: block;
page-break-inside: avoid;
}
}
div.prompt {
min-width: 21ex;
-webkit-box-shadow: none;
box-shadow: none;
}
div.nbgrader_cell {
Expand Down Expand Up @@ -105,9 +57,8 @@ span.nbgrader-label {
top: 4px;
}
</style>
{% endblock html_head_css %}

</head>
{%- endblock header -%}

{% block body %}
<body>
Expand Down Expand Up @@ -139,20 +90,13 @@ span.nbgrader-label {
</div>
</div>
<div class="panel-body">
<div id="notebook" class="border-box-sizing">
<div class="container" id="notebook-container">
{{ super() }}
</div>
</div>
{{ super() }}
</div>
</div>
</div>
</body>
{%- endblock body %}

{% block footer %}
</html>
{% endblock footer %}

{% macro score(cell) -%}
<span class="pull-right">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"base_template": "classic",
"mimetypes": {
"text/html": true
},
"preprocessors": {}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%- extends 'classic/index.html.j2' -%}
{%- extends 'index.html.j2' -%}
{% from 'formgrade_macros.html.j2' import nav, header %}
{% from 'mathjax.html.j2' import mathjax %}

Expand Down

0 comments on commit caec1e6

Please sign in to comment.