コード例 #1
0
 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()
コード例 #2
0
 def maybe_convert_values(self, model_class, data):
     ret = data.copy()
     for col_name, value in data.items():
         col = getattr(model_class, col_name)
         if isinstance(col, AssociationProxy) or col.impl.uses_objects:
             ret[col_name] = self.convert_identifiers(value)
         elif not hasattr(col, 'type'):
             continue
         elif isinstance(col.type, Date):
             if value in ('today', 'now', 'utcnow'):
                 ret[col_name] = utcnow().date
             else:
                 ret[col_name] = parse_datetime(value).date
         elif isinstance(col.type, DateTime):
             if value in ('now', 'utcnow'):
                 ret[col_name] = utcnow()
             elif not isinstance(value, datetime.datetime):
                 ret[col_name] = parse_datetime(value)
     return ret
コード例 #3
0
    def get_prev_next(self):
        if self.series:
            return self.get_series_prev_next()

        result = db.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': self.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'] == self.slug:
            return None, rows[1]
        elif rows[1]['slug'] == self.slug:
            return rows[0], None
コード例 #4
0
ファイル: user_admin.py プロジェクト: szkkteam/flask-starter
 def populate_obj(self, user):
     super().populate_obj(user)
     if user.active and not user.confirmed_at:
         user.confirmed_at = utcnow()
コード例 #5
0
 def get_published(cls):
     return cls.query\
         .filter(cls.publish_date <= utcnow())\
         .order_by(cls.publish_date.desc(), cls.last_updated.desc())\
         .all()