]>
git.ipfire.org Git - ipfire.org.git/blob - webapp/backend/news.py
3 from misc
import Object
6 def get(self
, uuid
, lang
="en"):
7 return self
.db
.get("SELECT * FROM news WHERE uuid = %s AND lang = %s \
8 AND published IS NOT NULL AND published <= NOW()", uuid
, lang
)
10 def get_by_slug(self
, slug
):
11 return self
.db
.get("SELECT * FROM news WHERE slug = %s \
12 AND published IS NOT NULL AND published <= NOW()", slug
)
14 def get_latest(self
, author
=None, locale
=None, limit
=1, offset
=0):
15 query
= "SELECT * FROM news WHERE published IS NOT NULL AND published <= NOW()"
19 query
+= " AND author_id = %s"
23 query
+= " AND lang = %s"
24 args
.append(locale
.code
[:2])
26 query
+= " ORDER BY published DESC"
36 return self
.db
.query(query
, *args
)
38 def get_by_year(self
, year
, locale
=None):
39 query
= "SELECT * FROM news WHERE published IS NOT NULL AND published <= NOW() \
40 AND EXTRACT(YEAR FROM published) = %s"
44 query
+= " AND lang = %s"
45 args
.append(locale
.code
[:2])
47 query
+= " ORDER BY published DESC"
49 return self
.db
.query(query
, *args
)
53 query
= self
.db
.query("SELECT DISTINCT EXTRACT(YEAR FROM published)::integer AS year FROM news \
54 WHERE published IS NOT NULL AND published <= NOW() ORDER BY year DESC")
56 return [r
.year
for r
in query
]