def n_count(category):
"""Count the number of projects in a given category."""
if category == 'featured':
return _n_featured()
if category == 'draft':
return _n_draft()
sql = text('''
WITH uniq AS (
SELECT COUNT(project.id) FROM project
LEFT OUTER JOIN category ON project.category_id=category.id
WHERE
category.short_name=:category
AND project.published=true
AND (project.info->>'passwd_hash') IS NULL
GROUP BY project.id)
SELECT COUNT(*) FROM uniq
''')
results = session.execute(sql, dict(category=category))
count = 0
for row in results:
count = row[0]
return count
评论列表
文章目录