From 94d473d36e97be678e6ca3f6b0aef05b5128b5b6 Mon Sep 17 00:00:00 2001 From: Jarmil <jarmil.halamicek@seznam.cz> Date: Tue, 15 Sep 2020 08:41:25 +0200 Subject: [PATCH] WIP: jupyter notebooks - priprava --- uniweb/migrations/0007_auto_20200915_0812.py | 131 ++++++++++++++++++ uniweb/models.py | 2 + uniweb/templates/uniweb/base.html | 2 +- uniweb/templates/uniweb/snippet_sections.html | 6 + uniweb/templatetags/__init__.py | 0 uniweb/templatetags/uniweb_filters.py | 10 ++ 6 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 uniweb/migrations/0007_auto_20200915_0812.py create mode 100644 uniweb/templatetags/__init__.py create mode 100644 uniweb/templatetags/uniweb_filters.py diff --git a/uniweb/migrations/0007_auto_20200915_0812.py b/uniweb/migrations/0007_auto_20200915_0812.py new file mode 100644 index 00000000..0eb3436d --- /dev/null +++ b/uniweb/migrations/0007_auto_20200915_0812.py @@ -0,0 +1,131 @@ +# Generated by Django 3.1.1 on 2020-09-15 06:12 + +import wagtail.contrib.table_block.blocks +import wagtail.core.blocks +import wagtail.core.fields +import wagtail.documents.blocks +import wagtail.images.blocks +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("uniweb", "0006_auto_20200911_1426"), + ] + + operations = [ + migrations.AlterField( + model_name="uniwebflexiblepage", + name="content", + field=wagtail.core.fields.StreamField( + [ + ( + "title", + wagtail.core.blocks.CharBlock(icon="title", label="nadpis"), + ), + ( + "text", + wagtail.core.blocks.RichTextBlock( + features=[ + "h2", + "h3", + "h4", + "h5", + "bold", + "italic", + "ol", + "ul", + "hr", + "link", + "document-link", + "image", + "superscript", + "subscript", + "strikethrough", + "blockquote", + ], + label="text", + ), + ), + ( + "text_columns", + wagtail.core.blocks.StructBlock( + [ + ( + "left_text", + wagtail.core.blocks.RichTextBlock( + features=[ + "h2", + "h3", + "h4", + "h5", + "bold", + "italic", + "ol", + "ul", + "hr", + "link", + "document-link", + "image", + "superscript", + "subscript", + "strikethrough", + "blockquote", + ], + label="levý sloupec", + ), + ), + ( + "right_text", + wagtail.core.blocks.RichTextBlock( + features=[ + "h2", + "h3", + "h4", + "h5", + "bold", + "italic", + "ol", + "ul", + "hr", + "link", + "document-link", + "image", + "superscript", + "subscript", + "strikethrough", + "blockquote", + ], + label="pravý sloupec", + ), + ), + ] + ), + ), + ( + "gallery", + wagtail.core.blocks.ListBlock( + wagtail.images.blocks.ImageChooserBlock(label="obrázek"), + icon="image", + label="galerie", + ), + ), + ( + "table", + wagtail.contrib.table_block.blocks.TableBlock( + label="tabulka", template="uniweb/snippet_table.html" + ), + ), + ( + "jupyter", + wagtail.documents.blocks.DocumentChooserBlock( + label="Jupyter notebook" + ), + ), + ], + blank=True, + verbose_name="obsah stránky", + ), + ), + ] diff --git a/uniweb/models.py b/uniweb/models.py index 6c6539e4..720f3bf4 100644 --- a/uniweb/models.py +++ b/uniweb/models.py @@ -10,6 +10,7 @@ from wagtail.contrib.table_block.blocks import TableBlock from wagtail.core import blocks from wagtail.core.fields import StreamField from wagtail.core.models import Page +from wagtail.documents.blocks import DocumentChooserBlock from wagtail.images.blocks import ImageChooserBlock from wagtail.images.edit_handlers import ImageChooserPanel from wagtailmetadata.models import MetadataPageMixin @@ -158,6 +159,7 @@ class UniwebFlexiblePage(Page, SubpageMixin, MetadataPageMixin): "table", TableBlock(label="tabulka", template="uniweb/snippet_table.html",), ), + ("jupyter", DocumentChooserBlock(label="Jupyter notebook")), ], verbose_name="obsah stránky", blank=True, diff --git a/uniweb/templates/uniweb/base.html b/uniweb/templates/uniweb/base.html index e7960a3d..a9a7ed11 100644 --- a/uniweb/templates/uniweb/base.html +++ b/uniweb/templates/uniweb/base.html @@ -1,4 +1,4 @@ -{% load static wagtailcore_tags wagtailimages_tags wagtailmetadata_tags %} +{% load uniweb_filters static wagtailcore_tags wagtailimages_tags wagtailmetadata_tags %} <!doctype html> <html lang="cs"> <head> diff --git a/uniweb/templates/uniweb/snippet_sections.html b/uniweb/templates/uniweb/snippet_sections.html index fc8db888..3f535a06 100644 --- a/uniweb/templates/uniweb/snippet_sections.html +++ b/uniweb/templates/uniweb/snippet_sections.html @@ -42,5 +42,11 @@ </div> {% endif %} + {% if block.block_type == "jupyter" %} + <div class="content-block my-4 clearfix{% if forloop.first %} mt-8 lg:mt-12{% endif %}"> + {{ block.value|jupyterize }} + </div> + {% endif %} + {% endfor %} </section> diff --git a/uniweb/templatetags/__init__.py b/uniweb/templatetags/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/uniweb/templatetags/uniweb_filters.py b/uniweb/templatetags/uniweb_filters.py new file mode 100644 index 00000000..63241b3e --- /dev/null +++ b/uniweb/templatetags/uniweb_filters.py @@ -0,0 +1,10 @@ +# definice vlastnich tagu pro templates + +from django import template + +register = template.Library() + + +@register.filter() +def jupyterize(value): + return value.value + " HIHI" -- GitLab