本文整理汇总了Python中models.BlogPost.put方法的典型用法代码示例。如果您正苦于以下问题:Python BlogPost.put方法的具体用法?Python BlogPost.put怎么用?Python BlogPost.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.BlogPost
的用法示例。
在下文中一共展示了BlogPost.put方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_blog_post
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import put [as 别名]
def create_blog_post(title, blurb, content):
published = datetime.now() + timedelta(days=-random.randint(1, 50))
p = BlogPost(title=title, blurb=blurb, content=content, published=published)
p.put()
for i in range(0, random.randint(0, 5)):
random_comment(p)
示例2: test_label
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import put [as 别名]
def test_label(self):
for feed_item in None, {}:
bp = BlogPost(id='x')
bp.put()
self.assertEquals('BlogPost x [no url]', bp.label())
bp = BlogPost(id='x', feed_item={'permalinkUrl': 'http://perma/link'})
bp.put()
self.assertEquals('BlogPost x http://perma/link', bp.label())
示例3: submitApost
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import put [as 别名]
def submitApost(self):
returnedTags=[]
def Tagupdate (tag):
#logging.info(self.tags.filter('tag',tag).count())
if tag!="" and self.tags.filter('tag',tag).count()==0:#tag does not exist
return(Tag(tag=tag).put())
else:
return(self.tags.filter('tag',tag)[0].key())#otherwise find its key
posttagkeys=[]
if not self.tags:#Tags are empty therefore insert new tags
posttagkeys=[Tag(tag=tag).put() for tag in self.posttags if tag!=""]
elif self.posttags[0]!="": posttagkeys=map(Tagupdate ,self.posttags)
for key in posttagkeys:
obj=db.get(key)
returnedTags.append({"tag":obj.tag,"tagid":obj.key().id()})
catnames=[]
catkeys=[]
if self.categories: #categories exist make list of them
[catnames.append(catobj.category) for catobj in self.categories]
[catkeys.append(catobj.key()) for catobj in self.categories]
catobjs=dict(zip(catnames,catkeys))
if self.postcategory in catobjs.keys():catkey=catobjs[self.postcategory]
else:#this post has a new category
newcatobj=Category()
newcatobj.category=self.postcategory
newcatobj.put()
catkey=newcatobj.key()
else:
newcatobj=Category()
newcatobj.category=self.postcategory
newcatobj.put()
catkey=newcatobj.key()
post=BlogPost()
post.title=self.title
post.body=self.body
post.tags=posttagkeys
post.category=catkey
post.put()
self.deleteMemcache(self)
self.refetch(self)
return(post.key(),returnedTags)
示例4: db_build
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import put [as 别名]
def db_build():
""" Convert all markdown file in ./data/blog into
html and put them in the datastore.
"""
# turn on code fencing...and pyshell
md = markdown2.Markdown(extras=['fenced-code-blocks', 'pyshell'])
# grab all markdown files and convert them to html
for filename in get_files_of_type('md', './data/blog'):
with open(filename, 'r') as f:
md_text = f.read()
html = md.convert(md_text)
title = os.path.basename(filename).rsplit('.', 1)[0].lower()
post = BlogPost(title=title, markdown=md_text, html=html)
post.put()
logging.info("Putting blogpost '{}' into datastore...".format(title))
示例5: post
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import put [as 别名]
def post(self):
name = self.request.get('name')
user = users.get_current_user()
if name:
prof = Profile(
name=name,
user=user
)
prof.put()
category_link = self.request.get('category')
category = Category.all().filter('link = ', category_link).get()
p = BlogPost(
title=self.request.get('title'),
body=self.request.get('body'),
category=category
)
p.teaser = self.makeTeaser(p.body)
user_name, prof_id = self.getUserNameAndID(user)
p.author_name = user_name
p.put()
self.redirect('/')
示例6: post
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import put [as 别名]
def post(self):
subject = self.request.get("subject")
content = self.request.get("content")
if subject and content:
newpost = BlogPost(subject=subject, content=content)
key = newpost.put()
memcache.set("front_page", None)
self.redirect("/unit3/blog/%s" % key.id())
else:
self.write(
blog_post_form,
{"subject": subject, "content": content, "error": "Both subject and content are required."},
)