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:
parent
c518d5421d
commit
461cd7c10d
@ -103,9 +103,10 @@ class BlogPostMediaManager(MediaManagerBase):
|
|||||||
return blog
|
return blog
|
||||||
|
|
||||||
def add_to_user_home_context(context):
|
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)
|
blogs = context['request'].db.Blog.query.filter_by(author=context['user'].id)
|
||||||
|
|
||||||
if blogs:
|
if blogs.count():
|
||||||
context['blogs'] = blogs
|
context['blogs'] = blogs
|
||||||
else:
|
else:
|
||||||
context['blogs'] = None
|
context['blogs'] = None
|
||||||
|
@ -14,14 +14,11 @@
|
|||||||
#
|
#
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# 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 %}
|
{%if blogs %}
|
||||||
<h3>Blog</h3>
|
<h3>Blog</h3>
|
||||||
{% set blogs_url = request.urlgen('mediagoblin.media_types.blog.blog_admin_dashboard',
|
{% set blogs_url = request.urlgen('mediagoblin.media_types.blog.blog_admin_dashboard',
|
||||||
blogs=blogs, user=user.username) %}
|
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%}
|
{%endif%}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user