本文整理汇总了Python中models.Post.key方法的典型用法代码示例。如果您正苦于以下问题:Python Post.key方法的具体用法?Python Post.key怎么用?Python Post.key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Post
的用法示例。
在下文中一共展示了Post.key方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import key [as 别名]
def post(self):
url = self.request.get('url')
title = sanitizeHtml(self.request.get('title'))
message = sanitizeHtml(self.request.get('message'))
session = get_current_session()
if session.has_key('user') and len(title) > 0:
user = session['user']
# decide if its a message or a link, if its a link we need a try/catch around the save, the link might be invalid
if len(message) == 0:
try:
post = Post(url=url,title=title,message=message, user=user)
post.put()
vote = Vote(user=user, post=post, target_user=post.user)
vote.put()
self.redirect('/noticia/' + str(post.key()));
except db.BadValueError:
self.redirect('/agregar')
else:
post = Post(title=title,message=message, user=user)
post.put()
post.url = "http://" + urlparse(self.request.url).netloc + "/noticia/" + str(post.key())
post.put()
vote = Vote(user=user, post=post, target_user=post.user)
vote.put()
self.redirect('/noticia/' + str(post.key()));
else:
self.redirect('/')
示例2: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import key [as 别名]
def post(self):
url = self.request.get("url")
title = sanitizeHtml(self.request.get("title"))
message = sanitizeHtml(self.request.get("message"))
session = get_current_session()
if session.has_key("user") and len(title) > 0:
user = session["user"]
# decide if its a message or a link, if its a link we need a try/catch around the save, the link might be invalid
if len(message) == 0:
try:
post = Post(url=url, title=title, message=message, user=user)
post.put()
vote = Vote(user=user, post=post, target_user=post.user)
vote.put()
Post.remove_cached_count_from_memcache()
self.redirect("/noticia/" + str(post.key()))
except db.BadValueError:
self.redirect("/agregar")
else:
post = Post(title=title, message=message, user=user)
post.put()
post.url = "http://" + urlparse(self.request.url).netloc + "/noticia/" + str(post.key())
post.put()
Post.remove_cached_count_from_memcache()
vote = Vote(user=user, post=post, target_user=post.user)
vote.put()
self.redirect("/noticia/" + str(post.key()))
else:
self.redirect("/")
示例3: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import key [as 别名]
def post(self):
session = get_current_session()
url = self.request.get('url')
title = helper.sanitizeHtml(self.request.get('title'))
message = helper.sanitizeHtml(self.request.get('message'))
if session.has_key('user'):
if len(title) > 0:
user = session['user']
if len(message) == 0: #is it a post or a message?
#Check that we don't have the same URL within the last 'check_days'
since_date = date.today() - timedelta(days=7)
q = Post.all().filter("created >", since_date).filter("url =", url).count()
url_exists = q > 0
try:
if not url_exists:
post = Post(url=url,title=title,message=message, user=user)
post.put()
vote = Vote(user=user, post=post, target_user=post.user)
vote.put()
Post.remove_cached_count_from_memcache()
self.redirect('/noticia/' + str(post.key()));
else:
session['post_error'] = "Este link ha sido entregado en los ultimo 7 dias"
self.redirect('/agregar')
except db.BadValueError:
session['post_error'] = "El formato del link no es valido"
self.redirect('/agregar')
else:
post = Post(title=title,message=message, user=user)
post.put()
post.url = helper.base_url(self) + "/noticia/" + str(post.key())
post.put()
Post.remove_cached_count_from_memcache()
vote = Vote(user=user, post=post, target_user=post.user)
vote.put()
self.redirect('/noticia/' + str(post.key()));
else:
session['post_error'] = "Necesitas agregar un titulo"
self.redirect('/agregar')
else:
self.redirect('/login')
示例4: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import key [as 别名]
def post(self):
subject = self.request.get('subject')
content = self.request.get('content')
error = ''
if subject and content:
post = Post(parent=blog_key(), subject=subject, content=content,
author=self.user)
# new post's likes_counter is set to 0 initially
post.put()
self.redirect('/blog/%s' % str(post.key().id()))
else:
error = 'Please enter both subject and content.'
self.render('newpost.html', error=error)
示例5: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import key [as 别名]
def post(self):
if not self.user:
return self.redirect('/login')
subject = self.request.get('subject')
content = self.request.get('content')
if subject and content:
post = Post(subject=subject,
content=content,
author=self.user)
post.put()
self.redirect('/blog/'+str(post.key().id()))
else:
self.render('newpost.html', content=content,
subject=subject, err_msg=True)
示例6: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import key [as 别名]
def post(self):
if not self.user:
self.redirect("/blog/login")
return
subject = self.request.get("subject")
content = utils.escape_html(self.request.get("content"))
if subject and content:
post = Post(subject=subject, content=content)
post.put()
top_posts(update=True)
self.redirect("/blog/%i" % (post.key().id()))
else:
error = "we need both subject and content"
self.render("blog_newpost.html", subject=subject, content=content, error=error)
示例7: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import key [as 别名]
def post(self):
if not self.user:
return self.redirect('/login')
subject = self.request.get('subject')
content = self.request.get('content')
author = self.request.get('author')
comment = self.request.get('comment')
if subject and content:
p = Post(parent=blog_key(), subject=subject,
content=content, author=author, comment=comment, likes=0, liked_by=[])
p.put()
self.redirect('/blog/%s' % str(p.key().id()))
else:
error = "subject and content, please!"
self.render("newpost.html", subject=subject,
content=content, error=error, comment=comment)
示例8: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import key [as 别名]
def post(self):
if not self.user:
self.redirect("/login?redirect=%s" % "/blog/newpost")
subject = self.request.get('subject')
content = self.request.get('content')
if subject and content:
p = Post(parent = blog_key(), subject = subject, content = content, owner = self.user)
p.put() ## store into database
add_post(p)
self.redirect('/blog/%s' % str(p.key().id()))
# memcache.flush_all()
######the above is clear the cache after new post.
else:
error = "subject and content, please!"
self.render("newpost.html", subject=subject, content=content, error=error)
示例9: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import key [as 别名]
def post(self):
if not self.user:
self.redirect('/blog/login')
return
subject = self.request.get("subject")
content = self.request.get("content")
if self.request.POST.get('save_post'):
if subject and content:
p = Post(subject=subject, content=content, created_by=self.user.key().id())
p.put()
self.redirect("/blog/" + str(p.key().id()))
else:
error = "Please enter both subject and content"
self.render_new_post(subject, content, error)
elif self.request.POST.get('cancel_new_post'):
self.redirect('/blog')
示例10: sendmessage
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import key [as 别名]
def sendmessage():
"""
phones = Phone.all()
regIds = [phone.phone_id for phone in phones]
data = dict()
data['title'] = 'me'
data['post'] = '123'
dataToSend = dict()
dataToSend['registration_ids'] = regIds
dataToSend['data'] = data
response = Response(json.dumps(dataToSend),mimetype='application/json')
response.headers.add('Content-Type','application/json')
response.headers.add('Authorization','key=AIzaSyBsBuZuPlRkt45QstSJ_qaHC7_e1NFEIZU')
#return response
headers = MultiDict()
headers['Content-Type'] = 'application/json'
headers['Authorization'] = "key=AIzaSyBsBuZuPlRkt45QstSJ_qaHC7_e1NFEIZU"
req = urllib2.Request("https://android.googleapis.com/gcm/send", json.dumps(dataToSend), headers)
f = urllib2.urlopen(req)
responseMsg = f.read()
f.close()
return responseMsg;
return json.dumps(dataToSend, sort_keys=True, indent=4)
"""
data = MultiDict()
f = request.form
for key in f.keys():
data[key] = f[key]
files = request.files.getlist('upload')
titleMsgHash = data['title'] + data['post']# + chr(random.randrange(97,97+26+1))
titleMsgHash = getHash(titleMsgHash)
currentPost = Post(key_name=titleMsgHash,title=data['title'],msg=data['post'])
currentPost.put()
base64Strings = []
i = 0
for file in files:
#file.save(os.path.join(app.config['UPLOAD_FOLDER'], file.filename))
fileString = file.read()
image64String = fileString.encode("base64")
imageKeyName = data['title']+data['post']+'image'+str(i)
tmpImage = Image(key_name=getHash(imageKeyName),encoded_string=image64String,post_id=currentPost.key())
tmpImage.put()
i = i+1
logging.debug('reached end')
return jsonify(data)