本文整理汇总了Python中model.Entry.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Entry.get_by_id方法的具体用法?Python Entry.get_by_id怎么用?Python Entry.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Entry
的用法示例。
在下文中一共展示了Entry.get_by_id方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from model import Entry [as 别名]
# 或者: from model.Entry import get_by_id [as 别名]
def get(self, page_id="", operation=""):
t_values = {}
logging.info("PageManager get: page_id = %s, operation = %s" % (page_id, operation))
# find current_post based on page_id
if page_id:
current_post = Entry.get_by_id(long(page_id))
if current_post:
logging.info("find post %s from post id %s" % (page_id, current_post.title))
if operation == "edit":
t_values['current_post'] = current_post
elif operation == "publish":
current_post.is_external_page = True
current_post.put()
t_values['alert_message'] = "Post %s has been changed to public" % (current_post.title)
elif operation == "unpublish":
current_post.is_external_page = False
current_post.put()
t_values['alert_message'] = "Post %s has been changed to private" % (current_post.title)
elif operation == "delete":
current_post.delete()
t_values['alert_message'] = "Post %s has been changed to deleted" % (current_post.title)
# show all posts
posts = Entry.all().filter("entrytype =", 'page')
t_values['posts'] = posts
return self.response.out.write(render_template("pages.html", t_values, "", True))
示例2: post
# 需要导入模块: from model import Entry [as 别名]
# 或者: from model.Entry import get_by_id [as 别名]
def post(self):
# add new post or edit existed post
t_values = {}
current_post_id = self.request.POST["current_post_id"]
post_title = self.request.POST["blog_title"]
post_slug = get_safe_slug(self.request.POST["blog_slug"])
post_content = self.request.POST["blog_content"]
# find category
blog_category_id = self.request.POST["blog_category_id"]
post_category = Category.get_by_id(long(blog_category_id))
if post_category:
logging.info("find category %s for id %s" % (post_category.name, blog_category_id))
else:
logging.error("category id %s can't be located" % (blog_category_id))
if current_post_id:
logging.info("PostManager: post : edit post current_post_id = %s" % (current_post_id))
# update existed post
post = Entry.get_by_id(long(current_post_id))
if post:
t_values['alert_message'] = "Post %s has been updated!" % (post.title)
post.title = post_title
post.slug = post_slug
post.content = post_content
post.entrytype = "post"
# update category count if this post is public
if post.is_external_page and post.category != post_category:
if post.category and (post.category.entrycount > 0):
post.category.entrycount -= 1
post.category.put()
post_category.entrycount += 1
post.category.put()
post.category = post_category
post.put()
else:
logging.info("PostManager: post : new post title %s" % (self.request.POST['blog_title']))
# create new post
post = Entry()
post.title = post_title
post.slug = post_slug
post.content = post_content
post.entrytype = 'post'
post.category = post_category
# save as public or private?
operation = self.request.POST["submit_action"]
if operation == "save_publish":
post.is_external_page = True
# update category count
post.category.entrycount += 1
post.category.put()
else: # "save" operation
post.is_external_page = False
# save the post
post.put()
t_values['alert_message'] = "Post %s has been created!" % (post.title)
# show all posts
posts = Entry.all().filter("entrytype =", 'post')
t_values['posts'] = posts
return self.response.out.write(render_template("posts.html", t_values, "", True))
示例3: post
# 需要导入模块: from model import Entry [as 别名]
# 或者: from model.Entry import get_by_id [as 别名]
def post(self, user_id, feed_id, entry_id):
"""Updates a specific entry"""
current_user = utils.get_current_user()
if not current_user:
self.error(403)
return
user = User.get_by_id(int(user_id))
if user == None:
self.error(404)
return
if current_user.key() != user.key():
self.error(401)
return
feed = InputFeed.get_by_id(int(feed_id), parent=user)
if feed == None:
self.error(404)
return
entry = Entry.get_by_id(int(entry_id), parent=feed)
published = self.request.get('published')
if published != None:
entry.published = bool(int(published))
entry.save()
self.response.headers['Content-Type'] = 'application/json; charset=utf-8'
self.response.headers['Access-Control-Allow-Origin'] = '*'
self.response.out.write(json.dumps(entry.to_struct()))
示例4: delete
# 需要导入模块: from model import Entry [as 别名]
# 或者: from model.Entry import get_by_id [as 别名]
def delete(self, feed_id, entry_id, tag_title):
""" Delete tag """
current_user = utils.get_current_user()
tag_title = tag_title.decode('utf-8')
if not current_user:
logging.info('no user logged in')
self.error(403)
return
logging.info(feed_id)
feed = InputFeed.get_by_id(int(feed_id), parent=current_user)
if not feed:
logging.info('no feed found')
self.error(404)
return
entry = Entry.get_by_id(int(entry_id), parent=feed)
if not entry:
logging.info('no entry found')
self.error(404)
return
if not tag_title:
logging.info('no tag_title provided found')
self.error(400)
return
tag = Tag.all().ancestor(current_user).filter('title_lower =', tag_title.lower()).get()
if not tag:
logging.info('no tag found')
self.error(404)
return
entry.tags.remove(tag.key())
entry.save()
self.response.headers['Content-Type'] = 'text/plain; charset=utf-8'
self.response.headers['Access-Control-Allow-Origin'] = '*'
self.response.out.write('ok')
示例5: post
# 需要导入模块: from model import Entry [as 别名]
# 或者: from model.Entry import get_by_id [as 别名]
def post(self, post_slug=""):
if post_slug:
t_values = {}
post_id = self.request.POST['post_id']
post = Entry.get_by_id(long(post_id))
if post:
# ok, we find the post, try to add comment to this post
logging.warning("find one post with post_id %s" % (post_id))
t_values['post'] = post
# dump(post)
# check google recaptcha, these two fileds might not exist due to connection to reCAPTCHA
recaptcha_challenge_field = self.request.POST.get('recaptcha_challenge_field', "")
recaptcha_response_field = self.request.POST.get('recaptcha_response_field', "")
remote_ip = self.request.environ['REMOTE_ADDR']
private_key = "6LdwFdISAAAAAOYRK7ls3O-kXPTnYDEstrLM2MRo"
antispam_flag = False
try:
result = submit(recaptcha_challenge_field, recaptcha_response_field, private_key, remote_ip)
logging.info("google recaptcha %s, %s" % (result.is_valid, result.error_code))
if result.is_valid:
antispam_flag = True
except:
e = sys.exc_info()[0]
logging.info(e)
# create comment for this post
if antispam_flag:
logging.info("PostManager - add comment")
comm_author = self.request.POST['author']
comm_email = self.request.POST['email']
comm_weburl = self.request.POST['weburl']
comm_content = self.request.POST['comment']
comment_ip = self.request.environ['REMOTE_ADDR']
comm = Comment(entry=post, author=comm_author, email=comm_email, weburl=comm_weburl, content=comm_content, ip=comment_ip)
comm.put()
t_values['alert_message'] = "Thanks %s for your comment!" % (comm_author)
else:
logging.warning("comment ignored because antispam failed")
t_values['alert_message'] = "Sorry, your comment was ignored because of reCAPTCHA failure!"
# find all comments
comments = Comment.all().filter("entry =", post).order("date")
logging.info("PostHandler, post, find %d comments" % (comments.count()))
if post_id:
# only update commentcount when new comment is added
post.commentcount = comments.count()
post.put()
t_values['comments'] = comments
else:
logging.warning("post_id %s does not exist" % (post_id))
links = Link.all().order("date")
t_values['links'] = links
categories = Category.all()
t_values['categories'] = categories
pages = Entry.all().filter("is_external_page =", True).filter("entrytype =", 'page').order("date")
t_values['pages'] = pages
return self.response.out.write(render_template("post.html", t_values, "basic", False))
else:
self.redirect(uri_for("weblog.index"))