From 8a897d25a4ee0fcbc30ad2cbca80cdf8096f2e8c Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 17 Jul 2018 13:33:26 +0100 Subject: [PATCH] blog: Add index page Signed-off-by: Michael Tremer --- Makefile.am | 4 +++- src/templates/blog/index.html | 11 +++++++++++ src/templates/blog/modules/posts.html | 7 +++++++ src/web/__init__.py | 2 ++ src/web/blog.py | 12 ++++++++++++ 5 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/templates/blog/index.html create mode 100644 src/templates/blog/modules/posts.html diff --git a/Makefile.am b/Makefile.am index f69cbcc4..289cf1af 100644 --- a/Makefile.am +++ b/Makefile.am @@ -113,12 +113,14 @@ templatesdir = $(datadir)/templates templates_blog_DATA = \ src/templates/blog/author.html \ src/templates/blog/base.html \ + src/templates/blog/index.html \ src/templates/blog/post.html templates_blogdir = $(templatesdir)/blog templates_blog_modules_DATA = \ - src/templates/blog/modules/post.html + src/templates/blog/modules/post.html \ + src/templates/blog/modules/posts.html templates_blog_modulesdir = $(templates_blogdir)/modules diff --git a/src/templates/blog/index.html b/src/templates/blog/index.html new file mode 100644 index 00000000..4ea36226 --- /dev/null +++ b/src/templates/blog/index.html @@ -0,0 +1,11 @@ +{% extends "base.html" %} + +{% block title %}{{ _("Welcome!") }}{% end block %} + +{% block main %} +
+
+ {% module BlogPosts(posts) %} +
+
+{% end block %} diff --git a/src/templates/blog/modules/posts.html b/src/templates/blog/modules/posts.html new file mode 100644 index 00000000..fc81b48a --- /dev/null +++ b/src/templates/blog/modules/posts.html @@ -0,0 +1,7 @@ +{% for i, post in enumerate(posts) %} + {% module BlogPost(post) %} + + {% if i < (len(posts) - 1) %} +
+ {% end %} +{% end %} diff --git a/src/web/__init__.py b/src/web/__init__.py index 63cd2b10..b4037c93 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -40,6 +40,7 @@ class Application(tornado.web.Application): }, "ui_modules" : { "BlogPost" : blog.PostModule, + "BlogPosts" : blog.PostsModule, # Old modules "Advertisement" : AdvertisementModule, @@ -124,6 +125,7 @@ class Application(tornado.web.Application): # blog.ipfire.org self.add_handlers(r"blog(\.dev)?\.ipfire\.org", [ + (r"/", blog.IndexHandler), (r"/authors/(\w+)", blog.AuthorHandler), (r"/post/(.*)", blog.PostHandler), ]) diff --git a/src/web/blog.py b/src/web/blog.py index 59e9d845..5ace7a8d 100644 --- a/src/web/blog.py +++ b/src/web/blog.py @@ -6,6 +6,13 @@ import handlers_base as base from . import ui_modules +class IndexHandler(base.BaseHandler): + def get(self): + posts = self.planet.get_entries(limit=3) + + self.render("blog/index.html", posts=posts) + + class AuthorHandler(base.BaseHandler): def get(self, uid): author = self.accounts.get_by_uid(uid) @@ -32,3 +39,8 @@ class PostHandler(base.BaseHandler): class PostModule(ui_modules.UIModule): def render(self, post): return self.render_string("blog/modules/post.html", post=post) + + +class PostsModule(ui_modules.UIModule): + def render(self, posts): + return self.render_string("blog/modules/posts.html", posts=posts) -- 2.39.2