From: Sebastian Spaeth Date: Thu, 12 Dec 2013 17:03:47 +0000 (+0100) Subject: Force evaluation of Query() through count() X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=461cd7c10d67e04cde4155f32bcd13d174318ba2;p=mediagoblin.git 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. --- 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%}