From f91dfcc70ef2c01d766309211259693ff98bb505 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 17 Jul 2018 12:53:06 +0100 Subject: [PATCH] blog: Create module for posts Signed-off-by: Michael Tremer --- Makefile.am | 5 +++++ src/templates/blog/modules/post.html | 10 ++++++++++ src/templates/blog/post.html | 11 ++--------- src/web/__init__.py | 3 +++ src/web/blog.py | 7 +++++++ 5 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 src/templates/blog/modules/post.html diff --git a/Makefile.am b/Makefile.am index ecf7f3ca..b52c7515 100644 --- a/Makefile.am +++ b/Makefile.am @@ -116,6 +116,11 @@ templates_blog_DATA = \ templates_blogdir = $(templatesdir)/blog +templates_blog_modules_DATA = \ + src/templates/blog/modules/post.html + +templates_blog_modulesdir = $(templates_blogdir)/modules + templates_modules_DATA = \ src/templates/modules/menu.html diff --git a/src/templates/blog/modules/post.html b/src/templates/blog/modules/post.html new file mode 100644 index 00000000..c8ab8e66 --- /dev/null +++ b/src/templates/blog/modules/post.html @@ -0,0 +1,10 @@ +
+
{{ post.title }}
+ +

+ {{ _("by") }} {{ post.author.name }}, + {{ locale.format_date(post.published, shorter=True, relative=False) }} +

+ + {% raw post.text %} +
diff --git a/src/templates/blog/post.html b/src/templates/blog/post.html index 37053a79..4532880e 100644 --- a/src/templates/blog/post.html +++ b/src/templates/blog/post.html @@ -4,15 +4,8 @@ {% block main %}
-
-
{{ post.title }}
- -

- {{ _("by") }} {{ post.author.name }}, - {{ locale.format_date(post.published, shorter=True, relative=False) }} -

- - {% raw post.text %} +
+ {% module BlogPost(post) %}
{% end block %} diff --git a/src/web/__init__.py b/src/web/__init__.py index 6a1f9218..94d31e38 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -39,6 +39,9 @@ class Application(tornado.web.Application): "format_month_name" : self.format_month_name, }, "ui_modules" : { + "BlogPost" : blog.PostModule, + + # Old modules "Advertisement" : AdvertisementModule, "DonationBox" : DonationBoxModule, "DonationButton" : DonationButtonModule, diff --git a/src/web/blog.py b/src/web/blog.py index 06f8c2ef..90f8c86b 100644 --- a/src/web/blog.py +++ b/src/web/blog.py @@ -4,6 +4,8 @@ import tornado.web import handlers_base as base +from . import ui_modules + class PostHandler(base.BaseHandler): def get(self, slug): entry = self.planet.get_entry_by_slug(slug) @@ -11,3 +13,8 @@ class PostHandler(base.BaseHandler): raise tornado.web.HTTPError(404) self.render("blog/post.html", post=entry) + + +class PostModule(ui_modules.UIModule): + def render(self, post): + return self.render_string("blog/modules/post.html", post=post) -- 2.47.3