本文整理汇总了Python中model.Entry.slug方法的典型用法代码示例。如果您正苦于以下问题:Python Entry.slug方法的具体用法?Python Entry.slug怎么用?Python Entry.slug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Entry
的用法示例。
在下文中一共展示了Entry.slug方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from model import Entry [as 别名]
# 或者: from model.Entry import slug [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))
示例2: post
# 需要导入模块: from model import Entry [as 别名]
# 或者: from model.Entry import slug [as 别名]
def post(self):
if not self.is_login:
self.redirect(users.create_login_url(self.request.uri))
filename=self.param('filename')
do_comment=self.paramint('c',0)
if filename[:4]=='img/':#处理图片
new_filename=filename.split('/')[1]
mtype =new_filename.split('.')[1]
bits = self.request.body
media=Media.all().filter('name =',new_filename)
if media.count()>0:
media=media[0]
else:
media=Media()
media.name=new_filename
media.mtype=mtype
media.bits=bits
media.put()
bid='_'.join(new_filename.split('_')[:-1])
entries=Entry.all().filter('slug =',bid)
if entries.count()>0:
entry=entries[0]
entry.content=entry.content.replace(filename,'/media/'+str(media.key()))
entry.put()
return
if filename=="index.html" or filename[-5:]!='.html':
return
#处理html页面
bid=filename[:-5]
try:
soup=BeautifulSoup(self.request.body)
bp=soup.find(id='bp')
title=self.getChineseStr( soup.title.text)
logging.info(bid)
pubdate=self.getdate( bp.find(id='bp-'+bid+'-publish').text)
body=bp.find('div','blogpost')
entries=Entry.all().filter('title = ',title)
if entries.count()<1:
entry=Entry()
else:
entry=entries[0]
## entry=Entry.get_by_key_name(bid)
## if not entry:
## entry=Entry(key_name=bid)
entry.slug=bid
entry.title=title
entry.author_name=self.login_user.nickname()
entry.date=pubdate
entry.settags("")
entry.content=unicode(body)
entry.author=self.login_user
entry.save(True)
if do_comment>0:
comments=soup.find('div','comments','div')
if comments:
for comment in comments.contents:
name,date=comment.h5.text.split(' - ')
# modify by lastmind4
name_date_pair = comment.h5.text
if name_date_pair.index('- ') == 0:
name_date_pair = 'Anonymous ' + name_date_pair
name,date=name_date_pair.split(' - ')
key_id=comment.h5['id']
date=self.getdate(date)
content=comment.contents[1].text
comment=Comment.get_or_insert(key_id,content=content)
comment.entry=entry
comment.date=date
comment.author=name
comment.save()
except Exception,e :
logging.info("import error: %s"%e.message)