AND %s = ANY(tags) \
ORDER BY published_at DESC LIMIT %s", tag, limit)
- def get_by_author(self, author, limit=None):
- return self._get_posts("SELECT * FROM blog \
- WHERE (author = %s OR author_uid = %s) \
- AND published_at IS NOT NULL \
- AND published_at <= NOW() \
- ORDER BY published_at DESC LIMIT %s",
- author.name, author.uid, limit)
-
def get_by_year(self, year):
return self._get_posts("SELECT * FROM blog \
WHERE EXTRACT(year FROM published_at) = %s \
AND published_at <= NOW() \
ORDER BY published_at DESC", year)
- def get_drafts(self, author=None, limit=None):
- if author:
- return self._get_posts("SELECT * FROM blog \
- WHERE author_uid = %s \
- AND (published_at IS NULL OR published_at > NOW()) \
- ORDER BY COALESCE(updated_at, created_at) DESC LIMIT %s",
- author.uid, limit)
-
+ def get_drafts(self, author, limit=None):
return self._get_posts("SELECT * FROM blog \
- WHERE (published_at IS NULL OR published_at > NOW()) \
- ORDER BY COALESCE(updated_at, created_at) DESC LIMIT %s", limit)
+ WHERE author_uid = %s \
+ AND (published_at IS NULL OR published_at > NOW()) \
+ ORDER BY COALESCE(updated_at, created_at) DESC LIMIT %s",
+ author.uid, limit)
def search(self, query, limit=None):
posts = self._get_posts("SELECT blog.* FROM blog \
for row in res:
yield row.year
- @property
- def authors(self):
- res = self.db.query("""
- SELECT
- author_uid,
- MAX(published_at) AS published_at
- FROM
- blog
- WHERE
- author_uid IS NOT NULL
- AND
- published_at IS NOT NULL
- AND
- published_at <= NOW()
- GROUP BY
- author_uid
- ORDER BY
- published_at DESC
- """,
- )
-
- return [self.backend.accounts.get_by_uid(row.author_uid) for row in res]
-
async def announce(self):
posts = self._get_posts("SELECT * FROM blog \
WHERE (published_at IS NOT NULL AND published_at <= NOW()) \