本文整理汇总了Python中werkzeug.contrib.atom.AtomFeed.updated方法的典型用法代码示例。如果您正苦于以下问题:Python AtomFeed.updated方法的具体用法?Python AtomFeed.updated怎么用?Python AtomFeed.updated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.contrib.atom.AtomFeed
的用法示例。
在下文中一共展示了AtomFeed.updated方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: lang_feed
# 需要导入模块: from werkzeug.contrib.atom import AtomFeed [as 别名]
# 或者: from werkzeug.contrib.atom.AtomFeed import updated [as 别名]
def lang_feed(lang):
"""generate atom feed for blog entries in the specific language"""
blog_entries = db.session.query(BlogEntry).filter_by(lang = lang).order_by(BlogEntry.created.desc()).limit(PAGE_SIZE)
updated = blog_entries.first().created if blog_entries.count() > 0 else ''
etag = '"{0}"'.format(hashlib.sha256(str(updated)).hexdigest())
if request.headers.get('If-None-Match', '') == etag:
return '', 304
last_modified = format_date_time(mktime(updated.timetuple()))
if request.headers.get('If-Modified-Since', '') == last_modified:
return '', 304
title = app.config['BLOG_OWNER'] + "'s Thoughts and Writings"
if lang == 'cn':
title = app.config['BLOG_OWNER'] + u'的博客'
feed = AtomFeed(title = title,
url = request.url_root,
feed_url = request.url,
author = app.config['BLOG_OWNER'])
if updated:
feed.updated = updated
for blog_entry in blog_entries:
feed.add(title = blog_entry.title,
content = unicode(blog_entry.content),
content_type = 'html',
author = app.config['BLOG_OWNER'],
url = urljoin(request.url_root, url_for('blog_entry.read', uid = blog_entry.uid)),
updated = blog_entry.updated,
published = blog_entry.created)
response = feed.get_response()
response.headers['ETag'] = etag
response.headers['Last-Modified'] = last_modified
return response