本文整理匯總了Python中redwind.models.Post.load_by_date方法的典型用法代碼示例。如果您正苦於以下問題:Python Post.load_by_date方法的具體用法?Python Post.load_by_date怎麽用?Python Post.load_by_date使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類redwind.models.Post
的用法示例。
在下文中一共展示了Post.load_by_date方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: find_target_post
# 需要導入模塊: from redwind.models import Post [as 別名]
# 或者: from redwind.models.Post import load_by_date [as 別名]
def find_target_post(target_url):
current_app.logger.debug("looking for target post at %s", target_url)
# follow redirects if necessary
redirect_url = urllib.request.urlopen(target_url).geturl()
if redirect_url and redirect_url != target_url:
current_app.logger.debug("followed redirection to %s", redirect_url)
target_url = redirect_url
parsed_url = urllib.parse.urlparse(target_url)
if not parsed_url:
current_app.logger.warn("Could not parse target_url of received webmention: %s", target_url)
return None
try:
# FIXME this is a less-than-perfect fix for hosting from a
# subdirectory. The url_map may have some clever work-around.
parsed_site_root = urllib.parse.urlparse(get_settings().site_url)
site_prefix = parsed_site_root.path
if site_prefix.endswith("/"):
site_prefix = site_prefix[:-1]
if not parsed_url.path.startswith(parsed_site_root.path):
raise NotFound
urls = current_app.url_map.bind(get_settings().site_url)
path = parsed_url.path[len(site_prefix) :]
current_app.logger.debug("target path with no prefix %s", path)
endpoint, args = urls.match(path)
current_app.logger.debug("found match for target url %r: %r", endpoint, args)
except NotFound:
current_app.logger.warn("Webmention could not find target for %s", parsed_url.path)
return None
post = None
if endpoint == "views.post_by_path":
year = args.get("year")
month = args.get("month")
slug = args.get("slug")
post = Post.load_by_path("{}/{:02d}/{}".format(year, month, slug))
elif endpoint == "views.post_by_date":
post_type = args.get("post_type")
year = args.get("year")
month = args.get("month")
day = args.get("day")
index = args.get("index")
post = Post.load_by_date(post_type, year, month, day, index)
elif endpoint == "views.post_by_old_date":
post_type = args.get("post_type")
yymmdd = args.get("yymmdd")
year = int("20" + yymmdd[0:2])
month = int(yymmdd[2:4])
day = int(yymmdd[4:6])
post = Post.load_by_date(post_type, year, month, day, index)
elif endpoint == "views.post_by_id":
dbid = args.get("dbid")
post = Post.load_by_id(dbid)
if not post:
current_app.logger.warn("Webmention target points to unknown post: {}".format(args)),
return post