From: Michael Tremer Date: Wed, 22 Aug 2018 07:37:44 +0000 (+0100) Subject: blog: Find posts of an author by common name X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cdf85ee7df85db919303aa669a2b8034e89a6cac;p=ipfire.org.git blog: Find posts of an author by common name Signed-off-by: Michael Tremer --- diff --git a/src/backend/blog.py b/src/backend/blog.py index a2874916..346e3184 100644 --- a/src/backend/blog.py +++ b/src/backend/blog.py @@ -38,12 +38,13 @@ class Blog(misc.Object): AND %s = ANY(tags) \ ORDER BY published_at DESC LIMIT %s", tag, limit) - def get_by_author(self, uid, limit=None): + def get_by_author(self, author, limit=None): return self._get_posts("SELECT * FROM blog \ - WHERE author_uid = %s \ + WHERE (author = %s OR author_uid = %s) \ AND published_at IS NOT NULL \ AND published_at <= NOW() \ - ORDER BY published_at DESC LIMIT %s", uid, limit) + ORDER BY published_at DESC LIMIT %s", + author.name, author.uid, limit) def get_by_year(self, year): return self._get_posts("SELECT * FROM blog \ @@ -95,6 +96,8 @@ class Post(misc.Object): if self.data.author_uid: return self.backend.accounts.get_by_uid(self.data.author_uid) + return self.data.author + @property def created_at(self): return self.data.created_at diff --git a/src/templates/blog/modules/post.html b/src/templates/blog/modules/post.html index caf31816..a8dd4540 100644 --- a/src/templates/blog/modules/post.html +++ b/src/templates/blog/modules/post.html @@ -1,3 +1,5 @@ +{% import ipfire.accounts as accounts %} +
@@ -7,7 +9,14 @@

- {{ _("by") }} {{ post.author.name }}, + {{ _("by") }} + + {% if isinstance(post.author, accounts.Account) %} + {{ post.author.name }} + {% else %} + {{ post.author }} + {% end %}, + {{ locale.format_date(post.published_at, shorter=True, relative=False) }}

diff --git a/src/web/blog.py b/src/web/blog.py index bb2994b1..f4a8fd94 100644 --- a/src/web/blog.py +++ b/src/web/blog.py @@ -21,7 +21,7 @@ class AuthorHandler(base.BaseHandler): raise tornado.web.HTTPError(404, "User is unknown") # Get all posts from this author - posts = self.backend.blog.get_by_author(author.uid) + posts = self.backend.blog.get_by_author(author) if not posts: raise tornado.web.HTTPError(404, "User has no posts")