Templating engine for the Notebook

0 views
Skip to first unread message

Timothy Clemans

unread,
Aug 25, 2008, 7:39:34 AM8/25/08
to sage-...@googlegroups.com, mha...@gmail.com, Harald Schilly, boo...@u.washington.edu, William Stein, knoboo...@googlegroups.com
Hi,

Regarding the Sage Notebook, I propose that we use a templating engine
instead of using Python string templates class and writing HTML code
in the Python code. I have converted the existing templates in Extcode
to templates that use the Jinja engine, see
http://trac.sagemath.org/sage_trac/ticket/3923. I also moved the HTML
for the Account Settings page to a Jinja template, see
http://trac.sagemath.org/sage_trac/ticket/3937.

I think using Jinja makes the Python code more readable. In addition,
I like be able to create a base template that other templates build
upon. Plus it's nice to be able to use for loops and if statements in
the templates. I use both in the templates at the two tickets.

Jinja is a clone of the templating engine used in the most popular
Python web framework Django. I am very interested in the possibility
of migrating the Sage Notebook to Django. Moving all the Notebook's
HTML to Jinja templates is the first step in migrating.

If Sphinx, a documentation system, is distributed with Sage then Jinja
would also be. See the sage-devel thread "Sphinx and the Sage
Documentation" at
http://groups.google.com/group/sage-devel/browse_thread/thread/7b0b2f0b34f1f892/

Timothy

Harald Schilly

unread,
Aug 25, 2008, 8:16:36 AM8/25/08
to sage-devel
Hi

On Aug 25, 1:39 pm, "Timothy Clemans" <timothy.clem...@gmail.com>
wrote:
> I am very interested in the possibility
> of migrating the Sage Notebook to Django. Moving all the Notebook's
> HTML to Jinja templates is the first step in migrating.

My comments on that are based on my experience with something similar
- writing jsp and servlet code in java. But anyways, using templates
has a lot of benefits. Faster development, easier maintenance and
extensibility, i.e. extending basic templates with specialized
functionality and so on. This is also useful for things like i18n
internationalization of the interface, where just a middleware layer
switches according to a language parameter and nobody has to poke
around inside the current python code to replace strings. Another
point is, that editing html content is more error prone since there is
a better separation of code, logic and html. Also, the processing is
faster since templates are only loaded once. according to the django-
book website, there are also addons for authentication and
administration that makes development easier and the interface more
stable.

h

William Stein

unread,
Aug 25, 2008, 12:44:06 PM8/25/08
to Timothy Clemans, sage-...@googlegroups.com, mha...@gmail.com, Harald Schilly, boo...@u.washington.edu, knoboo...@googlegroups.com
On Mon, Aug 25, 2008 at 4:39 AM, Timothy Clemans
<timothy...@gmail.com> wrote:
> Hi,
>
> Regarding the Sage Notebook, I propose that we use a templating engine
> instead of using Python string templates class and writing HTML code
> in the Python code. I have converted the existing templates in Extcode
> to templates that use the Jinja engine, see
> http://trac.sagemath.org/sage_trac/ticket/3923. I also moved the HTML
> for the Account Settings page to a Jinja template, see
> http://trac.sagemath.org/sage_trac/ticket/3937.

Timothy,

I strongly support your proposal to use Jinja to template the HTML
generation code for the Sage notebook. Go for it!

William

>
> I think using Jinja makes the Python code more readable. In addition,
> I like be able to create a base template that other templates build
> upon. Plus it's nice to be able to use for loops and if statements in
> the templates. I use both in the templates at the two tickets.
>
> Jinja is a clone of the templating engine used in the most popular
> Python web framework Django. I am very interested in the possibility
> of migrating the Sage Notebook to Django. Moving all the Notebook's
> HTML to Jinja templates is the first step in migrating.
>
> If Sphinx, a documentation system, is distributed with Sage then Jinja
> would also be. See the sage-devel thread "Sphinx and the Sage
> Documentation" at
> http://groups.google.com/group/sage-devel/browse_thread/thread/7b0b2f0b34f1f892/
>
> Timothy
>

--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

Carl Witty

unread,
Aug 25, 2008, 1:02:40 PM8/25/08
to sage-devel
On Aug 25, 4:39 am, "Timothy Clemans" <timothy.clem...@gmail.com>
wrote:
> Hi,
>
> Regarding the Sage Notebook, I propose that we use a templating engine
> instead of using Python string templates class and writing HTML code
> in the Python code.

I think this is a great idea.

> If Sphinx, a documentation system, is distributed with Sage then Jinja
> would also be. See the sage-devel thread "Sphinx and the Sage
> Documentation" athttp://groups.google.com/group/sage-devel/browse_thread/thread/7b0b2f...

Unfortunately, Sphinx uses the original Jinja and you're using Jinja2;
one of these will presumably have to change. (I like the idea of
using Jinja2, which is billed as "Jinja1 without the design mistakes";
I don't know how hard it would be to change Sphinx to use Jinja2.)

Carl

alex clemesha

unread,
Aug 25, 2008, 1:04:27 PM8/25/08
to knoboo...@googlegroups.com, sage-...@googlegroups.com, mha...@gmail.com, Harald Schilly, boo...@u.washington.edu, William Stein
On Mon, Aug 25, 2008 at 4:39 AM, Timothy Clemans
<timothy...@gmail.com> wrote:
>
> Hi,
>
> Regarding the Sage Notebook, I propose that we use a templating engine
> instead of using Python string templates class and writing HTML code
> in the Python code. I have converted the existing templates in Extcode
> to templates that use the Jinja engine, see
> http://trac.sagemath.org/sage_trac/ticket/3923. I also moved the HTML
> for the Account Settings page to a Jinja template, see
> http://trac.sagemath.org/sage_trac/ticket/3937.
>
> I think using Jinja makes the Python code more readable. In addition,
> I like be able to create a base template that other templates build
> upon. Plus it's nice to be able to use for loops and if statements in
> the templates. I use both in the templates at the two tickets.
>
> Jinja is a clone of the templating engine used in the most popular
> Python web framework Django. I am very interested in the possibility
> of migrating the Sage Notebook to Django.
This is something that I have considered a bit. Django has a lot of
good stuff for templating, a good ORM, and the admin interface is
seriously amazing.

One argument against using Django for the notebook is that you
might end up trying to code around a bunch of the abstractions that
Django puts on top of what is really going on.

Either way, this is definitely something to consider, because in my
experience, Django is really good at what it does.

-Alex

Reply all
Reply to author
Forward
0 new messages