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.
This commit is contained in:
Sebastian Spaeth 2013-12-12 18:03:47 +01:00
parent c518d5421d
commit 461cd7c10d
2 changed files with 4 additions and 6 deletions

View File

@ -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

View File

@ -14,14 +14,11 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#}
{#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 %}
<h3>Blog</h3>
{% set blogs_url = request.urlgen('mediagoblin.media_types.blog.blog_admin_dashboard',
blogs=blogs, user=user.username) %}
<p><a href="{{ blogs_url }}"><em>Go to blogs</em></a></p>
<p><a href="{{ blogs_url }}"><em>Go to user's blog</em></a></p>
{%endif%}