本文整理汇总了Python中models.Post.url方法的典型用法代码示例。如果您正苦于以下问题:Python Post.url方法的具体用法?Python Post.url怎么用?Python Post.url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Post
的用法示例。
在下文中一共展示了Post.url方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: populate_db
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import url [as 别名]
def populate_db():
"""Add 'personalwebapp' tag, first post to database."""
from datetime import datetime
from models import Post, Tag, post_to_tag
Post.query.delete()
Tag.query.delete()
db.session.execute(post_to_tag.delete())
personalwebapp = Tag(name='personalwebapp')
db.session.add(personalwebapp)
post = Post(title='Hello PersonalWebApp!', content=FIRST_POST, author_id=1, timezone=-5)
post.tags.append(personalwebapp)
post.state_id = 2
post.published_at = datetime.utcnow()
post.url = 'hello_personal_webapp'
db.session.add(post)
post = Post(title='Example Draft Post', content='This is the first draft. I\'ll finish it later.',
author_id=1, timezone=-5)
post.url = 'example_draft_post'
db.session.add(post)
db.session.commit()
print('"personalwebapp" tag'
'and "Hello PersonalWebApp!" published post and "Example Draft Post" draft post have been generated.')
示例2: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import url [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('/')
示例3: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import url [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("/")
示例4: addPostToDatabase
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import url [as 别名]
def addPostToDatabase(thread):
post = Post()
post.name = thread["data"]["title"]
post.url = "http://www.reddit.com" + thread["data"]["permalink"]
post.upvotes = thread["data"]["ups"]
post.downs = thread["data"]["downs"]
session.add(post)
session.commit()
return post
示例5: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import url [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"))
nice_url = helper.sluglify(title)
if session.has_key("user"):
if len(nice_url) > 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
q = Post.all().filter("nice_url", nice_url).count()
nice_url_exist = q > 0
try:
if not url_exists:
if not nice_url_exist:
post = Post(url=url, title=title, message=message, user=user, nice_url=nice_url)
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.nice_url))
else:
session["post_error"] = "Este titulo ha sido usado en una noticia anterior"
self.redirect("/agregar")
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:
q = Post.all().filter("nice_url", nice_url).count()
nice_url_exist = q > 0
if not nice_url_exist:
post = Post(title=title, message=message, user=user, nice_url=nice_url)
post.put()
post.url = helper.base_url(self) + "/noticia/" + post.nice_url
post.put()
Post.remove_cached_count_from_memcache()
vote = Vote(user=user, post=post, target_user=post.user)
vote.put()
self.redirect("/noticia/" + post.nice_url)
else:
session["post_error"] = "Este titulo ha sido usado en una noticia anterior"
self.redirect("/agregar")
else:
session["post_error"] = "Necesitas agregar un titulo"
self.redirect("/agregar")
else:
self.redirect("/login")
示例6: create_tags_posts
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import url [as 别名]
def create_tags_posts(self):
post1 = Post(title='title one', content='content one', author_id=1, timezone=0)
post2 = Post(title='title two', content='content two', author_id=1, timezone=0)
post3 = Post(title='title three', content='content three', author_id=1, timezone=0)
post1.url = 'post_one'
post1.state_id = 2
post2.url = 'post_two'
post2.state_id = 1
post3.url = 'post_three'
tag_a = Tag(name='tag_a')
tag_b = Tag(name='tag_b')
post1.tags = [tag_a, tag_b]
post2.tags = [tag_a]
with self.get_context():
db.session.add(tag_a)
db.session.add(tag_b)
db.session.add(post1)
db.session.add(post2)
db.session.add(post3)
db.session.commit()
示例7: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import url [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')
示例8: getPosts
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import url [as 别名]
def getPosts(blog):
if blog.url.endswith('persianblog.ir'):
url = "http://%s/rss.xml" % (blog.url)
else:
url = "http://%s/rss" % (blog.url)
print "going to parse: ", url
feed = feedparser.parse(url)
for entry in feed.entries:
if postExists(entry['link']):
continue
post = Post()
post.title = entry['title']
post.text = clean_html(entry['description'])
if hasattr(entry, 'published_parsed'):
post.date = datetime.fromtimestamp(mktime(entry['published_parsed']))
elif hasattr(entry, 'updated_parsed'):
post.date = datetime.fromtimestamp(mktime(entry['updated_parsed']))
else:
post.date = datetime.now()
post.url = entry['link']
post.blog = blog
post.save()
return feed
示例9: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import url [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'))
nice_url = helper.sluglify(title)
key = self.request.get('comment_key')
if session.has_key('user') and key == keys.comment_key:
if len(nice_url) > 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
q = Post.all().filter("nice_url", nice_url).count()
nice_url_exist = q > 0
try:
if not url_exists:
if not nice_url_exist:
post = Post(url=url,title=title,message=message, user=user, nice_url=nice_url)
post.put()
helper.killmetrics("Submit","Link", "do", session, "",self)
vote = Vote(user=user, post=post, target_user=post.user)
vote.put()
Post.remove_cached_count_from_memcache()
#index with indextank
helper.indextank_document( helper.base_url(self), post)
self.redirect('/noticia/' + str(post.nice_url));
else:
session['post_error'] = "Este titulo ha sido usado en una noticia anterior"
self.redirect('/agregar')
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:
q = Post.all().filter("nice_url", nice_url).count()
nice_url_exist = q > 0
if not nice_url_exist:
post = Post(title=title,message=message, user=user, nice_url=nice_url)
post.put()
helper.killmetrics("Submit","Post", "do", session, "",self)
post.url = helper.base_url(self) + "/noticia/" + post.nice_url
post.put()
Post.remove_cached_count_from_memcache()
vote = Vote(user=user, post=post, target_user=post.user)
vote.put()
#index with indextank
helper.indextank_document( helper.base_url(self), post)
self.redirect('/noticia/' + post.nice_url);
else:
session['post_error'] = "Este titulo ha sido usado en una noticia anterior"
self.redirect('/agregar')
else:
session['post_error'] = "Necesitas agregar un titulo"
self.redirect('/agregar')
else:
self.redirect('/login')
示例10: editpost
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import url [as 别名]
def editpost(post_id=None):
"""show the edit page, update the post
choice of editor:
while editing an existing post, use post.editor as the editor
editing a new post, use request.args["editor"] as the editor
"""
if request.method == "GET":
if post_id is not None:
post = Post.get_by_id(post_id=post_id, public_only=False)
editor = post.editor
if not post:
abort(404)
else:
post = Post()
editor = request.args.get("editor", "markdown")
return render_template('admin/editpost.html',
admin_url="post_" + editor,
post=post,
editor=editor)
elif request.method == "POST":
data = request.json
now_time = datetime.now()
if data['post_id'] is not None:
post = Post.get_by_id(
post_id=int(data["post_id"]),
public_only=False)
else:
post = Post()
post.create_time = now_time
post.editor = data.get("editor", "markdown")
post.update_time = now_time
post.title = data.get("title", "")
post.update_tags(data.get("tags", ""))
post.url = data.get("url", "")
post.keywords = data.get("keywords", "")
post.metacontent = data.get("metacontent", "")
post.content = data.get("content", "")
post.raw_content = Post.gen_raw_content(post.content, post.editor)
post.allow_comment = data.get("allow_comment", True)
post.allow_visit = data.get("allow_visit", True)
post.is_original = data.get("is_original", True)
post.need_key = data.get("need_key", False)
post.password = data.get("password", "")
post.save()
return jsonify(success=True,
post_id=post.post_id)
elif request.method == "DELETE":
# Delete post by id
if post_id is not None:
post = Post.get_by_id(int(post_id), public_only=False)
if post:
post.delete()
# Batch Delete method
else:
removelist = request.json
for post_id in removelist:
post = Post.get_by_id(post_id=int(post_id), public_only=False)
if post:
post.delete()
return jsonify(success=True)