From 461cd7c10d67e04cde4155f32bcd13d174318ba2 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Thu, 12 Dec 2013 18:03:47 +0100 Subject: [PATCH] Force evaluation of Query() through count() Otherwise "blogs" is a query that evaluates to true, even if the user has no blogs. This fixes the bug that the blog link is shown on a user's profile page even if she has no blogs at all. --- mediagoblin/media_types/blog/__init__.py | 3 ++- .../templates/mediagoblin/blog/url_to_blogs_dashboard.html | 7 ++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/mediagoblin/media_types/blog/__init__.py b/mediagoblin/media_types/blog/__init__.py index 8a61c6e0..eca4c8fb 100644 --- a/mediagoblin/media_types/blog/__init__.py +++ b/mediagoblin/media_types/blog/__init__.py @@ -103,9 +103,10 @@ class BlogPostMediaManager(MediaManagerBase): return blog def add_to_user_home_context(context): + """Inject a user's blogs into a (user home page) template context""" blogs = context['request'].db.Blog.query.filter_by(author=context['user'].id) - if blogs: + if blogs.count(): context['blogs'] = blogs else: context['blogs'] = None diff --git a/mediagoblin/media_types/blog/templates/mediagoblin/blog/url_to_blogs_dashboard.html b/mediagoblin/media_types/blog/templates/mediagoblin/blog/url_to_blogs_dashboard.html index 483c1455..cb781b53 100644 --- a/mediagoblin/media_types/blog/templates/mediagoblin/blog/url_to_blogs_dashboard.html +++ b/mediagoblin/media_types/blog/templates/mediagoblin/blog/url_to_blogs_dashboard.html @@ -14,14 +14,11 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -#} - -{#This injects the URL to a user's blog dashboard on her profile. -#} +#}{#This injects the URL to a user's blog dashboard on her profile.#} {%if blogs %}

Blog

{% set blogs_url = request.urlgen('mediagoblin.media_types.blog.blog_admin_dashboard', blogs=blogs, user=user.username) %} -

Go to blogs

+

Go to user's blog

{%endif%} -- 2.25.1