本文整理汇总了Python中mail.Mail.get_posts_by_date方法的典型用法代码示例。如果您正苦于以下问题:Python Mail.get_posts_by_date方法的具体用法?Python Mail.get_posts_by_date怎么用?Python Mail.get_posts_by_date使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mail.Mail
的用法示例。
在下文中一共展示了Mail.get_posts_by_date方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from mail import Mail [as 别名]
# 或者: from mail.Mail import get_posts_by_date [as 别名]
def post(self):
self.admin_or_login()
# get new post DB properties
title = self.request.get('post-title')
body = self.request.get('post-body')
if not title or not body: # forgot something - make user go back
return self.render('new-blog-post.html',
post_title=title,
post_body=body)
title_path = get_title_path(title, character_limit=30)
today = datetime.date.today()
offset = len(Mail.get_posts_by_date(today)) # TODO: use gql.count() instead of len(posts)
# put post in DB
mail_key = Mail(title=title,
title_path=title_path,
body=body,
bday_offset=offset).put()
# get blog post document search properties
fields = [search.TextField(name='title', value=title),
search.TextField(name='body', value=body)]
doc = search.Document(doc_id=mail_key.urlsafe(), fields=fields)
# put blog post in document search
try:
search.Index(name=SEARCH_INDEX_NAME).put(doc)
except search.Error:
logging.error('Document search PUT failed')
# TODO: small bug - have to refresh after redirect
self.redirect('/blog')
示例2: get
# 需要导入模块: from mail import Mail [as 别名]
# 或者: from mail.Mail import get_posts_by_date [as 别名]
def get(self, year, month, day, offset=None, limit=MAX_POSTS_PER_PAGE):
if offset is not None:
offset = int(offset)
limit = 1
year, month, day = map(int, (year, month, day))
date = datetime.datetime(year, month, day)
posts = Mail.get_posts_by_date(date, limit=limit, offset=offset)
self.view_posts(posts)