def publish_date(self): datestamp = self.frontmatter.get('publish_date') if not datestamp: match = re.match(DATE_RE, self.is_dir and self.dir_name or self.file_name) datestamp = match and match.group('date') or None if datestamp: datestamp = parse_datetime(datestamp) return datestamp and datestamp.astimezone(pytz.UTC) or utcnow()
def get_prev_next(self, article: Article): if article.series: return self.get_series_prev_next(article) result = self.session.execute(f''' WITH articles AS ( SELECT slug, title, ROW_NUMBER() OVER (ORDER BY publish_date ASC, last_updated ASC) AS row_number FROM {Article.__tablename__} WHERE publish_date <= :now AND article_series_id IS NULL ) SELECT slug, title FROM articles WHERE row_number IN ( SELECT row_number + i FROM articles CROSS JOIN (SELECT -1 AS i UNION ALL SELECT 0 UNION ALL SELECT 1) n WHERE slug = :slug ) ''', {'now': utcnow(), 'slug': article.slug}) rows = [{'slug': row[0], 'title': row[1]} for row in result.fetchall()] if len(rows) == 1: return None, None elif len(rows) == 3: return rows[0], rows[2] elif rows[0]['slug'] == article.slug: return None, rows[1] elif rows[1]['slug'] == article.slug: return rows[0], None
def populate_obj(self, user): super().populate_obj(user) if user.is_active and not user.confirmed_at: user.confirmed_at = utcnow()
def find_published(self): return (self.q .filter(Article.publish_date <= utcnow()) .order_by(Article.publish_date.desc(), Article.last_updated.desc()) .all())