本文整理汇总了Python中model.Entry.put方法的典型用法代码示例。如果您正苦于以下问题:Python Entry.put方法的具体用法?Python Entry.put怎么用?Python Entry.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Entry
的用法示例。
在下文中一共展示了Entry.put方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from model import Entry [as 别名]
# 或者: from model.Entry import put [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 put [as 别名]
def post(self):
target = self.request.get('target')
amount = int(self.request.get('amount'))
location = self.request.get('location')
date = datetime.datetime.strptime(self.request.get('date'), '%Y-%m-%d').date()
succeed = True#self.request.get('succeed')
story = self.request.get('story')
entry = Entry(target=target, amount=amount, location=location, date=date, succeed=succeed, story=story, author=users.get_current_user())
entry.put()
self.redirect('/')
示例3: get
# 需要导入模块: from model import Entry [as 别名]
# 或者: from model.Entry import put [as 别名]
def get(self):
'''i=0
n = self.request.get('n')
if not n:
n='1'
csvfile='data/data'+n+'.csv'
self.response.headers['Content-Type'] = 'text/html'
csvreader = csv.reader(file(os.path.join(os.path.dirname(__file__),csvfile)))
for line in csvreader:
e = Entry()
e.title = line[0].decode('utf-8')
e.url = line[1].decode('utf-8')
e.content = line[2].decode('utf-8')
e.private = False
tag_name=line[3].decode('utf-8')
t_q = Tag.all()
t_q = t_q.filter('name =',tag_name)
if(t_q.count(1)>0):
t = t_q.get()
t.count_link+=1
t.usetime=datetime.datetime.now()
t.put()
else:
t = Tag()
t.name = tag_name
t.count_link=1
t.usetime=datetime.datetime.now()
t.put()
e.tags.append(db.Category(tag_name))
e.put()
i +=1
self.response.out.write('%d ' % i)
self.response.out.write('%s ' % e.key())
self.response.out.write('%s <br />' % line[0])
'''
n = self.request.get('n')
if not n:
n=0
else:
n=int(n)
for i in range(1,1000):
e = Entry()
e.title=str(i+n*999)
e.pageid=n
e.put()
self.response.out.write('%d ' % i)
self.response.out.write('%s <br />' % e.key())
示例4: test_put
# 需要导入模块: from model import Entry [as 别名]
# 或者: from model.Entry import put [as 别名]
def test_put(self):
context = Context(http=MockHttp(HTTP_SRC_DIR), entry="http://example.org/entry/67")
entry = Entry(context)
(headers, body) = entry.put(body="<entry></entry>")
self.assertEqual(200, headers.status)
self.assertFalse(entry.has_media())
self.assertEqual(0, len(body))
示例5: post
# 需要导入模块: from model import Entry [as 别名]
# 或者: from model.Entry import put [as 别名]
def post(self):
if users.is_current_user_admin():
key = self.request.get('key')
if key :
e = db.get(key)
else:
e = Entry()
type = self.request.get('type')
if not type:
type = 'link'
title = self.request.get('title')
e.title = title.replace('&','&').replace('<','<').replace('>','>')
url = self.request.get('url')
purl= self.request.get('purl')
if type == 'pic' and not key:
e.url = purl.replace('&','&').replace('<','<').replace('>','>')
else:
e.url = url.replace('&','&').replace('<','<').replace('>','>')
content = self.request.get('content')
e.content = content
if not key:
e.addtime +=datetime.timedelta(hours=+8)
e.private = bool(int(self.request.get('private')))
e.type = type
if type =='pic' and not key:
if url:
try:
result = urlfetch.fetch(url)
if result.status_code == 200:
e.image = db.Blob(result.content)
except :
self.response.out.write('获取图片超时!')
return
else:
myfile = self.request.get("myfile")
if not myfile:
self.response.out.write( '没有选择文件!')
return
try:
e.image = db.Blob(myfile)
except :
self.response.out.write( '文件上传失败!')
return
if key:#更新数据
for oldtag in e.tags:
tag = Tag.all().filter('name',oldtag)
if(tag.count(1)>0):
t = tag.get()
if type == 'link':
t.count_link -=1
if type == 'note':
t.count_note -=1
if type == 'pic':
t.count_pic -=1
t.put()
else:#新增数据
max_pageCount =900 #超过此数据,则pageid递增
entry = Entry.all().order('-addtime')
if entry.count()>0:
cur_pageid = entry.get().pageid
else:
cur_pageid = 0
cur_pageCount = entry.filter('pageid =',cur_pageid).count(1000)
if cur_pageCount>=max_pageCount:
e.pageid = cur_pageid+1
else:
e.pageid = cur_pageid
e.tags = []
tag_names = self.request.get('tags').split()
for tag_name in tag_names:
tag = Tag.all().filter('name',tag_name)
if(tag.count(1)>0):
t = tag.get()
if type == 'link':
t.count_link +=1
if type == 'note':
t.count_note +=1
if type == 'pic':
t.count_pic +=1
t.usetime = datetime.datetime.now()
t.put()
else:
t = Tag()
t.name = tag_name
if type == 'link':
t.count_link =1
#.........这里部分代码省略.........