]> git.ipfire.org Git - ipfire.org.git/commitdiff
blog: Find posts of an author by common name
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 22 Aug 2018 07:37:44 +0000 (08:37 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 22 Aug 2018 07:37:44 +0000 (08:37 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/blog.py
src/templates/blog/modules/post.html
src/web/blog.py

index a287491676da98fafac543acea31ccde1d919f1f..346e3184052a913ed29060f9117890d1aeafcd69 100644 (file)
@@ -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
index caf318162fdaf06f20b1a53274841356e7037731..a8dd4540f7fca329b4cf37ba120e1b9b08a2aa79 100644 (file)
@@ -1,3 +1,5 @@
+{% import ipfire.accounts as accounts %}
+
 <div class="blog-post {% if "lightningwirelabs.com" in post.tags %}lightning-wire-labs{% end %}">
        <div class="blog-header">
                <h5 class="mb-0">
@@ -7,7 +9,14 @@
                </h5>
 
                <p class="small text-muted">
-                       {{ _("by") }} <a href="/authors/{{ post.author.uid }}">{{ post.author.name }}</a>,
+                       {{ _("by") }}
+
+                       {% if isinstance(post.author, accounts.Account) %}
+                               <a href="/authors/{{ post.author.uid }}">{{ post.author.name }}</a>
+                       {% else %}
+                               <strong>{{ post.author }}</strong>
+                       {% end %},
+
                        {{ locale.format_date(post.published_at, shorter=True, relative=False) }}
                </p>
        </div>
index bb2994b1df11eebbec1f538ee197bf8ad938c460..f4a8fd94775ebcbb8d73f0e2ac79db8f58272020 100644 (file)
@@ -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")